Tell me more ×
Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It's 100% free, no registration required.

I am trying to make some Arduino code count on a 7 segment display. I have the wiring all right but this code will not delay one second and go to next function. Any ideas?

/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
  This example code is in the public domain.
 */

void setup() {                
  // initialize the digital pin as an output.
  // Pin 13 has an LED connected on most Arduino boards:
  pinMode(3,OUTPUT);    pinMode(4,OUTPUT);    pinMode(5,OUTPUT);
  pinMode(6,OUTPUT);    pinMode(7,OUTPUT);    pinMode(8,OUTPUT);
  pinMode(9,OUTPUT); 
}   

void n0() {
  digitalWrite(3,LOW);  digitalWrite(4,LOW);  digitalWrite(5,LOW);
  digitalWrite(6,LOW);  digitalWrite(7,LOW);  digitalWrite(8,LOW);
  digitalWrite(9,HIGH);
}

void ndash() {
  digitalWrite(3,HIGH); digitalWrite(4,HIGH); digitalWrite(5,HIGH);
  digitalWrite(6,HIGH); digitalWrite(7,HIGH); digitalWrite(8,HIGH);
  digitalWrite(9,LOW);
}

void loop() {
  n0();
  delay(1000);
  ndash();
}
share|improve this question

1 Answer

up vote 6 down vote accepted

If I understand your symptoms correctly, you need a second delay.

Here's what the code looks like if you executed the loop a few times:

  n0();
  delay(1000);
  ndash();
  n0();
  delay(1000);
  ndash();
  n0();
  delay(1000);
  ndash();
  n0();
  delay(1000);
  ndash();

ndash() is only displayed for however long it takes for n0() to execute, which is probably too fast to see.

share|improve this answer
1  
The underlying C in Arduino is basically this: int main() {setup(); for(;;) {loop();}} – Nick T Dec 6 '10 at 7:23
good answer - I agree 100% – vicatcu Dec 6 '10 at 16:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.