So I'm pretty new to arduino, and I'm not that experienced with C, so as a first project i've decided to make a simple device that will display binary integers on an 8 LED display, counting up from 0.
The problem that I am having is that the digit farthest to the right (I call it 'a' in the program) does not seem to want to alternate between on and off, but instead, depending on the code, is always off or always on. The code is below. Does anyone have any idea what might be wrong with the code? I have tried moving the 'a++;" line around to try and fix the problem, but nothing works.
#define a disp_num[8]
#define b disp_num[7]
#define c disp_num[6]
#define d disp_num[5]
#define e disp_num[4]
#define f disp_num[3]
#define g disp_num[2]
#define h disp_num[1]
int t=250;
int disp_num[]={0,0,0,0,0,0,0,0};
void setup(){
pinMode(1,OUTPUT);
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
}
int hi_or_lo(int bit_in){
int bit_out;
int by_two;
by_two=bit_in/2;
if(by_two<2){
bit_out=1;
}
else{
bit_out=0;
}
return bit_out;
}
int num2disp(int array_in[]){
for(int l=1;l<9;l++){
if(array_in[l]==0){
digitalWrite(l,LOW);
}
if(array_in[l]==1){
digitalWrite(l,HIGH);
}
}
}
void loop(){
num2disp(disp_num);
a++;
if(hi_or_lo(a)==0){
a=0;
b++;
if(hi_or_lo(b)==0){
b=0;
c++;
if(hi_or_lo(c)==0){
c=0;
d++;
if(hi_or_lo(d)==0){
d=0;
e++;
if(hi_or_lo(e)==0){
e=0;
f++;
if(hi_or_lo(f)==0){
f=0;
g++;
if(hi_or_lo(g)==0){
g=0;
h++;
}
}
}
}
}
}
}
delay(t);
}