Simple test

Ensure your device works with this simple test.

examples/circuitplayground_acceleration.py
 1# 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"""
 8import time
 9from adafruit_circuitplayground import cp
10
11while True:
12    x, y, z = cp.acceleration
13    print((x, y, z))
14
15    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."""
 5import time
 6from rainbowio import colorwheel
 7from adafruit_circuitplayground import cp
 8
 9
10def rainbow_cycle(wait):
11    for j in range(255):
12        for i in range(cp.pixels.n):
13            idx = int((i * 256 / len(cp.pixels)) + j)
14            cp.pixels[i] = colorwheel(idx & 255)
15        cp.pixels.show()
16        time.sleep(wait)
17
18
19cp.pixels.auto_write = False
20cp.pixels.brightness = 0.3
21while True:
22    rainbow_cycle(0.001)  # rainbowcycle with 1ms delay per step
examples/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."""
5from adafruit_circuitplayground import cp
6
7while True:
8    if cp.shake():
9        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."""
 6from adafruit_circuitplayground import cp
 7
 8# Set to check for single-taps.
 9cp.detect_taps = 1
10tap_count = 0
11
12# We're looking for 2 single-taps before moving on.
13while tap_count < 2:
14    if cp.tapped:
15        tap_count += 1
16print("Reached 2 single-taps!")
17
18# Now switch to checking for double-taps
19tap_count = 0
20cp.detect_taps = 2
21
22# We're looking for 2 double-taps before moving on.
23while tap_count < 2:
24    if cp.tapped:
25        tap_count += 1
26print("Reached 2 double-taps!")
27print("Done.")
28while True:
29    cp.red_led = True
examples/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."""
 5import time
 6from adafruit_circuitplayground import cp
 7
 8# Change to 1 for single-tap detection.
 9cp.detect_taps = 2
10
11while True:
12    if cp.tapped:
13        print("Tapped!")
14    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."""
 5from adafruit_circuitplayground import cp
 6
 7while True:
 8    if cp.button_a:
 9        cp.start_tone(262)
10    elif cp.button_b:
11        cp.start_tone(294)
12    else:
13        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."""
 5import time
 6import board
 7from adafruit_circuitplayground import cp
 8
 9
10# You'll need to first use the touchpads individually to register them as active touchpads
11# You don't have to use the result though
12is_a1_touched = cp.touch_A1  # This result can be used if you want
13if is_a1_touched:
14    print("A1 was touched upon startup!")
15is_a2_touched = cp.touch_A2
16is_a3_touched = cp.touch_A3
17is_a4_touched = cp.touch_A4
18
19print("Pads that are currently setup as touchpads:")
20print(cp.touch_pins)
21
22while True:
23    current_touched = cp.touched
24
25    if current_touched:
26        print("Touchpads currently registering a touch:")
27        print(current_touched)
28    else:
29        print("No touchpads are currently registering a touch.")
30
31    if all(pad in current_touched for pad in (board.A2, board.A3, board.A4)):
32        print("This only prints when A2, A3, and A4 are being held at the same time!")
33
34    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."""
 8from adafruit_circuitplayground import cp
 9
10# Main loop gets x, y and z axis acceleration, prints the values, and turns on
11# red, green and blue, at levels related to the x, y and z values.
12while True:
13    if not cp.switch:
14        # If the switch is to the right, it returns False!
15        print("Slide switch off!")
16        cp.pixels.fill((0, 0, 0))
17        continue
18    R = 0
19    G = 0
20    B = 0
21    x, y, z = cp.acceleration
22    print((x, y, z))
23    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."""
 5from adafruit_circuitplayground import cp
 6
 7while True:
 8    if cp.button_a:
 9        print("Button A pressed!")
10        cp.red_led = True
examples/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."""
 5from adafruit_circuitplayground import cp
 6
 7# This code is written to be readable versus being Pylint compliant.
 8# pylint: disable=simplifiable-if-statement
 9
10while True:
11    if cp.button_b:
12        cp.red_led = True
13    else:
14        cp.red_led = False
15
16# Can also be written as:
17#    cp.red_led = cp.button_b
examples/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."""
 6from adafruit_circuitplayground import cp
 7
 8cp.pixels.brightness = 0.3
 9cp.pixels.fill((0, 0, 0))  # Turn off the NeoPixels if they're on!
10
11while True:
12    if cp.button_a:
13        cp.pixels[2] = (0, 255, 0)
14    else:
15        cp.pixels[2] = (0, 0, 0)
16
17    if cp.button_b:
18        cp.pixels[7] = (0, 0, 255)
19    else:
20        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."""
 6from adafruit_circuitplayground import cp
 7
 8cp.pixels.brightness = 0.3
 9cp.pixels.fill((0, 0, 0))  # Turn off the NeoPixels if they're on!
10
11while True:
12    if cp.button_a:
13        cp.pixels[0:5] = [(255, 0, 0)] * 5
14    else:
15        cp.pixels[0:5] = [(0, 0, 0)] * 5
16
17    if cp.button_b:
18        cp.pixels[5:10] = [(0, 255, 0)] * 5
19    else:
20        cp.pixels[5:10] = [(0, 0, 0)] * 5
examples/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!"""
12import pulseio
13import board
14import adafruit_irremote
15from adafruit_circuitplayground import cp
16
17# Create a 'pulseio' input, to listen to infrared signals on the IR receiver
18try:
19    pulsein = pulseio.PulseIn(board.IR_RX, maxlen=120, idle_state=True)
20except AttributeError as err:
21    raise NotImplementedError(
22        "This example does not work with Circuit Playground Bluefruti!"
23    ) from err
24
25# Create a decoder that will take pulses and turn them into numbers
26decoder = adafruit_irremote.GenericDecode()
27
28while True:
29    cp.red_led = True
30    pulses = decoder.read_pulses(pulsein)
31    try:
32        # Attempt to convert received pulses into numbers
33        received_code = decoder.decode_bits(pulses)
34    except adafruit_irremote.IRNECRepeatException:
35        # We got an unusual short code, probably a 'repeat' signal
36        continue
37    except adafruit_irremote.IRDecodeException:
38        # Something got distorted
39        continue
40
41    print("Infrared code received: ", received_code)
42    if received_code == [66, 84, 78, 65]:
43        print("Button A signal")
44        cp.pixels.fill((100, 0, 155))
45    if received_code == [66, 84, 78, 64]:
46        print("Button B Signal")
47        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!"""
12import time
13import pulseio
14import board
15import adafruit_irremote
16from adafruit_circuitplayground import cp
17
18# Create a 'PulseOut' output, to send infrared signals from the IR transmitter
19try:
20    pulseout = pulseio.PulseOut(board.IR_TX, frequency=38000, duty_cycle=2**15)
21except AttributeError as err:
22    # Catch no board.IR_TX pin
23    raise NotImplementedError(
24        "This example does not work with Circuit Playground Bluefruit!"
25    ) from err
26
27# Create an encoder that will take numbers and turn them into NEC IR pulses
28encoder = adafruit_irremote.GenericTransmit(
29    header=[9500, 4500], one=[550, 550], zero=[550, 1700], trail=0
30)
31
32while True:
33    if cp.button_a:
34        print("Button A pressed! \n")
35        cp.red_led = True
36        encoder.transmit(pulseout, [66, 84, 78, 65])
37        cp.red_led = False
38        # wait so the receiver can get the full message
39        time.sleep(0.2)
40    if cp.button_b:
41        print("Button B pressed! \n")
42        cp.red_led = True
43        encoder.transmit(pulseout, [66, 84, 78, 64])
44        cp.red_led = False
45        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
12from adafruit_circuitplayground import cp
13
14cp.pixels.auto_write = False
15cp.pixels.brightness = 0.3
16
17
18def scale_range(value):
19    """Scale a value from 0-320 (light range) to 0-9 (NeoPixel range).
20    Allows remapping light value to pixel position."""
21    return round(value / 320 * 9)
22
23
24while True:
25    peak = scale_range(cp.light)
26    print(cp.light)
27    print(int(peak))
28
29    for i in range(10):
30        if i <= peak:
31            cp.pixels[i] = (0, 255, 255)
32        else:
33            cp.pixels[i] = (0, 0, 0)
34    cp.pixels.show()
35    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."""
 7import time
 8from adafruit_circuitplayground import cp
 9
10while True:
11    print("Light:", cp.light)
12    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."""
 5from adafruit_circuitplayground import cp
 6
 7cp.pixels.brightness = 0.3
 8
 9while True:
10    cp.pixels[0] = (255, 0, 0)
11    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."""
 7import time
 8from adafruit_circuitplayground import cp
 9
10while True:
11    print("Light:", cp.light)
12    print((cp.light,))
13    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!"""
11from adafruit_circuitplayground import cp
12
13while True:
14    if cp.button_a:
15        cp.play_file("dip.wav")
16    if cp.button_b:
17        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!"""
11from adafruit_circuitplayground import cp
12
13cp.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."""
 5from adafruit_circuitplayground import cp
 6
 7while True:
 8    if cp.button_a:
 9        cp.play_tone(262, 1)
10    if cp.button_b:
11        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!"""
6from adafruit_circuitplayground import cp
7
8cp.play_tone(262, 1)
9cp.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!"""
 6import time
 7from adafruit_circuitplayground import cp
 8
 9while True:
10    cp.red_led = True
11    time.sleep(0.5)
12    cp.red_led = False
13    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."""
 6import time
 7from adafruit_circuitplayground import cp
 8
 9while True:
10    cp.red_led = not cp.red_led
11    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."""
5from adafruit_circuitplayground import cp
6
7while True:
8    cp.red_led = True
examples/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."""
 5from adafruit_circuitplayground import cp
 6
 7# This code is written to be readable versus being Pylint compliant.
 8# pylint: disable=simplifiable-if-statement
 9
10while True:
11    if cp.switch:
12        cp.red_led = True
13    else:
14        cp.red_led = False
examples/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."""
6from adafruit_circuitplayground import cp
7
8while True:
9    cp.red_led = cp.switch
examples/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!"""
 6import time
 7from adafruit_circuitplayground import cp
 8
 9while True:
10    print("Slide switch:", cp.switch)
11    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!"""
 7import array
 8import math
 9import board
10import audiobusio
11from adafruit_circuitplayground import cp
12
13
14def constrain(value, floor, ceiling):
15    return max(floor, min(value, ceiling))
16
17
18def log_scale(input_value, input_min, input_max, output_min, output_max):
19    normalized_input_value = (input_value - input_min) / (input_max - input_min)
20    return output_min + math.pow(normalized_input_value, 0.630957) * (
21        output_max - output_min
22    )
23
24
25def normalized_rms(values):
26    minbuf = int(sum(values) / len(values))
27    return math.sqrt(
28        sum(float(sample - minbuf) * (sample - minbuf) for sample in values)
29        / 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!"""
 6import time
 7from adafruit_circuitplayground import cp
 8
 9# Change to 1 for detecting a single-tap!
10cp.detect_taps = 2
11
12while True:
13    if cp.tapped:
14        print("Tapped!")
15        cp.red_led = True
16        time.sleep(0.1)
17    else:
18        cp.red_led = False
examples/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"""
10import time
11from adafruit_circuitplayground import cp
12
13cp.pixels.auto_write = False
14cp.pixels.brightness = 0.3
15
16# Set these based on your ambient temperature in Celsius for best results!
17minimum_temp = 24
18maximum_temp = 30
19
20
21def scale_range(value):
22    """Scale a value from the range of minimum_temp to maximum_temp (temperature range) to 0-10
23    (the number of NeoPixels). Allows remapping temperature value to pixel position."""
24    return int((value - minimum_temp) / (maximum_temp - minimum_temp) * 10)
25
26
27while True:
28    peak = scale_range(cp.temperature)
29    print(cp.temperature)
30    print(int(peak))
31
32    for i in range(10):
33        if i <= peak:
34            cp.pixels[i] = (0, 255, 255)
35        else:
36            cp.pixels[i] = (0, 0, 0)
37    cp.pixels.show()
38    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."""
 7import time
 8from adafruit_circuitplayground import cp
 9
10while True:
11    print("Temperature C:", cp.temperature)
12    print("Temperature F:", cp.temperature * 1.8 + 32)
13    print((cp.temperature, cp.temperature * 1.8 + 32))
14    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!"""
 7import time
 8from adafruit_circuitplayground import cp
 9
10while True:
11    print("Temperature C:", cp.temperature)
12    print("Temperature F:", cp.temperature * 1.8 + 32)
13    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!"""
 7import time
 8from adafruit_circuitplayground import cp
 9
10cp.pixels.brightness = 0.3
11
12while True:
13    if cp.touch_A1:
14        print("Touched A1!")
15        cp.pixels.fill((255, 0, 0))
16    if cp.touch_A2:
17        print("Touched A2!")
18        cp.pixels.fill((210, 45, 0))
19    if cp.touch_A3:
20        print("Touched A3!")
21        cp.pixels.fill((155, 100, 0))
22    if cp.touch_A4:
23        print("Touched A4!")
24        cp.pixels.fill((0, 255, 0))
25    if cp.touch_A5:
26        print("Touched A5!")
27        cp.pixels.fill((0, 135, 125))
28    if cp.touch_A6:
29        print("Touched A6!")
30        cp.pixels.fill((0, 0, 255))
31    if cp.touch_TX:
32        print("Touched TX!")
33        cp.pixels.fill((100, 0, 155))
34    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!"""
 7import time
 8from adafruit_circuitplayground import cp
 9
10cp.pixels.brightness = 0.3
11
12while True:
13    if cp.touch_A1:
14        print("Touched A1!")
15        cp.pixels[6] = (255, 0, 0)
16    if cp.touch_A2:
17        print("Touched A2!")
18        cp.pixels[8] = (210, 45, 0)
19    if cp.touch_A3:
20        print("Touched A3!")
21        cp.pixels[9] = (155, 100, 0)
22    if cp.touch_A4:
23        print("Touched A4!")
24        cp.pixels[0] = (0, 255, 0)
25    if cp.touch_A5:
26        print("Touched A5!")
27        cp.pixels[1] = (0, 135, 125)
28    if cp.touch_A6:
29        print("Touched A6!")
30        cp.pixels[3] = (0, 0, 255)
31    if cp.touch_TX:
32        print("Touched TX!")
33        cp.pixels[4] = (100, 0, 155)
34    time.sleep(0.1)