Skip to content
Snippets Groups Projects
Select Git revision
  • 4f9afde6a88648400fdead52e8833dbe6d0c5c31
  • main default protected
2 results

pushButton.c

Blame
  • ma1u20's avatar
    ma1u20 authored
    4f9afde6
    History
    pushButton.c 754 B
    #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;
    }