0
int j;
void setup()
{
   for(j=2 ; j<=9 ; j++)
      pinMode( j , OUTPUT );
   digitalWrite( 2, HIGH );
}
void one()
{
   digitalWrite( 3, HIGH );
   digitalWrite( 4, HIGH );
}
void all_off()
{
   for(j=3 ; j<9 ; j++)
      digitalWrite( j,LOW);
}
void loop()
{
   one();
   delay(1000);
   all_off();
   delay(3000);
}

Trying to do a blinking "1" (stopped at 1 before continuing other numbers because of this problem ) with a single-digit 7 segment display. Where pin 2 is comnected to the com pins of the display.

Expected: display 1 for a second , then turn off for 3 seconds.

Reality: display1 for 3 seconds then turn off for a second.

Tried putting the delay functions in the one and all_off functions but no use.

Tried changing the delay(1000) to delay(7000) , the off time increased.

Tried changing the delay(3000) to delay(1000) , the turn on time changed to 1 second.

The code should work in order, should it not? What is happening? How to fix it?

  • And the wiring/circuit? – Mikael Patel May 14 '16 at 20:50
1

Without circuit information and part numbers, one can't say for sure what the problem is. However, the symptoms suggest that your LEDs turn on when you pull some pin low, rather than when it goes high. This can happen if, for example, the LED anodes are wired (through a resistor) to V+ and the cathodes are connected to a drive pin. If, however, the cathodes are connected to ground through a transistor, positive-logic should apply, rather than negative logic.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.