A simple RGB LED lamp for illuminating a keyboard tray.
Not a member? You should Sign up.
Already have an account? Log in.
To make the experience fit your profile, pick a username and tell us what interests you.
Each press of the button cycles the LED colors. It turns off after red.
Just wire it up and upload the following code.
int redPin = 3; int greenPin = 5; int bluePin = 6; int buttonPin = 2; int initialCount = 0; //uncomment this line if using a Common Anode LED #define COMMON_ANODE void setup() { pinMode(redPin, OUTPUT); pinMode(greenPin, OUTPUT); pinMode(bluePin, OUTPUT); pinMode(buttonPin, INPUT_PULLUP); setColor(0,0,0); } void loop() { int buttonState = digitalRead(buttonPin); if ( buttonState == LOW ){ delay(500); //delay for debounce initialCount++; if (initialCount > 4 ){ initialCount = 0; } switch (initialCount){ case 0: setColor(0,0,0); break; case 1: setColor(0, 255, 0); // green break; case 2: setColor(0, 255, 255); // aqua break; case 3: setColor(0, 0, 255); // blue break; case 4: setColor(255, 0, 0); // red break; } } } void setColor(int red, int green, int blue) { #ifdef COMMON_ANODE red = 255 - red; green = 255 - green; blue = 255 - blue; #endif analogWrite(redPin, red); analogWrite(greenPin, green); analogWrite(bluePin, blue); }
View all 3 instructions
Create an account to leave a comment. Already have an account? Log In.
Grégory Paul
snowfox
David
Martin
Become a member to follow this project and never miss any updates
Yes, delete it Cancel
You are about to report the project "arduino desktop lamp", please tell us the reason.
Your application has been submitted.
Are you sure you want to remove yourself as a member for this project?
Project owner will be notified upon removal.