0

I want to make an LED one digit display using 14 leds used in pairs so I have 7 pairs which show number. (Similar to the display in calculators). Now the problem is that my code won't function properly. The problem that is arising is that the leds won't go off, all of them would work at the same time, here's the code

int a = 2;
int b = 3;
int c = 4;
int d = 5;
int e = 6;
int f = 7;
int g = 8;
void setup()
{
 for(int i = 2; i++ ; i<9)
 {
 pinMode (i, OUTPUT);
 }
}
void _1()
{
 digitalWrite ( b, HIGH);
 digitalWrite ( f, HIGH);
 delay(1000);
}
void _2()
{
 digitalWrite ( a, HIGH);
 digitalWrite ( b, HIGH);
 digitalWrite ( d, HIGH);
 digitalWrite ( e, HIGH);
 digitalWrite ( g, HIGH);
 delay(1000);
}
void _3()
{
 digitalWrite ( a, HIGH);
 digitalWrite ( b, HIGH);
 digitalWrite ( d, HIGH);
 digitalWrite ( f, HIGH);
 digitalWrite ( g, HIGH);
 delay(1000);
}
void _4()
{
 digitalWrite ( c, HIGH);
 digitalWrite ( d, HIGH);
 digitalWrite ( f, HIGH);
 digitalWrite ( b, HIGH);
 delay(1000);
}
void _5()
{
 digitalWrite ( a, HIGH);
 digitalWrite ( c, HIGH);
 digitalWrite ( d, HIGH);
 digitalWrite ( f, HIGH);
 digitalWrite ( g, HIGH);
 delay(1000);
}
void _6()
{
 digitalWrite ( a, HIGH);
 digitalWrite ( c, HIGH);
 digitalWrite ( e, HIGH);
 digitalWrite ( f, HIGH);
 digitalWrite ( g, HIGH);
 digitalWrite ( d, HIGH);
 delay(1000);
}
void _7()
{
 digitalWrite ( a, HIGH);
 digitalWrite ( b, HIGH);
 digitalWrite ( f, HIGH);
 delay(1000);
}
void _8()
{
 digitalWrite ( a, HIGH);
 digitalWrite ( b, HIGH);
 digitalWrite ( c, HIGH);
 digitalWrite ( d, HIGH);
 digitalWrite ( e, HIGH);
 digitalWrite ( f, HIGH);
 digitalWrite ( g, HIGH);
 delay(1000);
}
void _9()
{
 digitalWrite ( a, HIGH);
 digitalWrite ( b, HIGH);
 digitalWrite ( c, HIGH);
 digitalWrite ( d, HIGH);
 digitalWrite ( f, HIGH);
 delay(1000);
}
void _0()
{
 digitalWrite ( a, HIGH);
 digitalWrite ( b, HIGH);
 digitalWrite ( c, HIGH);
 digitalWrite ( e, HIGH);
 digitalWrite ( f, HIGH);
 digitalWrite ( g, HIGH);
 delay(1000);
}
void wait()
{
 digitalWrite ( a, LOW);
 digitalWrite ( b, LOW);
 digitalWrite ( c, LOW);
 digitalWrite ( d, LOW); 
 digitalWrite ( e, LOW);
 digitalWrite ( f, LOW);
 digitalWrite ( g, LOW);
 delay(100);
}
void loop()
{
 _0();
 wait();
 _1();
 wait();
 _2();
 wait();
 _3();
 wait();
 _4();
 wait();
 _5();
 wait();
 _6();
 wait();
 _7();
 wait();
 _8();
 wait();
 _9();
 wait(); 
}

The problem is that it stays at _0 and then never changes. Any suggestions?

JRobert
15.4k3 gold badges24 silver badges51 bronze badges
asked Aug 29, 2015 at 6:59
1
  • Ohk the mistake was found and rectified. Thanks Commented Aug 29, 2015 at 10:10

1 Answer 1

2

The for loop in your setup() function isn't quite right. The condition (i<9) and the iterator (i++) need to be the other way round, like this:

for (int i = 2; i<9; i++)
{
 pinMode (i, OUTPUT);
}
answered Aug 29, 2015 at 7:31
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.