Colour Changing Imp Lamp
The Lincoln Imp held inside an infinity light trap.
Components and supplies
1
Arduino Nano R3
3
General Purpose Transistor NPN
1
DC/DC Converter, Buck Regulator
3
Resistor 1k ohm
Project description
Code
RGB led
arduino
to control an RGB led or strip
1/* 2 RGBLedExample 3 Example for the RGBLED Library 4 Created by Bret Stateham, November 13, 2014 5 You can get the latest version from http://github.com/BretStateham/RGBLED 6*/ 7#include <RGBLED.h> 8 9// Declare an RGBLED instanced named rgbLed 10// Red, Green and Blue LED legs are connected to PWM pins 11,9 & 6 respectively 11// In this example, we have a COMMON_ANODE LED, use COMMON_CATHODE otherwise 12RGBLED rgbLed(11,9,6,COMMON_CATHODE); 13 14//How long to show each color in the example code (in milliseconds); 15int delayMs = 50; 16 17void setup() { 18 //Initialize Serial communications 19 Serial.begin(9600); 20 21 //Report the LED type and pins in use to the serial port... 22 Serial.println("Welcome to the RGBLED Sample Sketch"); 23 String ledType = (rgbLed.commonType==0) ? "COMMON_CATHODE" : "COMMON_ANODE"; 24 Serial.println("Your RGBLED instancse is a " + ledType + " LED"); 25 Serial.println("And the Red, Green, and Blue legs of the LEDs are connected to pins:"); 26 Serial.println("r,g,b = " + String(rgbLed.redPin) + "," + String(rgbLed.greenPin) + "," + String(rgbLed.bluePin) ); 27 Serial.println(""); 28} 29 30void loop() { 31 32 //The code in the loop shows multiple exampls 33 34 //Set the RGBLED to show RED only 35 //printRgbValues() prints various LED values to the Serial port 36 //you can monitor the serial port to see the values printed 37 //The delay(delayMs) waits for 1 second to be able to see the color shown 38 //rgbLed.writeRGB(255,0,0); 39 //printRgbValues(); 40 //delay(delayMs); 41 42 //Set the RGBLED to show GREEN only 43 //rgbLed.writeRGB(0,255,0); 44 //printRgbValues(); 45 //delay(delayMs); 46 47 //Set the RGBLED to show BLUE only 48 //rgbLed.writeRGB(0,0,255); 49 //printRgbValues(); 50 //delay(delayMs); 51 52 //Set the RGBLED to show YELLOW (RED & GREEN) only 53 //rgbLed.writeRGB(255,255,0); 54 //printRgbValues(); 55 //delay(delayMs); 56 57 //Set the RGBLED to show ORANGE (RED & partial GREEN) only 58 //rgbLed.writeRGB(255,128,0); 59 //printRgbValues(); 60 //delay(delayMs); 61 62 //Set the RGBLED to show PURPLE (RED & BLUE) only 63 //rgbLed.writeRGB(255,0,255); 64 //printRgbValues(); 65 //delay(delayMs); 66 67 //Set the RGBLED to show PINK (RED & partial BLUE) only 68 //rgbLed.writeRGB(255,0,128); 69 //printRgbValues(); 70 //delay(delayMs); 71 72 //Set the RGBLED to show a random color 73 //rgbLed.writeRandom(); 74 //printRgbValues(); 75 //delay(delayMs); 76 77 //Set the pins individually if needed 78 //rgbLed.writeRed(255); 79 //rgbLed.writeGreen(255); 80 //rgbLed.writeBlue(255); 81 //printRgbValues(); 82 //delay(delayMs); 83 84 //The above code does the same thing as... 85 //rgbLed.writeRGB(255,255,255); 86 //printRgbValues(); 87 //delay(delayMs); 88 89 //Show the color wheel 90 Serial.println("Showing RGB Color Wheel..."); 91 Serial.println("------------------------------"); 92 //Use a 25ms delay between each color in the wheel 93 rgbLed.writeColorWheel(1500); 94 95 //Turn off the RGBLED 96 //rgbLed.turnOff(); 97 //printRgbValues(); 98 //delay(delayMs); 99 100} 101 102//printRgbValues prints the LED pins and values to the serial port 103//You can monitor the serial port to see those values 104void printRgbValues() { 105 Serial.println("Requested RGB Values:"); 106 Serial.println("(r,g,b)=(" + String(rgbLed.redValue) + "," + String(rgbLed.greenValue) + "," + String(rgbLed.blueValue) + ")"); 107 Serial.println("Mapped RGB Values based on type (COMMON_ANODE or COMMON_CATHODE):"); 108 Serial.println("Mapped(r,g,b)=(" + String(rgbLed.redMappedValue) + "," + String(rgbLed.greenMappedValue) + "," + String(rgbLed.blueMappedValue) + ")"); 109 Serial.println("------------------------------"); 110}
Downloadable files
circuit board
homemade
circuit board

circuit board
homemade
circuit board

Comments
Only logged in users can leave comments