/** * Displays the given `mesg` on the LCD while waiting for the user to press one of the * push buttons. * * Assumes that `init_push_buttons()` has been called before this was called. * If the given `mesg` is either NULL or the empty string, the LCD screen is not changed. * Otherwise, the LCD is cleared and the given `mesg` is printed to it. If `mesg` was * printed, then it will be cleared before returning. */ uint8_t wait_button(char *mesg) { uint8_t b; bool print_mesg = ((mesg != 0) && (*mesg != '\0')); // Wait to make sure that function does not immediately return because of a previous input. wait_ms(200); if (print_mesg) { lcd_clear(); lcd_puts(mesg); } // Wait while the button is not being pushed. do { b = read_push_buttons(); } while (b == 0); if (print_mesg) { lcd_clear(); } // Wait to make sure that the current press does not affect subsequent input. wait_ms(200); return b; }
void part1() { char button = 1; while(1) { // loop indefinitely button = read_push_buttons(); lprintf("Button: %d", button); } }
int main( void ) { char buffer[21] = {'\0'}; int i = 0; USART_Init ( calcUBRR() ); init_push_buttons(); lcd_init(); while(1){ switch(read_push_buttons()) { case '6': USART_Transmit('Y'); break; case '5': USART_Transmit('N'); break; case '4': Transmit_String("AHHHH!!!!"); break; case '3': Transmit_String("This"); break; case '2': Transmit_String("computer is"); break; case '1': Transmit_String("broken!"); break; } wait_ms(100); /* unsigned char new_letter = USART_Receive(); if(new_letter != 13) { buffer[i++] = new_letter; } USART_Transmit(new_letter); lprintf("%d, %c", i, new_letter); if(i == 20 || new_letter == 13) { if(new_letter == 13) { USART_Transmit(10); } i = 0; lprintf("%s", buffer); for(int j=0;j<20;j++) { buffer[j] = 0; } } */ } }
static void handle200msTick() { /* No need to disable other interrupts while handling * since only the flags are volatile */ /* Poll buttons and handle increment/decrement */ uint8_t button = read_push_buttons(); switch (button) { case 6: hours++; break; case 5: hours--; break; case 4: minutes++; break; case 3: minutes--; break; case 2: seconds++; break; case 1: seconds--; break; case 0: break; } /* Handle rollovers while pushing buttons. Does not cascade*/ if (hours == 24) hours = 0; if (hours > 24) hours = 23; if (minutes == 60) minutes = 0; if (minutes > 60) minutes = 59; if (seconds == 60) seconds = 0; if (seconds > 60) seconds = 59; /* Formatting string and print */ lprintf("%02d:%02d:%02d", hours, minutes, seconds); }