adafruit_circuitplayground.circuit_playground_base
¶
CircuitPython base class for Circuit Playground.
- Circuit Playground Express
- Circuit Playground Bluefruit.
- Author(s): Kattni Rembor, Scott Shawcroft
-
class
adafruit_circuitplayground.circuit_playground_base.
CircuitPlaygroundBase
[source]¶ Circuit Playground base class.
-
acceleration
¶ Obtain data from the x, y and z axes.
This example prints the values. Try moving the board to see how the printed values change.
To use with the Circuit Playground Express or Bluefruit:
from adafruit_circuitplayground import cp while True: x, y, z = cp.acceleration print(x, y, z)
-
adjust_touch_threshold
(adjustment)[source]¶ Adjust the threshold needed to activate the capacitive touch pads. Higher numbers make the touch pads less sensitive.
Parameters: adjustment (int) – The desired threshold increase To use with the Circuit Playground Express or Bluefruit:
from adafruit_circuitplayground import cp cp.adjust_touch_threshold(200) while True: if cp.touch_A1: print('Touched pad A1')
True
when Button A is pressed.False
if not.To use with the Circuit Playground Express or Bluefruit:
from adafruit_circuitplayground import cp while True: if cp.button_a: print("Button A pressed!")
True
when Button B is pressed.False
if not.To use with the Circuit Playground Express or Bluefruit:
from adafruit_circuitplayground import cp while True: if cp.button_b: print("Button B pressed!")
-
configure_tap
(tap, accel_range=<sphinx.ext.autodoc.importer._MockObject object>, threshold=None, time_limit=None, time_latency=50, time_window=255)[source]¶ Granular configuration of tap parameters. Expose the power of the adafruit_lis3dh module.
Parameters: - tap (int) – 0 to disable tap detection, 1 to detect only single taps, and 2 to detect only double taps.
- accel_range (int) – Takes the defined values from the adafruit_lis3dh module [ RANGE_2_G, RANGE_4_G, RANGE_8_G, RANGE_16_G ] (default sets the same value as the detect_taps setter)
- threshold (int) – A threshold for the tap detection. The higher the value the less sensitive the detection. This changes based on the accelerometer range. Good values are 5-10 for 16G, 10-20 for 8G, 20-40 for 4G, and 40-80 for 2G. (default sets the same value as the detect_taps setter)
- time_limit (int) – TIME_LIMIT register value (default sets the same value as the detect_taps setter)
- time_latency (int) – TIME_LATENCY register value (default 50).
- time_window (int) – TIME_WINDOW register value (default 255).
To use with the Circuit Playground Express or Bluefruit:
from adafruit_circuitplayground import cp import adafruit_lis3dh cp.configure_tap(1, accel_range=adafruit_lis3dh.RANGE_2_G, threshold=50) while True: if cp.tapped: print("Single tap detected!")
-
detect_taps
¶ Configure what type of tap is detected by
cp.tapped
. Use1
for single-tap detection and2
for double-tap detection. This does nothing withoutcp.tapped
.To use with the Circuit Playground Express or Bluefruit:
from adafruit_circuitplayground import cp cp.detect_taps = 1 while True: if cp.tapped: print("Single tap detected!")
-
light
¶ The light level.
Try covering the sensor next to the eye to see it change.
To use with the Circuit Playground Express or Bluefruit:
from adafruit_circuitplayground import cp import time while True: print("Light:", cp.light) time.sleep(1)
-
pixels
¶ Sequence-like object representing the ten NeoPixels around the outside of the Circuit Playground. Each pixel is at a certain index in the sequence as labeled below. Colors can be RGB hex like 0x110000 for red where each two digits are a color (0xRRGGBB) or a tuple like (17, 0, 0) where (R, G, B). Set the global brightness using any number from 0 to 1 to represent a percentage, i.e. 0.3 sets global brightness to 30%.
See
neopixel.NeoPixel
for more info.Here is an example that sets the first pixel green and the ninth red.
To use with the Circuit Playground Express or Bluefruit:
from adafruit_circuitplayground import cp cp.pixels.brightness = 0.3 cp.pixels[0] = 0x00FF00 cp.pixels[9] = (255, 0, 0)
-
play_file
(file_name)[source]¶ Play a .wav file using the onboard speaker.
Parameters: file_name – The name of your .wav file in quotation marks including .wav To use with the Circuit Playground Express or Bluefruit:
from adafruit_circuitplayground import cp while True: if cp.button_a: cp.play_file("laugh.wav") elif cp.button_b: cp.play_file("rimshot.wav")
-
play_tone
(frequency, duration)[source]¶ Produce a tone using the speaker. Try changing frequency to change the pitch of the tone.
Parameters: To use with the Circuit Playground Express or Bluefruit:
from adafruit_circuitplayground import cp cp.play_tone(440, 1)
-
red_led
¶ The red led next to the USB plug marked D13.
To use with the Circuit Playground Express or Bluefruit:
from adafruit_circuitplayground import cp import time while True: cp.red_led = True time.sleep(0.5) cp.red_led = False time.sleep(0.5)
-
shake
(shake_threshold=30)[source]¶ Detect when device is shaken.
Parameters: shake_threshold (int) – The threshold shake must exceed to return true (Default: 30) To use with the Circuit Playground Express or Bluefruit:
from adafruit_circuitplayground import cp while True: if cp.shake(): print("Shake detected!")
Decreasing
shake_threshold
increases shake sensitivity, i.e. the code will return a shake detected more easily with a lowershake_threshold
. Increasing it causes the opposite.shake_threshold
requires a minimum value of 10 - 10 is the value when the board is not moving, therefore anything less than 10 will erroneously report a constant shake detected.from adafruit_circuitplayground import cp while True: if cp.shake(shake_threshold=20): print("Shake detected more easily than before!")
-
start_tone
(frequency)[source]¶ Produce a tone using the speaker. Try changing frequency to change the pitch of the tone.
Parameters: frequency (int) – The frequency of the tone in Hz To use with the Circuit Playground Express or Bluefruit:
from adafruit_circuitplayground import cp while True: if cp.button_a: cp.start_tone(262) elif cp.button_b: cp.start_tone(294) else: cp.stop_tone()
-
stop_tone
()[source]¶ Use with start_tone to stop the tone produced.
To use with the Circuit Playground Express or Bluefruit:
from adafruit_circuitplayground import cp while True: if cp.button_a: cp.start_tone(262) elif cp.button_b: cp.start_tone(294) else: cp.stop_tone()
-
switch
¶ True
when the switch is to the left next to the music notes.False
when it is to the right towards the ear.To use with the Circuit Playground Express or Bluefruit:
from adafruit_circuitplayground import cp import time while True: print("Slide switch:", cp.switch) time.sleep(0.1)
-
tapped
¶ True once after a detecting a tap. Requires
cp.detect_taps
.Tap the Circuit Playground once for a single-tap, or quickly tap twice for a double-tap.
To use with Circuit Playground Express or Bluefruit:
from adafruit_circuitplayground import cp cp.detect_taps = 1 while True: if cp.tapped: print("Single tap detected!")
To use single and double tap together, you must have a delay between them. It will not function properly without it. This example uses both by counting a specified number of each type of tap before moving on in the code.
from adafruit_circuitplayground import cp # Set to check for single-taps. cp.detect_taps = 1 tap_count = 0 # We're looking for 2 single-taps before moving on. while tap_count < 2: if cp.tapped: tap_count += 1 print("Reached 2 single-taps!") # Now switch to checking for double-taps tap_count = 0 cp.detect_taps = 2 # We're looking for 2 double-taps before moving on. while tap_count < 2: if cp.tapped: tap_count += 1 print("Reached 2 double-taps!") print("Done.")
-
temperature
¶ The temperature in Celsius.
Converting this to Fahrenheit is easy!
To use with the Circuit Playground Express or Bluefruit:
from adafruit_circuitplayground import cp import time while True: temperature_c = cp.temperature temperature_f = temperature_c * 1.8 + 32 print("Temperature celsius:", temperature_c) print("Temperature fahrenheit:", temperature_f) time.sleep(1)
-
touch_A1
¶ Detect touch on capacitive touch pad A1.
To use with the Circuit Playground Express or Bluefruit:
from adafruit_circuitplayground import cp while True: if cp.touch_A1: print('Touched pad A1')
-
touch_A2
¶ Detect touch on capacitive touch pad A2.
To use with the Circuit Playground Express or Bluefruit:
from adafruit_circuitplayground import cp while True: if cp.touch_A2: print('Touched pad A2')
-
touch_A3
¶ Detect touch on capacitive touch pad A3.
To use with the Circuit Playground Express or Bluefruit:
from adafruit_circuitplayground import cp while True: if cp.touch_A3: print('Touched pad A3')
-
touch_A4
¶ Detect touch on capacitive touch pad A4.
To use with the Circuit Playground Express or Bluefruit:
from adafruit_circuitplayground import cp while True: if cp.touch_A4: print('Touched pad A4')
-
touch_A5
¶ Detect touch on capacitive touch pad A5.
To use with the Circuit Playground Express or Bluefruit:
from adafruit_circuitplayground import cp while True: if cp.touch_A5: print('Touched pad A5')
-
touch_A6
¶ Detect touch on capacitive touch pad A6.
To use with the Circuit Playground Express or Bluefruit:
from adafruit_circuitplayground import cp while True: if cp.touch_A6: print('Touched pad A6'
-
touch_TX
¶ Detect touch on capacitive touch pad TX (also known as A7 on the Circuit Playground Express) Note: can be called as
touch_A7
on Circuit Playground Express.To use with the Circuit Playground Express or Bluefruit:
from adafruit_circuitplayground import cp while True: if cp.touch_A7: print('Touched pad A7')
-
adafruit_circuitplayground.bluefruit
¶
CircuitPython helper for Circuit Playground Bluefruit.
- Author(s): Kattni Rembor
Implementation Notes¶
Hardware:
-
class
adafruit_circuitplayground.bluefruit.
Bluefruit
[source]¶ Represents a single CircuitPlayground Bluefruit.
-
loud_sound
(sound_threshold=200)[source]¶ Utilise a loud sound as an input.
Parameters: sound_threshold (int) – Threshold sound level must exceed to return true (Default: 200) This example turns the LEDs red each time you make a loud sound. Try clapping or blowing onto the microphone to trigger it.
from adafruit_circuitplayground.bluefruit import cpb while True: if cpb.loud_sound(): cpb.pixels.fill((50, 0, 0)) else: cpb.pixels.fill(0)
You may find that the code is not responding how you would like. If this is the case, you can change the loud sound threshold to make it more or less responsive. Setting it to a higher number means it will take a louder sound to trigger. Setting it to a lower number will take a quieter sound to trigger. The following example shows the threshold being set to a higher number than the default.
from adafruit_circuitplayground.bluefruit import cpb while True: if cpb.loud_sound(sound_threshold=300): cpb.pixels.fill((50, 0, 0)) else: cpb.pixels.fill(0)
-
play_mp3
(file_name)[source]¶ Play a .mp3 file using the onboard speaker.
Parameters: file_name – The name of your .mp3 file in quotation marks including .mp3 To use with the Circuit Playground Bluefruit:
from adafruit_circuitplayground import cp while True: if cp.button_a: cp.play_mp3("laugh.mp3") elif cp.button_b: cp.play_mp3("rimshot.mp3")
-
sound_level
¶ Obtain the sound level from the microphone (sound sensor).
This example prints the sound levels. Try clapping or blowing on the microphone to see the levels change.
from adafruit_circuitplayground.bluefruit import cpb while True: print(cpb.sound_level)
-
-
adafruit_circuitplayground.bluefruit.
cpb
= <adafruit_circuitplayground.bluefruit.Bluefruit object>¶ Object that is automatically created on import.
To use, simply import it from the module:
from adafruit_circuitplayground.bluefruit import cpb
adafruit_circuitplayground.express
¶
CircuitPython helper for Circuit Playground Express.
Hardware:
- Circuit Playground Express
- Author(s): Kattni Rembor, Scott Shawcroft
-
class
adafruit_circuitplayground.express.
Express
[source]¶ Represents a single CircuitPlayground Express. Do not use more than one at a time.
-
loud_sound
¶ This feature is not supported on Circuit Playground Express.
-
play_mp3
¶ This feature is not supported on Circuit Playground Express.
-
sound_level
¶ This feature is not supported on Circuit Playground Express.
-
touch_A7
¶ Detect touch on capacitive touch pad TX (also known as A7 on the Circuit Playground Express) Note: can be called as
touch_A7
on Circuit Playground Express.To use with the Circuit Playground Express or Bluefruit:
from adafruit_circuitplayground import cp while True: if cp.touch_A7: print('Touched pad A7')
-
-
adafruit_circuitplayground.express.
cpx
= <adafruit_circuitplayground.express.Express object>¶ Object that is automatically created on import.
To use, simply import it from the module:
from adafruit_circuitplayground.express import cpx