

The main body of the project is a while True, which will run the game code. Each time the loop iterates it uses the rainbow_cycle function to create a light show when the game starts. Create a for loop which will repeat 10 times. Create a list called “colors,” and use it to store the color tuples we created earlier. This function is part of Adafruit’s standard “strand test” demo. Create a function, rainbow_cycle which will cycle through all of the NeoPixels, displaying a rainbow effect. Create five tuples (data storage objects) to store the RGB color values for the buttons and to turn the LEDs off. The way we have connected the button to the Pico will pull this pin to GND (low) when the red button is pressed. Using a pull up resistor we pull GPIO 27 high to 3.3V. Set the GPIO pin for the red button so that it pulls high. Set the GPIO pin for the red button as an input. Create an object, red, which represents the red button connected to GPIO 27. pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.3, auto_write=False)Ĩ. We also set the brightness to 0.3 (30%) to reduce eye strain. Create an object, “pixels” and use it to connect to the NeoPixels using the two variables that identify the GPIO pin and the number of pixels. Setup GPIO 28 as the pin used to control our NeoPixels, then create a variable called num_pixels to store the number of NeoPixel LEDs. from random import choice, uniformįrom digitalio import DigitalInOut, Direction, PullĦ. In this case we want to use inputs (buttons) and set the internal resistor of the GPIO pins so that it pulls up (3.3V). DigitalIO works with the Board library to finetune how we use the GPIO.
SIMON SAYS AI GENERATOR
Uniform is a random number generator for float numbers. Random has many functions but choice enables us to pick “randomly” from lists, tuples, dictionaries etc. From random import choice and uniform, and from digitailio import DigitalInOut, Direction and Pull to handle input / output, pin direction and support for pull up resistors (see resistor color codes for help identifying different sizes). NeoPixel is the library used to control the eight RGB LEDs. Colorwheel is an animation tool that we will use to create a rainbow cycle effect. Import two more libraries for advanced control of NeoPixels. Time contains functions to pause the code, whereas Board provides basic GPIO access. Time and Board are used common CircuitPython libraries. Import libraries to control the speed of the game, and for access to the GPIO. Open the code.py file found in the root of the CIRCUITPY drive in your preferred editor.ģ.
SIMON SAYS AI CODE
(Image credit: Tom's Hardware) Writing the Code for Simon Game on Raspberry Pi Picoġ.
