Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //here is the example using Fritzing
- //http://1drv.ms/1h1cQKQ
- //(the link is to OneDrive)
- //in this case I'm using a RGB Anode led
- //and, for those who does not know hoe the RGB led works, here's the answer
- //http://www.instructables.com/answers/How-do-multi-colored-led-lights-work/
- // Init the Pins used for PWM
- const int redPin = 9;
- const int greenPin = 10;
- const int bluePin = 11;
- const int buttonPin = 13;
- int buttonState = LOW;
- int currentColorValueRed;
- int currentColorValueGreen;
- int currentColorValueBlue;
- void setup()
- {
- pinMode(redPin, OUTPUT);
- pinMode(greenPin, OUTPUT);
- pinMode(bluePin, OUTPUT);
- pinMode(buttonPin, INPUT);
- Serial.begin(9600);
- }
- void loop()
- {
- int i;
- currentColorValueRed = 0;
- currentColorValueGreen = 255;
- currentColorValueBlue = 255;
- analogWrite(redPin, currentColorValueRed);
- analogWrite(greenPin, currentColorValueGreen);
- analogWrite(bluePin, currentColorValueBlue);
- for(i = 255; i > 0; i--) {
- currentColorValueGreen --;
- analogWrite(redPin, currentColorValueRed);
- analogWrite(greenPin, currentColorValueGreen);
- analogWrite(bluePin, currentColorValueBlue);
- delay(10);
- }
- for(i = 255; i > 0; i--) {
- currentColorValueRed ++;
- analogWrite(redPin, currentColorValueRed);
- analogWrite(greenPin, currentColorValueGreen);
- analogWrite(bluePin, currentColorValueBlue);
- delay(10);
- }
- for(i = 255; i > 0; i--) {
- currentColorValueBlue --;
- analogWrite(redPin, currentColorValueRed);
- analogWrite(greenPin, currentColorValueGreen);
- analogWrite(bluePin, currentColorValueBlue);
- delay(10);
- }
- for(i = 255; i > 0; i--) {
- currentColorValueGreen ++;
- analogWrite(redPin, currentColorValueRed);
- analogWrite(greenPin, currentColorValueGreen);
- analogWrite(bluePin, currentColorValueBlue);
- delay(10);
- }
- for(i = 255; i > 0; i--) {
- currentColorValueRed --;
- analogWrite(redPin, currentColorValueRed);
- analogWrite(greenPin, currentColorValueGreen);
- analogWrite(bluePin, currentColorValueBlue);
- delay(10);
- }
- for(i = 255; i > 0; i--) {
- currentColorValueBlue ++;
- analogWrite(redPin, currentColorValueRed);
- analogWrite(greenPin, currentColorValueGreen);
- analogWrite(bluePin, currentColorValueBlue);
- delay(10);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement