from machine import Pin, PWM
import time
import random
import machine
RESET_BUTTON = 1
GREEN_BUTTON = 5
RED_BUTTON = 9
BLUE_BUTTON = 13
YELLOW_BUTTON = 15
SPEAKER = 16
YELLOW_LIGHT = 17
BLUE_LIGHT = 18
RED_LIGHT = 26
GREEN_LIGHT = 28
# Set up our buttons and LEDs
game_controls = {
'red': {
'button': Pin(RED_BUTTON, Pin.IN, Pin.PULL_UP),
'led': Pin(RED_LIGHT, Pin.OUT),
},
'blue': {
'button': Pin(BLUE_BUTTON, Pin.IN, Pin.PULL_UP),
'led': Pin(BLUE_LIGHT, Pin.OUT),
},
'green': {
'button': Pin(GREEN_BUTTON, Pin.IN, Pin.PULL_UP),
'led': Pin(GREEN_LIGHT, Pin.OUT),
},
'yellow': {
'button': Pin(YELLOW_BUTTON, Pin.IN, Pin.PULL_UP),
'led': Pin(YELLOW_LIGHT, Pin.OUT),
}
}
speaker = PWM(Pin(SPEAKER)) # Change pin number as needed
def play_tone(frequency, duration):
"""Play a tone on the speaker"""
speaker.freq(frequency)
speaker.duty_u16(30000)
time.sleep_ms(duration)
speaker.duty_u16(0)
time.sleep_ms(50) # Small gap between sounds
play_tone(440, 200)