Go Down

Topic: Christmas LED Script (Read 1 time) previous topic - next topic

quipucito

Dec 31, 2011, 01:07 am Last Edit: Jan 01, 2012, 12:35 am by AWOL Reason: 1
I made this script for the celebration of Christmas!!!

:%
Code: [Select]

/*

  RG_LED_Color_Flicker_Cycle.pde
 
  Cycles through the colors of a RG LED

  Written for SparkFun Arduino Inventor's Kit CIRC-RG

*/

// LED leads connected to PWM pins
const int RED_LED_PIN = 9;
const int GREEN_LED_PIN = 10;

// Used to store the current intensity level of the individual LEDs
int redIntensity = 0;
int greenIntensity = 0;

// Length of time we spend showing each color
const int DISPLAY_TIME = 100; // In milliseconds


void setup() {
  // No setup required.
}

void loop() {
  // Cycle color from red through to green
  // (In this loop we move from 100% red, 0% green to 0% red, 100% green)
  for (greenIntensity = 0; greenIntensity <= 255; greenIntensity+=255) {
        redIntensity = 255-greenIntensity;
        analogWrite(GREEN_LED_PIN, greenIntensity);
        analogWrite(RED_LED_PIN, redIntensity);
        delay(DISPLAY_TIME);
  }

  // Cycle cycle from green through to red
  // (In this loop we move from 100% green, 0% red to 0% green, 100% red)   
  for (redIntensity = 0; redIntensity <= 255; redIntensity+=255) {
        greenIntensity = 255-redIntensity;
        analogWrite(RED_LED_PIN, redIntensity);
        analogWrite(GREEN_LED_PIN, greenIntensity);
        delay(DISPLAY_TIME);
  }
}

Go Up