A simple Simon Says game using a Grove Base Shield, 3 Grove LED Bars, 1 Grove Buzzer, and 3 Grove Buttons.
Components Used
Platform: ST-Nucleo-F401RE
Component Configuration
LED_Bar mid(D6, D5); //D5 LED_Bar right(D8, D7); //D7 LED_Bar left(D4, D3); //D3 InterruptIn button_left(A2); InterruptIn button_mid(A1); InterruptIn button_right(A0); DigitalOut buzzer(D2);
Gallery
Diff: main.cpp
- Revision:
- 11:2307c5edf18f
- Parent:
- 10:9d48af13dbd0
- Child:
- 12:73cbf84ee24a
--- a/main.cpp Fri Aug 19 15:27:17 2016 +0000 +++ b/main.cpp Fri Aug 19 16:42:40 2016 +0000 @@ -8,6 +8,9 @@ InterruptIn button_mid(A1); InterruptIn button_right(A0); DigitalOut buzzer(D2); +/* due to the type of InterruptIn .rise function call I am using (callback to + a void function), the input array has to be global since you can't use + input parameters (to my knowledge in the interrupted void function */ int input_index; int input[100]; bool start_flag = false; @@ -66,6 +69,8 @@ } } +/* void callback functions for the InterruptIn buttons - write a button index + to the input global array depending on which button was pressed */ void right_input() { input[input_index] = 1; input_index++; @@ -161,7 +166,7 @@ lose_count++; failure(); } - if (lose_count > 0) { + if (lose_count > 0) { // user lost so reset counter/level variables start_flag = false; win_count = 0; lose_count = 0;