File tree Expand file tree Collapse file tree
Cirecuit_Playground_Express_Pinata Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # Circuit Playground Express Piñata by Dano Wall for Adafruit Industries
2+ # CircuitPython code by Mike Barela for Adafruit Industries, MIT License
3+ import time
4+ import board
5+ import pulseio
6+ import random
7+ from adafruit_motor import servo
8+ import gc
9+ from adafruit_circuitplayground .express import cpx
10+ gc .collect ()
11+
12+ # create a PWMOut object on CPX Pin A1
13+ pwm = pulseio .PWMOut (board .A1 , frequency = 50 )
14+ # Create a servo object cpx_servo
15+ cpx_servo = servo .Servo (pwm )
16+
17+ hits = 0
18+ max_hits = random .randint (3 , 10 )
19+ cpx .detect_taps = 1 # Detect single taps
20+ cpx_servo .angle = 0
21+ cpx .pixels .fill ((0 , 0 , 0 )) # All NeoPixels off
22+
23+ while hits < max_hits :
24+ if cpx .tapped :
25+ print ("Hit!" )
26+ hits += 1
27+ cpx .pixels .fill ((255 , 255 , 255 )) # All White
28+ cpx .play_file ("hit.wav" )
29+ time .sleep (1.0 ) # Wait time in seconds
30+ cpx .pixels .fill ((0 , 0 , 0 )) # All off
31+ time .sleep (0.1 )
32+
33+ # Hits Reached, Payout!
34+ print ("Release!" )
35+ cpx .pixels .fill ((0 , 255 , 0 )) # All green
36+ cpx .play_file ("candy.wav" )
37+ cpx_servo .angle = 180
38+ print ("Press Reset or power cycle to reset device" )
39+ while True :
40+ pass # Infinite loop, press Reset button to reset
You can’t perform that action at this time.
0 commit comments