Ensure your device works with this simple test.
examples/circuitplayground_acceleration.py1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2# SPDX-License-Identifier: MIT 3 4""" 5This example uses the accelerometer on the Circuit Playground. It prints the values. Try moving 6the board to see the values change. If you're using Mu, open the plotter to see the values plotted. 7""" 8 9import time 10 11from adafruit_circuitplayground import cp 12 13while True: 14 x, y, z = cp.acceleration 15 print((x, y, z)) 16 17 time.sleep(0.1)examples/circuitplayground_pixels_simpletest.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2# SPDX-License-Identifier: MIT 3 4"""This example lights up the NeoPixels with a rainbow swirl.""" 5 6import time 7 8from rainbowio import colorwheel 9 10from adafruit_circuitplayground import cp 11 12 13def rainbow_cycle(wait): 14 for j in range(255): 15 for i in range(cp.pixels.n): 16 idx = int((i * 256 / len(cp.pixels)) + j) 17 cp.pixels[i] = colorwheel(idx & 255) 18 cp.pixels.show() 19 time.sleep(wait) 20 21 22cp.pixels.auto_write = False 23cp.pixels.brightness = 0.3 24while True: 25 rainbow_cycle(0.001) # rainbowcycle with 1ms delay per stepexamples/circuitplayground_shake.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2# SPDX-License-Identifier: MIT 3 4"""This example prints to the serial console when the Circuit Playground is shaken.""" 5 6from adafruit_circuitplayground import cp 7 8while True: 9 if cp.shake(): 10 print("Shake detected!")examples/circuitplayground_tapdetect_single_double.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2# SPDX-License-Identifier: MIT 3 4"""This example shows how you can use single-tap and double-tap together with a delay between. 5Single-tap the board twice and then double-tap the board twice to complete the program.""" 6 7from adafruit_circuitplayground import cp 8 9# Set to check for single-taps. 10cp.detect_taps = 1 11tap_count = 0 12 13# We're looking for 2 single-taps before moving on. 14while tap_count < 2: 15 if cp.tapped: 16 tap_count += 1 17print("Reached 2 single-taps!") 18 19# Now switch to checking for double-taps 20tap_count = 0 21cp.detect_taps = 2 22 23# We're looking for 2 double-taps before moving on. 24while tap_count < 2: 25 if cp.tapped: 26 tap_count += 1 27print("Reached 2 double-taps!") 28print("Done.") 29while True: 30 cp.red_led = Trueexamples/circuitplayground_tapdetect.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2# SPDX-License-Identifier: MIT 3 4"""This example prints to the serial console when the board is double-tapped.""" 5 6import time 7 8from adafruit_circuitplayground import cp 9 10# Change to 1 for single-tap detection. 11cp.detect_taps = 2 12 13while True: 14 if cp.tapped: 15 print("Tapped!") 16 time.sleep(0.05)examples/circuitplayground_tone.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2# SPDX-License-Identifier: MIT 3 4"""This example plays a different tone for each button, while the button is pressed.""" 5 6from adafruit_circuitplayground import cp 7 8while True: 9 if cp.button_a: 10 cp.start_tone(262) 11 elif cp.button_b: 12 cp.start_tone(294) 13 else: 14 cp.stop_tone()examples/circuitplayground_touched.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2# SPDX-License-Identifier: MIT 3 4"""This example prints to the serial console when you touch the capacitive touch pads.""" 5 6import time 7 8import board 9 10from adafruit_circuitplayground import cp 11 12# You'll need to first use the touchpads individually to register them as active touchpads 13# You don't have to use the result though 14is_a1_touched = cp.touch_A1 # This result can be used if you want 15if is_a1_touched: 16 print("A1 was touched upon startup!") 17is_a2_touched = cp.touch_A2 18is_a3_touched = cp.touch_A3 19is_a4_touched = cp.touch_A4 20 21print("Pads that are currently setup as touchpads:") 22print(cp.touch_pins) 23 24while True: 25 current_touched = cp.touched 26 27 if current_touched: 28 print("Touchpads currently registering a touch:") 29 print(current_touched) 30 else: 31 print("No touchpads are currently registering a touch.") 32 33 if all(pad in current_touched for pad in (board.A2, board.A3, board.A4)): 34 print("This only prints when A2, A3, and A4 are being held at the same time!") 35 36 time.sleep(0.25)examples/circuitplayground_acceleration_neopixels.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2# SPDX-License-Identifier: MIT 3 4"""If the switch is to the right, it will appear that nothing is happening. Move the switch to the 5left to see the NeoPixels light up in colors related to the accelerometer! The Circuit Playground 6has an accelerometer in the center that returns (x, y, z) acceleration values. This program uses 7those values to light up the NeoPixels based on those acceleration values.""" 8 9from adafruit_circuitplayground import cp 10 11# Main loop gets x, y and z axis acceleration, prints the values, and turns on 12# red, green and blue, at levels related to the x, y and z values. 13while True: 14 if not cp.switch: 15 # If the switch is to the right, it returns False! 16 print("Slide switch off!") 17 cp.pixels.fill((0, 0, 0)) 18 continue 19 R = 0 20 G = 0 21 B = 0 22 x, y, z = cp.acceleration 23 print((x, y, z)) 24 cp.pixels.fill(((R + abs(int(x))), (G + abs(int(y))), (B + abs(int(z)))))examples/circuitplayground_button_a.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2# SPDX-License-Identifier: MIT 3 4"""This example turns on the little red LED when button A is pressed.""" 5 6from adafruit_circuitplayground import cp 7 8while True: 9 if cp.button_a: 10 print("Button A pressed!") 11 cp.red_led = Trueexamples/circuitplayground_button_b.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2# SPDX-License-Identifier: MIT 3 4"""This example turns the little red LED on only while button B is currently being pressed.""" 5 6from adafruit_circuitplayground import cp 7 8while True: 9 if cp.button_b: 10 cp.red_led = True 11 else: 12 cp.red_led = False 13 14# Can also be written as: 15# cp.red_led = cp.button_bexamples/circuitplayground_buttons_1_neopixel.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2# SPDX-License-Identifier: MIT 3 4"""This example lights up the third NeoPixel while button A is being pressed, and lights up the 5eighth NeoPixel while button B is being pressed.""" 6 7from adafruit_circuitplayground import cp 8 9cp.pixels.brightness = 0.3 10cp.pixels.fill((0, 0, 0)) # Turn off the NeoPixels if they're on! 11 12while True: 13 if cp.button_a: 14 cp.pixels[2] = (0, 255, 0) 15 else: 16 cp.pixels[2] = (0, 0, 0) 17 18 if cp.button_b: 19 cp.pixels[7] = (0, 0, 255) 20 else: 21 cp.pixels[7] = (0, 0, 0)examples/circuitplayground_buttons_neopixels.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2# SPDX-License-Identifier: MIT 3 4"""This example lights up half the NeoPixels red while button A is being pressed, and half the 5NeoPixels green while button B is being pressed.""" 6 7from adafruit_circuitplayground import cp 8 9cp.pixels.brightness = 0.3 10cp.pixels.fill((0, 0, 0)) # Turn off the NeoPixels if they're on! 11 12while True: 13 if cp.button_a: 14 cp.pixels[0:5] = [(255, 0, 0)] * 5 15 else: 16 cp.pixels[0:5] = [(0, 0, 0)] * 5 17 18 if cp.button_b: 19 cp.pixels[5:10] = [(0, 255, 0)] * 5 20 else: 21 cp.pixels[5:10] = [(0, 0, 0)] * 5examples/circuitplayground_ir_receive.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2# SPDX-License-Identifier: MIT 3 4"""THIS EXAMPLE REQUIRES A SEPARATE LIBRARY BE LOADED ONTO YOUR CIRCUITPY DRIVE. 5This example requires the adafruit_irremote.mpy library. 6 7THIS EXAMPLE WORKS WITH CIRCUIT PLAYGROUND EXPRESS ONLY. 8 9This example uses the IR receiver found near the center of the board. Works with another Circuit 10Playground Express running the circuitplayground_ir_transmit.py example. The NeoPixels will light 11up when the buttons on the TRANSMITTING Circuit Playground Express are pressed!""" 12 13import adafruit_irremote 14import board 15import pulseio 16 17from adafruit_circuitplayground import cp 18 19# Create a 'pulseio' input, to listen to infrared signals on the IR receiver 20try: 21 pulsein = pulseio.PulseIn(board.IR_RX, maxlen=120, idle_state=True) 22except AttributeError as err: 23 raise NotImplementedError( 24 "This example does not work with Circuit Playground Bluefruti!" 25 ) from err 26 27# Create a decoder that will take pulses and turn them into numbers 28decoder = adafruit_irremote.GenericDecode() 29 30while True: 31 cp.red_led = True 32 pulses = decoder.read_pulses(pulsein) 33 try: 34 # Attempt to convert received pulses into numbers 35 received_code = decoder.decode_bits(pulses) 36 except adafruit_irremote.IRNECRepeatException: 37 # We got an unusual short code, probably a 'repeat' signal 38 continue 39 except adafruit_irremote.IRDecodeException: 40 # Something got distorted 41 continue 42 43 print("Infrared code received: ", received_code) 44 if received_code == [66, 84, 78, 65]: 45 print("Button A signal") 46 cp.pixels.fill((100, 0, 155)) 47 if received_code == [66, 84, 78, 64]: 48 print("Button B Signal") 49 cp.pixels.fill((210, 45, 0))examples/circuitplayground_ir_transmit.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2# SPDX-License-Identifier: MIT 3 4"""THIS EXAMPLE REQUIRES A SEPARATE LIBRARY BE LOADED ONTO YOUR CIRCUITPY DRIVE. 5This example requires the adafruit_irremote.mpy library. 6 7THIS EXAMPLE WORKS WITH CIRCUIT PLAYGROUND EXPRESS ONLY. 8 9This example uses the IR transmitter found near the center of the board. Works with another Circuit 10Playground Express running the circuitplayground_ir_receive.py example. Press the buttons to light 11up the NeoPixels on the RECEIVING Circuit Playground Express!""" 12 13import time 14 15import adafruit_irremote 16import board 17import pulseio 18 19from adafruit_circuitplayground import cp 20 21# Create a 'PulseOut' output, to send infrared signals from the IR transmitter 22try: 23 pulseout = pulseio.PulseOut(board.IR_TX, frequency=38000, duty_cycle=2**15) 24except AttributeError as err: 25 # Catch no board.IR_TX pin 26 raise NotImplementedError( 27 "This example does not work with Circuit Playground Bluefruit!" 28 ) from err 29 30# Create an encoder that will take numbers and turn them into NEC IR pulses 31encoder = adafruit_irremote.GenericTransmit( 32 header=[9500, 4500], one=[550, 550], zero=[550, 1700], trail=0 33) 34 35while True: 36 if cp.button_a: 37 print("Button A pressed! \n") 38 cp.red_led = True 39 encoder.transmit(pulseout, [66, 84, 78, 65]) 40 cp.red_led = False 41 # wait so the receiver can get the full message 42 time.sleep(0.2) 43 if cp.button_b: 44 print("Button B pressed! \n") 45 cp.red_led = True 46 encoder.transmit(pulseout, [66, 84, 78, 64]) 47 cp.red_led = False 48 time.sleep(0.2)examples/circuitplayground_light_neopixels.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2# SPDX-License-Identifier: MIT 3 4""" 5This example uses the light sensor on the Circuit Playground, located next to the picture of the 6eye on the board. Once you have the library loaded, try shining a flashlight on your Circuit 7Playground to watch the number of NeoPixels lit up increase, or try covering up the light sensor 8to watch the number decrease. 9""" 10 11import time 12 13from adafruit_circuitplayground import cp 14 15cp.pixels.auto_write = False 16cp.pixels.brightness = 0.3 17 18 19def scale_range(value): 20 """Scale a value from 0-320 (light range) to 0-9 (NeoPixel range). 21 Allows remapping light value to pixel position.""" 22 return round(value / 320 * 9) 23 24 25while True: 26 peak = scale_range(cp.light) 27 print(cp.light) 28 print(int(peak)) 29 30 for i in range(10): 31 if i <= peak: 32 cp.pixels[i] = (0, 255, 255) 33 else: 34 cp.pixels[i] = (0, 0, 0) 35 cp.pixels.show() 36 time.sleep(0.05)examples/circuitplayground_light.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2# SPDX-License-Identifier: MIT 3 4"""This example uses the light sensor on your Circuit Playground, located next to the picture of 5the eye. Try shining a flashlight on your Circuit Playground, or covering the light sensor with 6your finger to see the values increase and decrease.""" 7 8import time 9 10from adafruit_circuitplayground import cp 11 12while True: 13 print("Light:", cp.light) 14 time.sleep(0.2)examples/circuitplayground_neopixel_0_1.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2# SPDX-License-Identifier: MIT 3 4"""This example lights up the first and second NeoPixel, red and blue respectively.""" 5 6from adafruit_circuitplayground import cp 7 8cp.pixels.brightness = 0.3 9 10while True: 11 cp.pixels[0] = (255, 0, 0) 12 cp.pixels[1] = (0, 0, 255)examples/circuitplayground_light_plotter.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2# SPDX-License-Identifier: MIT 3 4"""If you're using Mu, this example will plot the light levels from the light sensor (located next 5to the eye) on your Circuit Playground. Try shining a flashlight on your Circuit Playground, or 6covering the light sensor to see the plot increase and decrease.""" 7 8import time 9 10from adafruit_circuitplayground import cp 11 12while True: 13 print("Light:", cp.light) 14 print((cp.light,)) 15 time.sleep(0.1)examples/circuitplayground_play_file_buttons.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2# SPDX-License-Identifier: MIT 3 4"""THIS EXAMPLE REQUIRES A WAV FILE FROM THE examples FOLDER IN THE 5Adafruit_CircuitPython_CircuitPlayground REPO found at: 6https://github.com/adafruit/Adafruit_CircuitPython_CircuitPlayground/tree/main/examples 7 8Copy the "dip.wav" and "rise.wav" files to your CIRCUITPY drive. 9 10Once the files are copied, this example plays a different wav file for each button pressed!""" 11 12from adafruit_circuitplayground import cp 13 14while True: 15 if cp.button_a: 16 cp.play_file("dip.wav") 17 if cp.button_b: 18 cp.play_file("rise.wav")examples/circuitplayground_play_file.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2# SPDX-License-Identifier: MIT 3 4"""THIS EXAMPLE REQUIRES A WAV FILE FROM THE examples FOLDER IN THE 5Adafruit_CircuitPython_CircuitPlayground REPO found at: 6https://github.com/adafruit/Adafruit_CircuitPython_CircuitPlayground/tree/main/examples 7 8Copy the "dip.wav" file to your CIRCUITPY drive. 9 10Once the file is copied, this example plays a wav file!""" 11 12from adafruit_circuitplayground import cp 13 14cp.play_file("dip.wav")examples/circuitplayground_play_tone_buttons.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2# SPDX-License-Identifier: MIT 3 4"""This example plays a different tone for a duration of 1 second for each button pressed.""" 5 6from adafruit_circuitplayground import cp 7 8while True: 9 if cp.button_a: 10 cp.play_tone(262, 1) 11 if cp.button_b: 12 cp.play_tone(294, 1)examples/circuitplayground_play_tone.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2# SPDX-License-Identifier: MIT 3 4"""This example plays two tones for 1 second each. Note that the tones are not in a loop - this is 5to prevent them from playing indefinitely!""" 6 7from adafruit_circuitplayground import cp 8 9cp.play_tone(262, 1) 10cp.play_tone(294, 1)examples/circuitplayground_red_led_blinky.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2# SPDX-License-Identifier: MIT 3 4"""This is the "Hello, world!" of CircuitPython: Blinky! This example blinks the little red LED on 5and off!""" 6 7import time 8 9from adafruit_circuitplayground import cp 10 11while True: 12 cp.red_led = True 13 time.sleep(0.5) 14 cp.red_led = False 15 time.sleep(0.5)examples/circuitplayground_red_led_blnky_short.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2# SPDX-License-Identifier: MIT 3 4"""This is the "Hello, world!" of CircuitPython: Blinky! This example blinks the little red LED on 5and off! It's a shorter version of the other Blinky example.""" 6 7import time 8 9from adafruit_circuitplayground import cp 10 11while True: 12 cp.red_led = not cp.red_led 13 time.sleep(0.5)examples/circuitplayground_red_led.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2# SPDX-License-Identifier: MIT 3 4"""This example turns on the little red LED.""" 5 6from adafruit_circuitplayground import cp 7 8while True: 9 cp.red_led = Trueexamples/circuitplayground_slide_switch_red_led.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2# SPDX-License-Identifier: MIT 3 4"""This example uses the slide switch to control the little red LED.""" 5 6from adafruit_circuitplayground import cp 7 8while True: 9 if cp.switch: 10 cp.red_led = True 11 else: 12 cp.red_led = Falseexamples/circuitplayground_slide_switch_red_led_short.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2# SPDX-License-Identifier: MIT 3 4"""This example uses the slide switch to control the little red LED. When the switch is to the 5right it returns False, and when it's to the left, it returns True.""" 6 7from adafruit_circuitplayground import cp 8 9while True: 10 cp.red_led = cp.switchexamples/circuitplayground_slide_switch.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2# SPDX-License-Identifier: MIT 3 4"""This example prints the status of the slide switch. Try moving the switch back and forth to see 5what's printed to the serial console!""" 6 7import time 8 9from adafruit_circuitplayground import cp 10 11while True: 12 print("Slide switch:", cp.switch) 13 time.sleep(0.1)examples/circuitplayground_sound_meter.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2# SPDX-License-Identifier: MIT 3 4"""This example uses the sound sensor, located next to the picture of the ear on your board, to 5light up the NeoPixels as a sound meter. Try talking to your Circuit Playground or clapping, etc, 6to see the NeoPixels light up!""" 7 8import array 9import math 10 11import audiobusio 12import board 13 14from adafruit_circuitplayground import cp 15 16 17def constrain(value, floor, ceiling): 18 return max(floor, min(value, ceiling)) 19 20 21def log_scale(input_value, input_min, input_max, output_min, output_max): 22 normalized_input_value = (input_value - input_min) / (input_max - input_min) 23 return output_min + math.pow(normalized_input_value, 0.630957) * (output_max - output_min) 24 25 26def normalized_rms(values): 27 minbuf = int(sum(values) / len(values)) 28 return math.sqrt( 29 sum(float(sample - minbuf) * (sample - minbuf) for sample in values) / len(values) 30 ) 31 32 33mic = audiobusio.PDMIn( 34 board.MICROPHONE_CLOCK, board.MICROPHONE_DATA, sample_rate=16000, bit_depth=16 35) 36 37samples = array.array("H", [0] * 160) 38mic.record(samples, len(samples)) 39input_floor = normalized_rms(samples) + 10 40 41# Lower number means more sensitive - more LEDs will light up with less sound. 42sensitivity = 500 43input_ceiling = input_floor + sensitivity 44 45peak = 0 46while True: 47 mic.record(samples, len(samples)) 48 magnitude = normalized_rms(samples) 49 print((magnitude,)) 50 51 c = log_scale( 52 constrain(magnitude, input_floor, input_ceiling), 53 input_floor, 54 input_ceiling, 55 0, 56 10, 57 ) 58 59 cp.pixels.fill((0, 0, 0)) 60 for i in range(10): 61 if i < c: 62 cp.pixels[i] = (i * (255 // 10), 50, 0) 63 if c >= peak: 64 peak = min(c, 10 - 1) 65 elif peak > 0: 66 peak = peak - 1 67 if peak > 0: 68 cp.pixels[int(peak)] = (80, 0, 255) 69 cp.pixels.show()examples/circuitplayground_tap_red_led.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2# SPDX-License-Identifier: MIT 3 4"""This example turns on the little red LED and prints to the serial console when you double-tap 5the Circuit Playground!""" 6 7import time 8 9from adafruit_circuitplayground import cp 10 11# Change to 1 for detecting a single-tap! 12cp.detect_taps = 2 13 14while True: 15 if cp.tapped: 16 print("Tapped!") 17 cp.red_led = True 18 time.sleep(0.1) 19 else: 20 cp.red_led = Falseexamples/circuitplayground_temperature_neopixels.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2# SPDX-License-Identifier: MIT 3 4""" 5This example use the temperature sensor on the Circuit Playground, located next to the picture of 6the thermometer on the board. Try warming up the board to watch the number of NeoPixels lit up 7increase, or cooling it down to see the number decrease. You can set the min and max temperatures 8to make it more or less sensitive to temperature changes. 9""" 10 11import time 12 13from adafruit_circuitplayground import cp 14 15cp.pixels.auto_write = False 16cp.pixels.brightness = 0.3 17 18# Set these based on your ambient temperature in Celsius for best results! 19minimum_temp = 24 20maximum_temp = 30 21 22 23def scale_range(value): 24 """Scale a value from the range of minimum_temp to maximum_temp (temperature range) to 0-10 25 (the number of NeoPixels). Allows remapping temperature value to pixel position.""" 26 return int((value - minimum_temp) / (maximum_temp - minimum_temp) * 10) 27 28 29while True: 30 peak = scale_range(cp.temperature) 31 print(cp.temperature) 32 print(int(peak)) 33 34 for i in range(10): 35 if i <= peak: 36 cp.pixels[i] = (0, 255, 255) 37 else: 38 cp.pixels[i] = (0, 0, 0) 39 cp.pixels.show() 40 time.sleep(0.05)examples/circuitplayground_temperature_plotter.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2# SPDX-License-Identifier: MIT 3 4"""If you're using Mu, this example will plot the temperature in C and F on the plotter! Click 5"Plotter" to open it, and place your finger over the sensor to see the numbers change. The 6sensor is located next to the picture of the thermometer on the CPX.""" 7 8import time 9 10from adafruit_circuitplayground import cp 11 12while True: 13 print("Temperature C:", cp.temperature) 14 print("Temperature F:", cp.temperature * 1.8 + 32) 15 print((cp.temperature, cp.temperature * 1.8 + 32)) 16 time.sleep(0.1)examples/circuitplayground_temperature.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2# SPDX-License-Identifier: MIT 3 4"""This example uses the temperature sensor on the Circuit Playground, located next to the image of 5a thermometer on the board. It prints the temperature in both C and F to the serial console. Try 6putting your finger over the sensor to see the numbers change!""" 7 8import time 9 10from adafruit_circuitplayground import cp 11 12while True: 13 print("Temperature C:", cp.temperature) 14 print("Temperature F:", cp.temperature * 1.8 + 32) 15 time.sleep(1)examples/circuitplayground_touch_pixel_fill_rainbow.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2# SPDX-License-Identifier: MIT 3 4"""This example uses the capacitive touch pads on the Circuit Playground. They are located around 5the outer edge of the board and are labeled A1-A6 and TX. (A0 is not a touch pad.) This example 6lights up all the NeoPixels a different color of the rainbow for each pad touched!""" 7 8import time 9 10from adafruit_circuitplayground import cp 11 12cp.pixels.brightness = 0.3 13 14while True: 15 if cp.touch_A1: 16 print("Touched A1!") 17 cp.pixels.fill((255, 0, 0)) 18 if cp.touch_A2: 19 print("Touched A2!") 20 cp.pixels.fill((210, 45, 0)) 21 if cp.touch_A3: 22 print("Touched A3!") 23 cp.pixels.fill((155, 100, 0)) 24 if cp.touch_A4: 25 print("Touched A4!") 26 cp.pixels.fill((0, 255, 0)) 27 if cp.touch_A5: 28 print("Touched A5!") 29 cp.pixels.fill((0, 135, 125)) 30 if cp.touch_A6: 31 print("Touched A6!") 32 cp.pixels.fill((0, 0, 255)) 33 if cp.touch_TX: 34 print("Touched TX!") 35 cp.pixels.fill((100, 0, 155)) 36 time.sleep(0.1)examples/circuitplayground_touch_pixel_rainbow.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2# SPDX-License-Identifier: MIT 3 4"""This example uses the capacitive touch pads on the Circuit Playground. They are located around 5the outer edge of the board and are labeled A1-A6 and TX. (A0 is not a touch pad.) This example 6lights up the nearest NeoPixel to that pad a different color of the rainbow!""" 7 8import time 9 10from adafruit_circuitplayground import cp 11 12cp.pixels.brightness = 0.3 13 14while True: 15 if cp.touch_A1: 16 print("Touched A1!") 17 cp.pixels[6] = (255, 0, 0) 18 if cp.touch_A2: 19 print("Touched A2!") 20 cp.pixels[8] = (210, 45, 0) 21 if cp.touch_A3: 22 print("Touched A3!") 23 cp.pixels[9] = (155, 100, 0) 24 if cp.touch_A4: 25 print("Touched A4!") 26 cp.pixels[0] = (0, 255, 0) 27 if cp.touch_A5: 28 print("Touched A5!") 29 cp.pixels[1] = (0, 135, 125) 30 if cp.touch_A6: 31 print("Touched A6!") 32 cp.pixels[3] = (0, 0, 255) 33 if cp.touch_TX: 34 print("Touched TX!") 35 cp.pixels[4] = (100, 0, 155) 36 time.sleep(0.1)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4