Skip to content

Instantly share code, notes, and snippets.

@WimObiwan
Last active February 10, 2025 19:59
Show Gist options
  • Save WimObiwan/a3f837164c7f2dae148262660cc5eee7 to your computer and use it in GitHub Desktop.
Save WimObiwan/a3f837164c7f2dae148262660cc5eee7 to your computer and use it in GitHub Desktop.
Coderdojo Arduino
#include <ChainableLED.h>
#include <Grove_LED_Bar.h>
#define NUM_LEDS 1
// Pin for LED control
ChainableLED leds(2, 3, NUM_LEDS); // Pin 2 for data, pin 3 for clock
// Button pin
int buttonPin = 4; // Button is connected to pin 4
byte buttonState; // Variable to store button state
Grove_LED_Bar bar(0, 2, 0, LED_BAR_10);
void setup()
{
leds.init(); // Initialize the LED strip
pinMode(buttonPin, INPUT); // Set the button pin as input
leds.setColorRGB(0, 255, 0, 0); // Start with the LED being red
bar.begin();
bar.setBits(0x0);
}
void loop()
{
buttonState = digitalRead(buttonPin); // Read the state of the button
if (buttonState == HIGH) // If the button is pressed
{
// Set color to orange
leds.setColorRGB(0, 255, 50, 0);
delay(2500); // Wait for 2.5 seconds
// Set color to green
leds.setColorRGB(0, 0, 255, 10);
bar.setBits(0b0000000000);
delay(500);
bar.setBits(0b0000000001);
delay(500);
bar.setBits(0b0000000011);
delay(500);
bar.setBits(0b0000000111);
delay(500);
bar.setBits(0b0000001111);
delay(500);
bar.setBits(0b0000011111);
delay(500);
bar.setBits(0b0000111111);
delay(500);
bar.setBits(0b0001111111);
delay(500);
bar.setBits(0b0011111111);
delay(500);
bar.setBits(0b0111111111);
delay(500);
bar.setBits(0b1111111111);
// Set color back to red
leds.setColorRGB(0, 255, 0, 0);
}
else // If the button is not pressed
{
// Keep the LED red
leds.setColorRGB(0, 255, 0, 0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment