Wednesday, September 29, 2010

Why Why Why

does something that seems so logical and direct seem simultaneously so abstract.

Trying to get several leds to light at different times and fade and then when one exstinguishes a new one lights. BUT .. the code doesnt work....yet. And I was just cheking this hoping something interesting would happen, I know i need to use PWM pins for the dimming, that will be the next step.


/*
 Fade

 This example shows how to fade an LED on pin 9
 using the analogWrite() function.

 This example code is in the public domain.

 */
int brightness = 0;
int brightness2 = 150;// how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by
int P1 = 2;    //the number of the first led being lit
int P2 = 3;   //the number of the second
int INPIN = 13;  // a pin that will tell this sequence to begin
void setup()  {
  // declare pin 9 to be an output:
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(INPIN, INPUT);
 
}

void loop()  {
  if ( INPIN = HIGH){
 
    if (brightness = 0 ) {
     P1= random (2 , 12);
  }
  // set the brightness of pin 9:
  analogWrite(P1, brightness);  

  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness == 0 || brightness == 255) {
    fadeAmount = -fadeAmount ;
  }  
  if (brightness2 = 0){
     P2= random(2 , 12);
  }
analogWrite(P2, brightness2);  

  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness == 0 || brightness == 255) {
    fadeAmount = -fadeAmount ;
  }  
 
  delay(30);// wait for 30 milliseconds to see the dimming effect                              
}
}

2 comments:

  1. Keegan, you need to change the '=' to '==' in the first four lines of your loop() and the brightness2 if statement, I think.

    ReplyDelete
  2. also, brightness2 is always 150 and never changes

    ReplyDelete