|
52 | 52 | # The following line sets up a NeoPixel strip on Crickit CPX pin A1 |
53 | 53 | pixels = neopixel.NeoPixel(board.A1, num_pixels, brightness=0.3, auto_write=False) |
54 | 54 |
|
55 | | -# NeoPixel function |
| 55 | +#sleep var for pushing both buttons |
| 56 | +SLEEP_DELAY = 0.1 |
56 | 57 |
|
| 58 | +# NeoPixel function |
57 | 59 | def color_chase(color, wait): |
58 | 60 | for i in range(num_pixels): |
59 | 61 | pixels[i] = color |
60 | 62 | time.sleep(wait) |
61 | 63 | pixels.show() |
62 | 64 | time.sleep(0.5) |
63 | 65 |
|
64 | | -# For signal control, we'll chat directly with seesaw, use 'ss' to shorted typing! |
65 | | -ss = crickit.seesaw |
66 | 66 | # potentiometer connected to signal #3 |
67 | 67 | pot = crickit.SIGNAL8 |
68 | 68 |
|
69 | 69 | # initialize the light sensor on the CPX and the DC motor |
70 | | -analogin = AnalogIn(board.LIGHT) |
71 | | - |
72 | | -# initialize motor |
73 | | -motor_1 = crickit.dc_motor_1 |
| 70 | +light_in = AnalogIn(board.LIGHT) |
74 | 71 |
|
75 | 72 | while True: |
76 | 73 |
|
@@ -118,19 +115,19 @@ def color_chase(color, wait): |
118 | 115 | # Light sensor + DC motor |
119 | 116 |
|
120 | 117 | # uncomment to see values of light |
121 | | - # print(analogin.value) |
| 118 | + # print(light_in.value) |
122 | 119 | # time.sleep(0.5) |
123 | 120 |
|
124 | 121 | # reads the on-board light sensor and graphs the brighness with NeoPixels |
125 | 122 | # light value remaped to motor speed |
126 | | - peak = map_range(analogin.value, 3000, 62000, 0, 1) |
| 123 | + peak = map_range(light_in.value, 3000, 62000, 0, 1) |
127 | 124 |
|
128 | 125 | # DC motor |
129 | | - motor_1.throttle = peak # full speed forward |
| 126 | + crickit.dc_motor_1.throttle = peak # full speed forward |
130 | 127 |
|
131 | 128 | # hit both buttons to trigger noise |
132 | 129 | if not ss.digital_read(BUTTON_1) and not ss.digital_read(BUTTON_2): |
133 | 130 | print("Buttons 1 and 2 pressed") |
134 | 131 | for f in (262, 294, 330, 349, 392, 440, 494, 523): |
135 | 132 | tone(board.A0, f, 0.25) |
136 | | - time.sleep(0.1) |
| 133 | + time.sleep(SLEEP_DELAY) |
0 commit comments