Go Down

Topic: a small and easy program but went wrong (Read 396 times) previous topic - next topic

Hani

Hi all....
I have the VBB program so will i was testing my solenids i had a problem with the program and here it is....
Code: [Select]

int voltone = 2;
int volttwo = 4;

void setup() {

  Serial.begin(9600);
 
  pinMode(voltone, OUTPUT);
  pinMode(volttwo, OUTPUT);
}


void loop() {
 
  digitalWrite(voltone, HIGH);   
  delay(1000);               
  digitalWrite(volttwo, HIGH);   
  delay(1000);
  digitalWrite(voltone, LOW);
  digitalWrite(volttwo, LOW);
}



what am i expecting from this code is to set one "LED"(for example) on then wait then set the other "LED 2" on then turn off LED and finally turn off LED2 .... but that is not what i'm getting! ..... what i'm getting is this.... LED is on and remain on while LED2 blinks with no end... :(

please help

PaulS

Think about what your program is doing:

forever:
  Turn led 1 on
  wait
  Turn led 2 on
  wait
  Turn led 1 off
  Turn led 2 off
repeat.

Waiting a bit after turning them off might matter.

MaJiG

#2
Jan 31, 2013, 01:27 am Last Edit: Jan 31, 2013, 01:30 am by MaJiG Reason: 1
Your code is good! Up to a point.

What is happening is that after you turn both LEDs OFF, you need another delay to see it. Just add another delay(1000) at the bottom of the code.

What is happening right now is that LED1 is turned OFF at the bottom of the code and right back ON at the top.

Good luck!

Hani

ahaa.... so its just the delay which will make me see what actually happens

johncc

Yes.  Another way to look at it is that the time between the end of "void loop()" and the beginning of it, is almost zero.  That's the "loop" part :)

Hani

Quote

Yes.  Another way to look at it is that the time between the end of "void loop()" and the beginning of it, is almost zero.  That's the "loop" part :)



yep... thanks :)

Go Up