44Buttons A and B advance forward and backward through the circle. The switch selects
55the type of arpeggio, either dominant seventh or blues.
66
7- You can ignore the FrequencyProvider class if you’re just interested in the CPX interface.
7+ You can ignore the FrequencyProvider class if you’re just interested in the Circuit Playground
8+ interface.
89
910See a code walkthrough here: https://www.youtube.com/watch?v=cDhqyT3ZN0g
1011"""
1112
1213# pylint: disable=R0903
1314import time
14- from adafruit_circuitplayground . express import cpx
15+ from adafruit_circuitplayground import cp
1516
1617HS_OCT = 12 # Half-steps per octave
1718HS_4TH = 5 # Half-steps in a fourth
@@ -65,11 +66,11 @@ def freq(self, normalized_position, selected_arpeg):
6566class ButtonDetector :
6667 def __init__ (self ):
6768 self .next_press_allowed_at = time .monotonic ()
68- self .buttons_on = (cpx .button_a , cpx .button_b )
69+ self .buttons_on = (cp .button_a , cp .button_b )
6970
7071 def pressed (self , index ):
7172 """Return whether the specified button (0=A, 1=B) was pressed, limiting the repeat rate"""
72- pressed = cpx .button_b if index else cpx .button_a
73+ pressed = cp .button_b if index else cp .button_a
7374 if pressed :
7475 now = time .monotonic ()
7576 if now >= self .next_press_allowed_at :
@@ -80,7 +81,7 @@ def pressed(self, index):
8081
8182class TiltingArpeggios :
8283 def __init__ (self ):
83- cpx .pixels .brightness = 0.2
84+ cp .pixels .brightness = 0.2
8485 self .freq_maker = FrequencyMaker ()
8586 TiltingArpeggios .update_pixel (self .freq_maker .circle_pos )
8687 self .button = ButtonDetector ()
@@ -97,18 +98,18 @@ def run(self):
9798 @staticmethod
9899 def update_pixel (circle_pos ):
99100 """Manage the display on the NeoPixels of the current circle position"""
100- cpx .pixels .fill ((0 , 0 , 0 ))
101+ cp .pixels .fill ((0 , 0 , 0 ))
101102 # Light the pixels clockwise from “1 o’clock” with the USB connector on the bottom
102103 pixel_index = (4 - circle_pos ) % 10
103104 # Use a different color after all ten LEDs used
104105 color = (0 , 255 , 0 ) if circle_pos <= 9 else (255 , 255 , 0 )
105- cpx .pixels [pixel_index ] = color
106+ cp .pixels [pixel_index ] = color
106107
107108 @staticmethod
108109 def tilt ():
109110 """Normalize the Y-Axis Tilt"""
110111 standard_gravity = 9.81 # Acceleration (m/s²) due to gravity at the earth’s surface
111- constrained_accel = min (max (0.0 , - cpx .acceleration [1 ]), standard_gravity )
112+ constrained_accel = min (max (0.0 , - cp .acceleration [1 ]), standard_gravity )
112113 return constrained_accel / standard_gravity
113114
114115 def process_button_presses (self ):
@@ -120,12 +121,12 @@ def process_button_presses(self):
120121
121122 def change_tone_if_needed (self ):
122123 """Find the frequency for the current arpeggio and tilt, and restart the tone if changed"""
123- arpeggio_index = 0 if cpx .switch else 1
124+ arpeggio_index = 0 if cp .switch else 1
124125 freq = self .freq_maker .freq (TiltingArpeggios .tilt (), arpeggio_index )
125126 if freq != self .last_freq :
126127 self .last_freq = freq
127- cpx .stop_tone ()
128- cpx .start_tone (freq )
128+ cp .stop_tone ()
129+ cp .start_tone (freq )
129130
130131
131132TiltingArpeggios ().run ()
0 commit comments