Counter
hello guys....first wonder if can make counter , d-latch arduino make project shown in image in attachment....i searched these think methods found complicating me started make simpler code know it's not perfect 1 think it's easy understand so....my question : "is there simple way right code ?.....and in advance
code: [select]
const int led1=7;
const int led2=8;
const int button1=3;
const int button2=5;
int i=0;
int z=0;
double counter=0;
int b1s;
int b2s;
void setup()
{
pinmode(led1, output);
pinmode(led2, output);
pinmode(button1, input);
pinmode(button2, input);
}
void loop()
{
b1s=digitalread(button1);
b2s=digitalread(button2);
if(b1s==high&&b2s==low){i=1;}
if(i==1){digitalwrite(led1,high); digitalwrite(led2,low); counter++;}
else if(i==0 && z==0){digitalwrite(led1,low); digitalwrite(led2,low);}
if(b2s==high&&b1s==low){z=1; i=0;}
if(z==1)
{
if(counter != 0){digitalwrite(led1,low); digitalwrite(led2,high); counter--;}
else if(counter == 0){digitalwrite(led1,low); digitalwrite(led2,low); z=0;}
}
}
a class homework problem?
Arduino Forum > Using Arduino > Programming Questions > Counter
arduino
Comments
Post a Comment