Skip to content

Commit 04859cb

Browse files
authored
Merge pull request #608 from adafruit/TheKitty-patch-65
Add code for CPX Pinata
2 parents 6af60f2 + 835f2ea commit 04859cb

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

  • Cirecuit_Playground_Express_Pinata
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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

0 commit comments

Comments
 (0)