Arduino Pumpkin Lights

Ok, I decided to make some LED’s to go in a pumpkin this year. Here’s the code for it:

/*
  Pumpkin LED Lights
 
 This sketch controls 6 LEDs connected to the 6
 PWM pins
 
 1&2 are Green
 3&4 are Yellow
 5&6 are Red
 
 */

int ledPin1 =  3;    // LED connected to digital pin
int ledPin2 =  5;    // LED connected to digital pin
int ledPin3 =  6;    // LED connected to digital pin
int ledPin4 =  9;    // LED connected to digital pin
int ledPin5 =  10;    // LED connected to digital pin
int ledPin6 =  11;    // LED connected to digital pin

// The setup() method runs once, when the sketch starts
void setup()   {                
  // initialize the digital pin as an output:
  pinMode(ledPin1, OUTPUT); 
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(ledPin4, OUTPUT);
  pinMode(ledPin5, OUTPUT);
  pinMode(ledPin6, OUTPUT);  
  randomSeed(analogRead(0));

}

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()      
{
  Flicker(random(1,4),random(2,200)); // might be a long flicker
  Glow(random(1,4),random(5,40),random(2,30));
  Flicker(random(1,4),random(200,800));   // long flicker
}
int Flicker(int col, int del){

  unsigned long currentMillis = millis();
  unsigned long startMillis = currentMillis;


  do
  {


    if (col == 1) {

      analogWrite(ledPin1, random(0, 255));
      delay(10);
      analogWrite(ledPin2, random(0, 255));
      delay(10);
    }
    if (col == 2) {

      analogWrite(ledPin3, random(0, 255));
      delay(10);
      analogWrite(ledPin4, random(0, 255));
      delay(10);
    }
    if (col == 3) {

      analogWrite(ledPin5, random(0, 255));
      delay(10);
      analogWrite(ledPin6, random(0, 255));
      delay(10);
    }
    unsigned long currentMillis = millis();

  } 
  while (millis() < (startMillis + (del * 1000)));



  analogWrite(ledPin1, 0);
  analogWrite(ledPin2, 0);
  analogWrite(ledPin3, 0);
  analogWrite(ledPin4, 0);
  analogWrite(ledPin5, 0);
  analogWrite(ledPin6, 0);





}


int Glow(int col, int cycles, int del){

  if (col == 1) {
    for (int u=1; u <= cycles; u++){

      for (int i=0; i <= 250; i = i + 4){
        analogWrite(ledPin1, i);
        analogWrite(ledPin2, i);
        delay(del);
      } 

      for (int i=0; i <= 250; i = i + 4){
        analogWrite(ledPin1, 255-i);
        analogWrite(ledPin2, 255-i);
        delay(del);
      } 


    }
  }
  analogWrite(ledPin1, 0);
  analogWrite(ledPin2, 0);
  if (col == 2) {
    for (int u=1; u <= cycles; u++){

      for (int i=0; i <= 250; i = i + 4){
        analogWrite(ledPin3, i);
        analogWrite(ledPin4, i);
        delay(del);
      } 

      for (int i=0; i <= 250; i = i + 4){
        analogWrite(ledPin3, 255-i);
        analogWrite(ledPin4, 255-i);
        delay(del);
      } 


    }
  }
  analogWrite(ledPin3, 0);
  analogWrite(ledPin4, 0);
  if (col == 3) {
    for (int u=1; u <= cycles; u++){

      for (int i=0; i <= 250; i = i + 4){
        analogWrite(ledPin5, i);
        analogWrite(ledPin6, i);
        delay(del);
      } 

      for (int i=0; i <= 250; i = i + 4){
        analogWrite(ledPin5, 255-i);
        analogWrite(ledPin6, 255-i);
        delay(del);
      } 


    }
  }



  analogWrite(ledPin1, 0);
  analogWrite(ledPin2, 0);
  analogWrite(ledPin3, 0);
  analogWrite(ledPin4, 0);
  analogWrite(ledPin5, 0);
  analogWrite(ledPin6, 0);

}

The basic setup is 6 LED’s on the PWM pins, grouped in two’s, so LEDs 1&2 are both green, 3&4 are yellow and 5&6 are red. It just goes through some basic effects. I could have done more but this is good enough for now.