A simple Simon Says game using a Grove Base Shield, 3 Grove LED Bars, 1 Grove Buzzer, and 3 Grove Buttons.

Dependencies:   LED_Bar mbed

Components Used

Platform: ST-Nucleo-F401RE

Components / Grove Shield V2
As an expansion board, Base Shield v2 has many Grove connectors, making it convenient for you to use Grove products together
Digital on / off buzzer
Seeed Grove Button module with digital interface
The Grove LED Bar is comprised of a 10 segment LED gauge bar and an MY9221 LED controlling chip.

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

main.cpp

Committer:
jplunkett
Date:
2016-08-17
Revision:
0:67efb4657416
Child:
1:1aca092ceb7e

File content as of revision 0:67efb4657416:

#include "mbed.h"
#include "LED_Bar.h"

LED_Bar bar(D6, D5);
DigitalIn button1(A3);
DigitalIn button2(A2);
DigitalIn button3(A1);
DigitalIn button4(A0);
int button_index;

int main() {
    bar.setLevel(0);
    while(1) {
        wait(0.3);
        if (button1) { 
            button_index = 1;
            while(button1){
                bar.setSingleLed(9, 1); 
                bar.setSingleLed(8, 1);
            }; 
            bar.setSingleLed(9, 0); 
            bar.setSingleLed(8, 0);
        }
        if (button2) { 
            button_index = 2;
            while(button2){
                bar.setSingleLed(7, 1); 
                bar.setSingleLed(6, 1);
            }; 
            bar.setSingleLed(7, 0); 
            bar.setSingleLed(6, 0);
        }
        if (button3) { 
            button_index = 3;
            while(button3){
                bar.setSingleLed(5, 1); 
                bar.setSingleLed(4, 1);
            }; 
            bar.setSingleLed(5, 0); 
            bar.setSingleLed(4, 0);
        }
        if (button4) { 
            button_index = 4;
            while(button4){
                bar.setSingleLed(3, 1); 
                bar.setSingleLed(2, 1);
            }; 
            bar.setSingleLed(3, 0); 
            bar.setSingleLed(2, 0);
        }
    }
}