Simon Says

Start 

Using many inputs and some random instructions, this project recreates the feel of the classic Simon Says game.

Modules 

Gather the following parts to complete this project.

Parts

All Parts
All Parts
LCD Display
Button
Touch
Cable
PartQuantity
LCD Display 1
Button 1
Touch 1
Cable 4

OneButton 

Take a cable and unwrap it. Plug one side into the LCD Display and the other into any I2C socket. Take another cable and attach one end to a button and the other to Digital socket D6.

All the parts you'll need
All the parts you'll need
Take a cable...
... and unwrap it
Plug one side into the LCD Display socket
The other into any I2C socket
Take a cable...
... and unwrap it
Plug one side into the button socket
The other into any Digital socket

Upload

Upload the code below. This tutorial uses Digital socket 6. If you are using a different socket update the code after copying it.

Download file Copy to clipboard
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <rgb_lcd.h>
#include <OneButton.h>

#define buttonSocket 6

rgb_lcd lcd;
const int colorR = 0;
const int colorG = 0;
const int colorB = 0;

OneButton button1(buttonSocket, false);

void setup() {
  lcd.begin(16, 2);
  lcd.setRGB(colorR, colorG, colorB);

  button1.attachClick(click1);
  button1.attachDoubleClick(doubleclick1);
  button1.attachLongPressStart(longPressStart1);
  button1.attachLongPressStop(longPressStop1);
  button1.attachDuringLongPress(longPress1);
}

void loop() {
  button1.tick();
  lcd.setCursor(0, 0);
  lcd.print("Press the Button");
}


void click1() {
  lcd.setCursor(0, 0);
  lcd.print("Button click    ");
  delay(1000);
}


void doubleclick1() {
  lcd.setCursor(0, 0);
  lcd.print("Button Doubleclk");
  delay(1000);
}


void longPressStart1() {
  lcd.setCursor(0, 0);
  lcd.print("Longpress Start ");
  delay(1000);
}


void longPress1() {
  lcd.setCursor(0, 0);
  lcd.print("Longpress Press ");
  delay(1000);
}


void longPressStop1() {
  lcd.setCursor(0, 0);
  lcd.print("Longpress Stop  ");
  delay(1000);
}

Observe

Press the button once. Press the button twice. Hold it down. Check out all the features of the OneButton library. What was once a simple button now has many uses.

Press the button
Press the button
Let's do it
Holding the button down

Simple Simon 

Take a cable and attach one end to a touch sensor and the other to Digital socket D7.

Take a cable...
Take a cable...
... and unwrap it
Plug one side into the touch socket
The other into Digital socket D7

Upload

Upload the code below. This tutorial uses Digital socket 7. If you are using a different socket update the code after copying it.

Download file Copy to clipboard
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <rgb_lcd.h>
#include <OneButton.h>

#define buttonSocket 6
#define touchSocket 7

rgb_lcd lcd;
const int colorR = 0;
const int colorG = 0;
const int colorB = 0;

OneButton button(buttonSocket, false);
OneButton touch(touchSocket, false);

String actions[] = {"buttonSingle", "buttonDouble", "touchSingle", "touchDouble"};
String currentAction = "";
String actionTaken = "";


void setup() {
  lcd.begin(16, 2);
  lcd.setRGB(colorR, colorG, colorB);

  button.attachClick(buttonSingle);
  button.attachDoubleClick(buttonDouble);
  touch.attachClick(touchSingle);
  touch.attachDoubleClick(touchDouble);

  currentAction = actions[random(0, 4)];

  lcd.setCursor(0, 0);
  lcd.print("Action To Do:");
  lcd.setCursor(0, 1);
  lcd.print(currentAction);
}

void loop() {
  button.tick();
  touch.tick();
}


void buttonSingle() {
  actionTaken = "buttonSingle";
  correctCheck();
}

void buttonDouble() {
  actionTaken = "buttonDouble";
  correctCheck();
}

void touchSingle() {
  actionTaken = "touchSingle";
  correctCheck();
}

void touchDouble() {
  actionTaken = "touchDouble";
  correctCheck();
}

void correctCheck() {
  if (currentAction == actionTaken) {
    clearScreen();
    lcd.setRGB(0, 255, 0);
    lcd.setCursor(0, 0);
    lcd.print("Correct!");
    lcd.setCursor(0, 1);
    lcd.print("Picking Action");
    delay(2000);
    lcd.setRGB(colorR, colorG, colorB);
    currentAction = actions[random(0, 4)];
    clearScreen();
    lcd.setCursor(0, 0);
    lcd.print("Action To Do:");
    lcd.setCursor(0, 1);
    lcd.print(currentAction);
  } else {
    lcd.setRGB(255, 0, 0);
    delay(500);
    lcd.setRGB(colorR, colorG, colorB);
  }
}

void clearScreen() {
  lcd.setCursor(0, 0);
  lcd.print("                ");
  lcd.setCursor(0, 1);
  lcd.print("                ");
}

Observe

Follow the actions on screen. Green for correct and red for try again.

An action is displayed
An action is displayed
Let's do it
Correct!
Wrong!

Modify

You can change the colors that the LCD Display uses.