Created
June 18, 2022 06:37
-
-
Save securetorobert/3b2ca1a0d4ab5968077702d616fc859f to your computer and use it in GitHub Desktop.
code to toggle state and control an output pin on Arduino Nano RP2040 Connect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Bounce2.h> | |
const int pin = 2; | |
const int button = 10; | |
bool led_state = false; | |
Bounce bouncer = Bounce(); | |
// the setup function runs once when you press reset or power the board | |
void setup() { | |
pinMode(pin, OUTPUT); | |
pinMode(button, INPUT_PULLUP); | |
bouncer.attach(button); | |
} | |
// the loop function runs over and over again forever | |
void loop() { | |
bouncer.update(); | |
if (bouncer.changed() && bouncer.read() == LOW) { | |
led_state = !led_state; | |
Serial.println(led_state); | |
} | |
digitalWrite(pin, led_state); | |
} | |
void switch_led_state() { | |
led_state = !led_state; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment