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 random
5+ import board
6+ import pulseio
7+ from adafruit_motor import servo
8+ from adafruit_circuitplayground .express import cpx
9+
10+ # create a PWMOut object on CPX Pin A1
11+ pwm = pulseio .PWMOut (board .A1 , frequency = 50 )
12+ # Create a servo object cpx_servo
13+ cpx_servo = servo .Servo (pwm )
14+
15+ hits = 0
16+ max_hits = random .randint (3 , 10 )
17+ cpx .detect_taps = 1 # Detect single taps
18+ cpx_servo .angle = 0
19+ cpx .pixels .fill ((0 , 0 , 0 )) # All NeoPixels off
20+
21+ while hits < max_hits :
22+ if cpx .tapped :
23+ print ("Hit!" )
24+ hits += 1
25+ cpx .pixels .fill ((255 , 255 , 255 )) # All White
26+ cpx .play_file ("hit.wav" )
27+ time .sleep (1.0 ) # Wait time in seconds
28+ cpx .pixels .fill ((0 , 0 , 0 )) # All off
29+ time .sleep (0.1 )
30+
31+ # Hits Reached, Payout!
32+ print ("Release!" )
33+ cpx .pixels .fill ((0 , 255 , 0 )) # All green
34+ cpx .play_file ("candy.wav" )
35+ cpx_servo .angle = 180
36+ print ("Press Reset or power cycle to reset device" )
37+ while True :
38+ pass # Infinite loop, press Reset button to reset
You can’t perform that action at this time.
0 commit comments