M5Stamp Pico Mate #3 – Simon says

M5Stamp Pico Mate #3 – Simon says

In this post I want to show you how to program the skill game “Simon says” on the M5Stamp Pico Mate with a few buttons and a RGB LED.

M5Stamp Pico Mate – Game “Simon say’s”

I have already introduced you to the M5Stamp Pico Mate in the article of the same name Introduction of the M5Stamp Pico. In the post M5Stamp Pico Mate #1: Programming a push button I already showed you how to program a push button on the M5Stamp and how to evaluate the signal in the code.

What is “Simon says”?

The skill game “Simon says” is about the players imitating an action, which the current game leader says, this can be e.g. “Simon says, stand on one leg!


Page “Simon says (game)”. In: Wikipedia – The free encyclopedia. Edit date: September 3, 2021, 04:13 UTC. URL: (retrieved: 26 January 2022, 10:09 UTC).

We adapt this game principle to a RGB LED and the player has to press the appropriate colored button in which the RGB LED lights up. I.e. when the RGB LED lights up red, the button with the red cap has to be pressed and so on.

Resources needed for this game

To build the game you will need:

Pinout of the M5Stamp Pico Mate

Here again is the pinout of the Pico Mate.

Pinout of the M5Stamp Pico Mate

Construction of the circuit

For the construction I use five print buttons (with colored caps) in the size 12 mm x 12 mm and of course another RGB LED


Component Pin on M5Stamp Pico Mate
Button, red G22
Pushbutton, green G18
Pushbutton, blue G19
pushbutton, yellow G21
RGB LED type SK6812 G27
8x RGB Stripe G26

Connecting the components to the M5Stamp Pico Mate Building the circuit “Simon says” on the M5Stamp Pico Mate

Programming “Simon says” in the Arduino IDE

In this little game we have four colored buttons (red, green, blue and yellow) each of these buttons represents a color in which the RGB LED can light up. Therefore we first define the possible colors in an array either by RGB values or as HTMLColorCode.

// Library to control the RGB LED #include // Pin to which the LED is connected #define INTERN_RGB_DATA_PIN 27 #define RGB_STRIPE_DATA_PIN 26 // Number of LEDs #define NUM_LEDS 9 // Button #define buttonRed 22 #define buttonGreen 18 #define buttonBlue 19 #define buttonYellow 21 // Define an object with the LEDs CRGB leds[NUM_LEDS]; // current index of the color int currentColorIndex = 0; // maximum number of colors const int NUM_COLORS = 4; // an array of colors CRGB colors[NUM_COLORS] = {CRGB::Red, CRGB::Green, CRGB::Blue, CRGB::Yellow}; // index of LEDs representing remaining “lives” int currentLeds = NUM_LEDS; // pause between color values int pause = 3000; void setup() { //start serial communication with 9600 baud Serial.begin(9600); // define that an RGB LED of type SK6812 is connected to the INTERN_RGB_DATA_PIN FastLED.addLeds(leds, 0, 1); // define d as 8 more RGB LEDs of type WS2812B are connected to pin RGB_STRIPE_DATA_PIN FastLED.addLeds(leds, 1, 9); // set brightness of LEDs to 9 (max. 10) FastLED.setBrightness(9); // Set button as input via internal 10kOhm resistor pinMode(buttonRed, INPUT_PULLUP); pinMode(buttonGreen, INPUT_PULLUP); pinMode(buttonBlue, INPUT_PULLUP); pinMode(buttonYellow, INPUT_PULLUP); // Initialize the game startGame(); } //initialize the game void startGame() { // reset the value for the remaining “lives” currentLeds = NUM_LEDS; // loop from 1 to currentLeds, // coloring the LEDs to the color red for (int i = 1; i < currentLeds; i++) { leds[i] = CRGB::Red; }; // set pause to 3000 ms pause = 3000; // reset color resetColor(); } void loop() { // evaluate the buttons and the colors if (digitalRead(buttonRed) == LOW) { testBtnIndex(0); } else if (digitalRead(buttonGreen) == LOW) { testBtnIndex(1); } else if (digitalRead(buttonBlue) == LOW) { testBtnIndex(2); } else if (digitalRead(buttonYellow) == LOW) { testBtnIndex(3); } } // Tests if the pressed button matches the current color. void testBtnIndex(int index) { if (currentColorIndex == index) { //set a new color resetColor(); } else { // button does NOT match and a “life” is subtracted” fail(); } } // subtracts one from the variable “currentLeds” and displays the current value on // the LED stripe void fail() { Serial.println(“fail”); // subtracts one from the variable currentLeds–; // If the value is greater than 1 then…. if (currentLeds > 1) { // Set all LEDs to black for (int i = 1; i <= NUM_LEDS; i++) { leds[i] = CRGB::Black; } // show; // set all LEDs to red until current “life” for (int i = 1; i < currentLeds; i++) { leds[i] = CRGB::Red; }; resetColor(); } else { // When all “lives” are used up then…. endGame(); } } // Ends the game because all “lives” have been used up. void endGame() { int p = 125; for (int i = 1; i <= NUM_LEDS; i++) { leds[i] = CRGB::Red;; delay(p); } for (int i = NUM_LEDS; i >= 1; i–) { leds[i] = CRGB::Black;; delay(p); } for (int i = 1; i <= NUM_LEDS; i++) { leds[i] = CRGB::Red;; delay(p); } startGame(); } // Subtracts 20ms from the initial value of pause (3000) // and displays a new color // Thus, the color changes faster and faster void resetColor() { pause = pause – 25; displayRandomColor(); } // display a random color from the defined array of colors void displayRandomColor() { // first dim the current LED leds[0] = CRGB::Black;; delay(pause); // get a random number from 0 to [number of colors in array] currentColorIndex = random(0, NUM_COLORS); leds[0] = colors[currentColorIndex]; Serial.println(currentColorIndex);; } <p>Here now the video of the game “Simon say’s”</p> <p>M5Stamp Pico Mate – Game “Simon say’s”</p>.

Continue reading:

Leave a Reply

Your email address will not be published.