Dobrý večer, chtěl bych se zeptat, jestli by někdo dokázal přepsat tento kód pro Mikrokontrolér ATMEGA8.
#include <stdio.h>
#include <unistd.h>
// global variables
int minutes = 0;
int secs = 0;
int showTime() {
// if second is lower than 10, add 0 before
if(secs < 10){
// minutes:seconds
printf("%d:0%d\n", minutes, secs);
} else {
printf("%d:%d\n", minutes, secs);
}
return 0;
}
// set time in seconds
int setTime(int time){
// if number is smaller than one hour
if(time <= 3600){
for (int i = 1; i<= time; i++) {
usleep(500);
secs++;
if((i%60) == 0){
minutes++;
secs = 0;
showTime();
} else {
showTime();
}
sleep(1);
}
} else {
printf("Toto pocitadlo je jen do 60 minut!");
}
minutes = secs = 0; // set default values
setTime(time); // recursion - infinite loop
return 0;
}
int main()
{
setTime(3600); // time in seconds
return 0;
}
Děkuji.