Learning Outcome

In this chapter, we learn to


Introduction: OLED and Gesture Sensor

Activities: Build a hearing reaction game with gesture and buzzer (Do-Re-Mi-Fa Arcade)

Challenge 1: Improve game test tone by displaying notes on OLED. 

Challenge 2: Program a hearing-gesture directory for better gaming experience.

Introduction to OLED

You can think of the OLED display as a very small, electronic billboard. It's like the display on your smartphone but much smaller. Like an electronic billboard, you can choose what to show on it. In this activity, we will learn how to code and print on the EDU PICO's OLED display module.

> Libraries <

-> Libraries: board, busio, time, adafruit_ssd1305, font5x8.bin.

-> OLED I2C Pins Configuration: SCL = GP5 and SDA = GP4.

 < CircuitPython Code >

Click here to download code

< Expected Output >

Upon completion of the activity, you should be able to:

-> Invert OLED display at initialization with a bluish-white background.

-> The program will displayed text on OLED

Mini Activity

Modify the code to allow user to type their name in the shell console and print the name on the OLED display. Replace the code from Line 7 to Line 11 with the code provided below.

> Libraries <

-> Libraries: board, busio, time, adafruit_ssd1305, font5x8.bin.

-> OLED I2C Pins Configuration: SCL = GP5 and SDA = GP4.

< CircuitPython Code >

Click here to download code

< Expected Output >

Upon completion of the activity, you should be able to:

-> Build a program to display your name on OLED

Introduction to Gesture Sensor

In this section, we'll explore how APDS9960 sensor can be used to detect hand gestures. The APDS9960 is a tiny electronic device that can "see" hand gestures and measure the amount of light around it. It's like having a tiny robot eye!

> Libraries <

-> Libraries: board, busio, adafruit_apds9960.

-> APDS9960 I2C Pins Configuration: SCL = GP5 and SDA = GP4.

-> Input: By perfoming various hand gestures in front of the sensor, the code will display direction to the shell console:

< CircuitPython Code >

Click here to download code

< Expected Output >

Upon completion of the activity, you should be able to:

-> The program code will display direction in the shell console after performing various hand gestures.

Gesture Reaction Game

Do-Re-Mi-Fa Arcade

Let's build our first arcade game. But this won't be your typical game, instead, this is going to help players improve their hand-eye coordination. In this project, we'll learn to integrate OLED display , buzzer, and APDS9960 gesture sensor, so be prepared for a slight increase in difficulty. Ready? Let's get started!

> Libraries <

-> Libraries: board, digitalio, time, simpleio, busio, adafruit_apds9960, adafruit_ssd1306, random, font5x8.bin.

-> OLED & APDS9960 I2C Pins Configuration: SCL = GP5, SDA = GP4.

-> Audio / Buzzer Configuration: Buzzer to GP21.

-> Button Configuration:

-> Input:

< CircuitPython Code >

Click here to download code

< Expected Output >

Upon completion of the activity, you should be able to:

-> The buzzer will play a random game tone, either DO, RE, MI, or FA.

-> If the player gives a wrong answer, the OLED will display "Try again" with a sad beep.

Challenges

#1 "DO RE MI FA" Tone Tester

Since we are building a reaction arcade game with OLED display, why not we challenge ourselves to make it even better? Let’s provide the player more information about the test tones when they press Button A.

> Libraries <

-> Libraries: board, digitalio, time, simpleio, busio, adafruit_apds9960, adafruit_ssd1306, random, font5x8.bin.

-> OLED & APDS9960 I2C Pins Configuration: SCL = GP5, SDA = GP4.

-> Audio / Buzzer Configuration: Buzzer to GP21.

-> Button Configuration:

< CircuitPython Code >

Click here to download code

< Expected Output >

Upon completion of the activity, you should be able to:

-> Press button A to get information about test tones

#2 Player's Experience

After playing for a few rounds, it can become frustrating if you don’t know which gesture direction represent which tone. To enhance the gaming experience, consider implementing a straightforward gesture directory to guide the player while they guess the gesture as shown in the image below.

> Libraries <

-> Libraries: board, digitalio, time, simpleio, busio, adafruit_apds9960, adafruit_ssd1306, random, font5x8.bin.

-> OLED & APDS9960 I2C Pins Configuration: SCL = GP5, SDA = GP4.

-> Audio / Buzzer Configuration: Buzzer to GP21.

-> Button Configuration:

< CircuitPython Code >

Click here to download code

< Expected Output >

Upon the completion of the activity, you should be able to:

-> OLED will display gesture direction if player gives the wrong answer.

Congratulations on Completing Chapter 3! Onward to the Next Chapter!"