Hello, Im in big trouble.. actually we have a test in school And I need to do stopwatch on A1,A2,A3 buttons with START, STOP, RESET.. i dont really know what to do..And how to do it. I have this code for numbers but I need to do it in stopwatch form.. please help.. heres my code atm
#define latchPin 4
#define clockPin 7
#define dataPin 8
#define button A1
int x,y,cnt=0;
long timer=0;
const byte segment[] = {B00000011, B10011111, 0B00100101, 0B00001101, 0B10011001,
0B01001001, 0B01000001, 0B00011111, 0B00000001/, 0B00001001, 0B00010001,
0B11000001, 0B01100011, 0B10000101, 0B01100001, 0B01110001/};
const byte digit[] = {0x01, 0x02, 0x04, 0x08};
void setup() {
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(button, INPUT);
}
void loop() {
if(millis()>timer+100)
{
timer=millis();
cnt++;
if(cnt==10000) cnt=0;
}
gg(segment[cnt%10], digit[3]);
gg(segment[cnt%100/10], digit[2]);
gg(segment[cnt%1000/100], digit[1]);
gg(segment[cnt%10000/1000], digit[0]);
}
void gg(int x, int y)
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, x);
shiftOut(dataPin, clockPin, MSBFIRST, y);
digitalWrite(latchPin, HIGH);
}
PM: I dont know how to do quetoes on mobile, so im sorry for that