Pages: [1]   Go Down
Author Topic: a small and easy program but went wrong  (Read 284 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 48
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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... smiley-sad

please help
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 45935
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Lost Wages
Offline Offline
Full Member
***
Karma: 11
Posts: 103
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
« Last Edit: January 30, 2013, 07:30:20 pm by MaJiG » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 48
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Temple, Texas
Offline Offline
Sr. Member
****
Karma: 14
Posts: 354
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 48
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley


yep... thanks smiley
Logged

Pages: [1]   Go Up
Jump to: