January 25, 2025
Description
With this gadget, you can visualize the additive color mixing of red, green, and blue. Pressing the button changes the color of the LED underneath. The gadget can be attached to a whiteboard using the magnets. Power is supplied via a USB-C connector.
#Material:
#Connections to the Arduino:
Button 1: D5 and GND
Button 2: D4 and GND
Button 3: D3 and GND
LED Strip: 5V, D10 and GND
#Arduino Code:
'#include <Adafruit_NeoPixel.h>
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(3,10,NEO_GRB + NEO_KHZ800);
int buttons[] = {5,4,3};
int colors[] = {0,0,0};
void setup() {
pixels.begin();
pinMode(buttons[0], INPUT);
pinMode(buttons[1], INPUT);
pinMode(buttons[2], INPUT);
digitalWrite(buttons[0],HIGH);
digitalWrite(buttons[1],HIGH);
digitalWrite(buttons[2],HIGH);
pixels.setPixelColor(0,pixels.Color(0,0,0));
pixels.setPixelColor(1,pixels.Color(0,0,0));
pixels.setPixelColor(2,pixels.Color(0,0,0));
pixels.show();
}
void loop() {
for (int i=0; i<sizeof(buttons);i++){
if(digitalRead(buttons[i]) == LOW){
colors[i]++;
if(colors[i] == 4){colors[i] = 0;}
switch(colors[i]){
case 0:pixels.setPixelColor(i,pixels.Color(0,0,0));break;
case 1:pixels.setPixelColor(i,pixels.Color(255,0,0));break;
case 2:pixels.setPixelColor(i,pixels.Color(0,255,0));break;
case 3:pixels.setPixelColor(i,pixels.Color(0,0,255));break;
}
pixels.show();
while(digitalRead(buttons[i]) == LOW){
delay(10);
}
}
}
}
License:
Creative Commons - Attribution - Share Alike