voidmydelay(unsigned int x, void (*fun)(void))
//min=10ms
{
unsigned int time_count = x/10;
volatile unsigned int comp_count =delay_counter + time_count;
//comp_count and delay_counter must is a volatilevariable
TIMSK2 |= (1<
while(delay_counter < comp_count){
//in order to notwaste CPU, you can execute your function in this loop
if(0 != fun)
fun();
}
TIMSK2 &=~(1<
}
void loop()
{
static int key_time = 0;
if(!game_over){
if(!digitalRead(key)){
if(key_time < 2)
degree = 140;
else
degree = 100;
key_time++;
}
else{
degree = 100;
key_time = 0;
}
myservo.write(degree);
// sets the servo positionaccording to the scaled value g
if(degree > 120){
mydelay(80, lcd_display);
game_time += 0.1;
mydelay(80, lcd_display);
game_time += 0.1;
}
else{
game_time += 0.1;
mydelay(80, lcd_display);
// waits for theservo to get there
}
}else{
if(!reset){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Game Over ");
lcd.setCursor(5, 1);
lcd.print(game_time);
mydelay(3000, 0);
}
reset = false;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" press key! ");
while(digitalRead(key)){
myservo.write(degree);
// sets the servo positionaccording to the scaled value
mydelay(32, 0);
// waits for theservo to get there
OCR0B = 10;
}
mydelay(64, 0);
while(!digitalRead(key));