Stopwatch with 3 buttons

Hello
I need to make stopwatch using 3 buttons. I’ve written the program but I just can’t get it right. I would be very thankfull if someone took a look on this program.

#include <LiquidCrystal.h>
#define tipka_A A0
#define tipka_B A1
#define tipka_C A2
bool a;
bool b;
bool c;
byte funkcija = 2;
volatile int index = 0;
volatile byte timer_preklop_osebni_podatki = 20; //sprememba 3 s
String tabela = {“MIHAEL”, “MEVLJA”, " LUKA ", " JARC "};
//stoparca*********************
volatile byte timer_stoparca = 61;
volatile byte stevec = 0;
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);//LiquidCrystal(rs, enable, d4, d5, d6, d7)
void setup() {
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print(tabela[index]);
pinMode(tipka_A, INPUT);
pinMode(tipka_B, INPUT);
pinMode(tipka_C, INPUT);
nastavitev_prekinitve_timer0_prescaler_1024(61);

}
void loop() {
lcd.setCursor(0, 0);
lcd.print(tabela[index]);
lcd.setCursor(5, 1);
lcd.print(stevec);
if (stevec < 10) {
lcd.setCursor(6, 1);
lcd.print(" ");
}
tipke();
}
//********************************ISR(TIMER0_COMPA_vect) {
//sprememba teksta

if (timer_preklop_osebni_podatki == 0) {
//sprememba
index++;
if (index == 4) {
index = 0;
}
timer_preklop_osebni_podatki = 20;

} else {
timer_preklop_osebni_podatki–;//daljši zapis: timer_preklop_osebni_podatki=timer_preklop_osebni_podatki-1
}
//proces stoparca**************************************************
if (timer_stoparca == 0) {
//sprememba
switch (funkcija) {
case 1:
start();
break;
case 2:
stop_s();
break;
case 3:
reset();
break;
}

timer_stoparca = 5;

} else {
timer_stoparca–;
}
}

void nastavitev_prekinitve_timer0_prescaler_1024(int fp) {
cli();//ustavitev vseh prekinitev
TCCR0A = 0;// nastavitev začetne vrednosti registra TCCR0A
TCCR0B = 0;// nastavitev začetne vrednosti registra TCCR0B
TCNT0 = 0;//inicializacija števca TCNT0
// nastavitev compare match registra za željeno frekvenco prekinitve fp=1610^6/(prescaler(OCR0A+1)
OCR0A = ((16 * 10 ^ 6) / (fp * 1024)) - 1;
//CTC način delovanja
TCCR0A |= (1 << WGM01);
//CS02=0, CS01=0, CS00=1 (prescaler=1)
//CS02=0, CS01=1, CS00=0 (prescaler=8)
//CS02=0, CS01=1, CS00=1 (prescaler=64)
//CS02=1, CS01=0, CS00=0 (prescaler=256)
//CS02=1, CS01=0, CS00=1 (prescaler=1024)
TCCR0B |= (1 << CS02);
TCCR0B |= (0 << CS01);
TCCR0B |= (1 << CS00);
// omogoči prekinitev na timer0
TIMSK0 |= (1 << OCIE0A);
sei();//aktivacija vseh prekinitev
}
void tipke() {
a = digitalRead(tipka_A);
if (a == 0) {
do {
a = digitalRead(tipka_A);
} while (a == 0);
funkcija = 1;
}
b = digitalRead(tipka_B);
if (b == 0) {
do {
b = digitalRead(tipka_B);
} while (b == 0);
funkcija = 2;
}
c = digitalRead(tipka_C);
if (c == 0) {
do {
c = digitalRead(tipka_C);
} while (c == 0);
funkcija = 3;
}
}
void start() {
stevec++;
if (stevec == 31) {
stevec = 30;
}
}
void stop_s() {
stevec = stevec;
}
void reset() {
stevec = 0;
}

You could give us a clue or 2 about what the code actually does and how that differs from what you want it to do (which we don’t know either).

Read the how to use this forum stickies to see how to post code and some advice on how to ask a question. Use the IDE autoformat tool to make your code easer to follow.

Without looking too deeply you've got inputs initialized as:

pinMode(tipka_A, INPUT);

and in your code are looking for the pins to be LOW:

.
.
.
a = digitalRead(tipka_A);
  if (a == 0) {
    do {
      a = digitalRead(tipka_A);
    } while (a == 0);
.
.
.

Do you have external pull-up resistors on these inputs?

The more typical way to use buttons is to initialize the pins to INPUT_PULLUP and use a switch that, when pressed, grounds the pin.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html .
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :slight_smile: