Skip to content
Snippets Groups Projects
Commit 4ddec15e authored by ma1u20's avatar ma1u20
Browse files

Upload New File

parent 0740e877
No related branches found
No related tags found
No related merge requests found
#include "pico/stdlib.h"
const uint ledPin = 14;
const uint pushButtonPin = 13;
bool getLogicState() {
return gpio_get(pushButtonPin);
}
int main() {
// Initialize LED pin as output
gpio_init(ledPin);
gpio_set_dir(ledPin, GPIO_OUT);
// Initialize push button pin as input
gpio_init(pushButtonPin);
gpio_set_dir(pushButtonPin, GPIO_IN);
gpio_pull_up(pushButtonPin);
while (true) {
bool logicState = getLogicState();
if (logicState) { // If push button pressed
gpio_put(ledPin, 1); // Turn LED on
} else { // If push button not pressed
gpio_put(ledPin, 0); // Turn LED off
}
sleep_ms(10); // Delay to avoid debounce issues
}
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment