Components and supplies
1
Jumper wires (generic)
1
Arduino UNO
1
RGB Diffused Common Cathode
1
Resistor 2.21k ohm
Project description
Code
Rgbled
ada
1//RGB LED 2//The RGB LED will appear red, green, and blue first, then red, orange, yellow, green, blue, indigo, and purple. 3//Email:support@sunfounder.com 4//Website:www.sunfounder.com 5//2015.5.7 6/*************************************************************************/ 7const int redPin = 11; // R petal on RGB LED module connected to digital pin 11 8const int greenPin = 10; // G petal on RGB LED module connected to digital pin 10 9const int bluePin = 9; // B petal on RGB LED module connected to digital pin 9 10/**************************************************************************/ 11void setup() 12{ 13 pinMode(redPin, OUTPUT); // sets the redPin to be an output 14 pinMode(greenPin, OUTPUT); // sets the greenPin to be an output 15 pinMode(bluePin, OUTPUT); // sets the bluePin to be an output 16} 17/***************************************************************************/ 18void loop() // run over and over again 19{ 20 // Basic colors: 21 color(255, 0, 0); // turn the RGB LED red 22 delay(1000); // delay for 1 second 23 color(0,255, 0); // turn the RGB LED green 24 delay(1000); // delay for 1 second 25 color(0, 0, 255); // turn the RGB LED blue 26 delay(1000); // delay for 1 second 27 // Example blended colors: 28 color(255,0,252); // turn the RGB LED red 29 delay(1000); // delay for 1 second 30 color(237,109,0); // turn the RGB LED orange 31 delay(1000); // delay for 1 second 32 color(255,215,0); // turn the RGB LED yellow 33 delay(1000); // delay for 1 second 34 color(34,139,34); // turn the RGB LED green 35 delay(1000); // delay for 1 second 36 color(0,112,255); // turn the RGB LED blue 37 delay(1000); // delay for 1 second 38 color(0,46,90); // turn the RGB LED indigo 39 delay(1000); // delay for 1 second 40 color(128,0,128); // turn the RGB LED purple 41 delay(1000); // delay for 1 second 42} 43/******************************************************/ 44void color (unsigned char red, unsigned char green, unsigned char blue)// the color generating function 45{ 46 analogWrite(redPin, red); 47 analogWrite(greenPin, green); 48 analogWrite(bluePin, blue); 49} 50/******************************************************/ 51//Controlling led by potentiometer 52//Rotate the shaft of the potentiometer and you should see the luminance of the LED change. 53//Email:support@sunfounder.com 54//Website:www.sunfounder.com 55//2015.5.7 56/******************************************/ 57const int analogPin = 0;//the analog input pin attach to 58const int ledPin = 8;//the led attach to 59int inputValue = 0;//variable to store the value coming from sensor 60int outputValue = 0;//variable to store the output value 61/******************************************/ 62 Serial.begin(9600);//set the serial communication baudrate as 9600 63} 64/******************************************/ 65void loop() 66{ 67 inputValue = analogRead(analogPin);//read the value from the potentiometer 68 Serial.print("Input: "); //print "Input" 69 Serial.println(inputValue); //print inputValue 70 outputValue = map(inputValue, 0, 1023, 0, 255); //Convert from 0-1023 proportional to the number of a number of from 0 to 255 71 Serial.print("Output: "); //print "Output" 72 Serial.println(outputValue); //print outputValue 73 analogWrite(ledPin, outputValue); //turn the LED on depending on the output value 74 delay(1000); 75} 76/*******************************************/ 77
Comments
Only logged in users can leave comments