0

wierd code operation
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

wierd code operation

by big93 on Tue Dec 04, 2007 11:30 pm

the code i typed in is giving me a wierd affect. My code is making one led very dimm, and makes it look like it barely lights up. but when i reverse the way the code goes, the led works fine!

take a look:

Code: Select all | TOGGLE FULL SIZE

int greenpin = 13;                  // Red LED connected to digital pin 12
int bluepin = 12;                // Green LED connected to digital pin 11
int redpin = 11;

void setup()                      // run once, when the sketch starts
{
  pinMode(greenpin, OUTPUT);        // sets the digital pin as output
  pinMode(bluepin, OUTPUT);      // sets the digital pin as output
}

void loop()                       // run over and over again
{
  digitalWrite(greenpin, HIGH);     // sets the Red LED on
  delay(500);                     // waits for half a second
  digitalWrite(greenpin, LOW);      // sets the Red LED off
  digitalWrite(bluepin, HIGH);
  delay(500);
  digitalWrite(bluepin, LOW);
  digitalWrite(redpin, HIGH);
  delay(500);
  digitalWrite(redpin, LOW);
  delay(500);
 
}



, this makes the first led light up fine, the next led light up fine, and the last one lights up dimm!

but when i change the code like this:

Code: Select all | TOGGLE FULL SIZE

int greenpin = 11;                  // Red LED connected to digital pin 12
int bluepin = 12;                // Green LED connected to digital pin 11
int redpin = 13;

void setup()                      // run once, when the sketch starts
{
  pinMode(greenpin, OUTPUT);        // sets the digital pin as output
  pinMode(bluepin, OUTPUT);      // sets the digital pin as output
}

void loop()                       // run over and over again
{
  digitalWrite(greenpin, HIGH);     // sets the Red LED on
  delay(500);                     // waits for half a second
  digitalWrite(greenpin, LOW);      // sets the Red LED off
  digitalWrite(bluepin, HIGH);
  delay(500);
  digitalWrite(bluepin, LOW);
  digitalWrite(redpin, HIGH);
  delay(500);
  digitalWrite(redpin, LOW);
  delay(500);
 
}


then the order the led's light up is backward, but all of them work fine, there is not dimm led! it's strange to me, anybody know whay it's reacting this way?
big93
 
Posts: 56
Joined: Wed Nov 21, 2007 10:31 pm

by adafruit on Wed Dec 05, 2007 10:36 am

you have to set all the pins to be outputs

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm
Location: nyc

by big93 on Wed Dec 05, 2007 1:07 pm

ha, i cant believe i dident see that, thanks lady!
big93
 
Posts: 56
Joined: Wed Nov 21, 2007 10:31 pm

Please be positive and constructive with your questions and comments.