// hello.button-blink.RP2040.1.ino // // Seeed XIAO RP2040 button, blink, echo hello-world, single core // // Neil Gershenfeld 12/28/23 // // This work may be reproduced, modified, distributed, // performed, and displayed for any purpose, but must // acknowledge this project. Copyright is retained and // must be preserved. The work is provided as is; no // warranty is provided, and users accept all liability. // // add RP2040 core // https://github.com/earlephilhower/arduino-pico // #include #define BTN_PIN 15 // GP15 #define LED_PIN 0 // GP2 (DIN of the NeoPixel) #define NUM_PIXELS 1 #define led_pin 2 Adafruit_NeoPixel strip(NUM_PIXELS, LED_PIN, NEO_GRB + NEO_KHZ800); bool button_up = true; void setup() { pinMode(led_pin,OUTPUT); digitalWrite(led_pin,HIGH); Serial.begin(9600); pinMode(BTN_PIN, INPUT_PULLUP); // not pressed=HIGH, pressed=LOW strip.begin(); strip.show(); strip.setBrightness(50); strip.setPixelColor(0, strip.Color(255, 165, 0)); strip.show(); Serial.println("Ready."); } void loop() { // Read button and toggle pixel bool pressed = (digitalRead(BTN_PIN) == LOW); if (pressed && button_up) { Serial.println("button down"); button_up = false; strip.setPixelColor(0, strip.Color(255, 165, 0)); // orange strip.show(); } else if (!pressed && !button_up) { Serial.println("button up"); button_up = true; strip.clear(); strip.show(); } }