Skip to content

Instantly share code, notes, and snippets.

@securetorobert
Created June 18, 2022 06:37
Show Gist options
  • Save securetorobert/3b2ca1a0d4ab5968077702d616fc859f to your computer and use it in GitHub Desktop.
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
#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