I nearly bought this kind of thing, but then realised I had all the parts I needed to make it myself, which is half the fun, right?!
This video shows it in action;
What I'm using in this build is;
Part | Approx Price |
---|---|
24 LED Ring | £2 |
Arduino Nano | £1.75 |
Breadboard, button, potentiometer, and wires | £1.25 |
The components are wired up like this;
And here's the code (uses the Adafruit neopixel library);
#include <Adafruit_NeoPixel.h> #ifdef __AVR__ #include <avr/power.h> #endif #define PIN 6 // pin on the Arduino is connected to the LED ring #define NUMPIXELS 24 // Number of pixels on the LED ring #define POT_PIN 0 // Potentiometer pin #define BUTTON_PIN 2 // Button pin Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); int showType = 0; bool oldState = HIGH; void setup() { pinMode(BUTTON_PIN, INPUT_PULLUP); // Declare pushbutton as input pixels.begin(); // This initializes the NeoPixel library. } void loop() { // Read the potentiometer value and translate to how many pixels we want to illuminate int value = analogRead(POT_PIN); value = map(value, 0, 1023, 0, 25); // Switch colours if the button is pressed bool newState = digitalRead(BUTTON_PIN); if (newState == LOW && oldState == HIGH) { delay(20); // Short delay to debounce button. // Check if button is still low after debounce. newState = digitalRead(BUTTON_PIN); if (newState == LOW) { // Cycle through different colour schemes showType++; if (showType > 8) showType=0; } } oldState = newState; // Set the last button state to the old state. uint32_t color = pixels.Color(255,255,255); // default to white when first booted if (showType==1) color = pixels.Color(0,0,255); // blue if (showType==2) color = pixels.Color(0,255,0); // green if (showType==3) color = pixels.Color(255,0,0); // red if (showType==4) color = pixels.Color(0,127,255); if (showType==5) color = pixels.Color(255,127,0); if (showType==6) color = pixels.Color(255,0,127); if (showType==7) color = pixels.Color(0,255,255); if (showType==8) color = pixels.Color(127,127,255); // Illuminate X pixels depending on how far the potentiometer is turned for(int i=0;i<NUMPIXELS;i++){ if (i<value) { pixels.setPixelColor(i, color); } else { pixels.setPixelColor(i, pixels.Color(0,0,0)); // Don't show anything } } pixels.show(); // This sends the updated pixel configuration to the hardware. }
And here's the end result!
Top Comments