Skip to content

Instantly share code, notes, and snippets.

@tuldok89
Created February 25, 2026 12:13
Show Gist options
  • Select an option

  • Save tuldok89/cac936e1af03824cf8ad2aefd1ecd9c4 to your computer and use it in GitHub Desktop.

Select an option

Save tuldok89/cac936e1af03824cf8ad2aefd1ecd9c4 to your computer and use it in GitHub Desktop.
Blink the LED and RGB LED on Vcc-Gnd RP2040 Board
#include <Arduino.h>
#include <hardware/timer.h>
#include <Adafruit_NeoPixel.h>
#include <random>
bool ledVal = LOW;
repeating_timer_t timer;
repeating_timer_t rgbTimer;
Adafruit_NeoPixel rgb(1, 23, NEO_GRB + NEO_KHZ800);
std::default_random_engine gen;
std::uniform_int_distribution<uint32_t> dist(0, 0xFFFFFF);
/**
* @brief Timer callback to toggle the built-in LED every 500ms and reset the watchdog timer
*/
bool timer_tick(repeating_timer_t *rt)
{
rp2040.wdt_reset();
ledVal = !ledVal;
digitalWrite(LED_BUILTIN, ledVal);
digitalWrite(6, !ledVal);
return true;
}
/***
* @brief Timer callback to update the RGB LED with a random color every 100ms
*/
bool rgb_tick(repeating_timer_t *rt)
{
rgb.setPixelColor(0, dist(gen));
rgb.show();
return true;
}
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
rgb.begin();
add_repeating_timer_ms(100, timer_tick, nullptr, &timer);
add_repeating_timer_ms(100, rgb_tick, nullptr, &rgbTimer);
rp2040.wdt_begin(1000);
}
void loop()
{
// let the core sleep
__wfi();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment