Adafruit Library
Adafruit_Circuit_Playground.h
Go to the documentation of this file.
1 
18 #ifndef _ADAFRUIT_CIRCUITPLAYGROUND_H_
19 #define _ADAFRUIT_CIRCUITPLAYGROUND_H_
20 
22 #include "utility/Adafruit_CPlay_Mic.h"
23 #include "utility/Adafruit_CPlay_NeoPixel.h"
24 #include "utility/Adafruit_CPlay_Speaker.h"
25 #include "utility/CP_Firmata.h"
26 #include <Arduino.h>
27 
28 #if defined(__AVR__) || \
29  defined(ARDUINO_NRF52840_CIRCUITPLAY) // Circuit Playground 'classic'
30 #include "utility/CPlay_CapacitiveSensor.h"
31 #else
32 #include "utility/Adafruit_CPlay_FreeTouch.h"
33 #include "utility/IRLibCPE.h"
34 #endif
35 
36 #ifndef NOT_AN_INTERRUPT // Not defined in Arduino 1.0.5
37 #define NOT_AN_INTERRUPT -1
38 #endif
39 
40 #ifdef __AVR__ // Circuit Playground 'classic'
41 #define CPLAY_CAPSENSE_SHARED 30
42 #define CPLAY_REDLED 13
43 #define CPLAY_NEOPIXELPIN 17
44 #define CPLAY_SLIDESWITCHPIN 21
45 #define CPLAY_LEFTBUTTON 4
46 #define CPLAY_RIGHTBUTTON 19
47 #define CPLAY_LIGHTSENSOR A5
48 #define CPLAY_THERMISTORPIN A0
49 #define CPLAY_SOUNDSENSOR A4
50 #define CPLAY_BUZZER 5
51 #define CPLAY_LIS3DH_CS 8
52 #define CPLAY_LIS3DH_INTERRUPT 7
53 #define CPLAY_LIS3DH_ADDRESS 0x18
54 #elif defined(ARDUINO_NRF52840_CIRCUITPLAY)
55 #include <math.h>
56 #define CPLAY_CAPSENSE_SHARED \
57  255
58 #define CPLAY_LEFTBUTTON 4
59 #define CPLAY_RIGHTBUTTON 5
60 #define CPLAY_SLIDESWITCHPIN 7
61 #define CPLAY_NEOPIXELPIN 8
62 #define CPLAY_REDLED 13
63 #define CPLAY_BUZZER A0
64 #define CPLAY_LIGHTSENSOR A8
65 #define CPLAY_THERMISTORPIN A9
66 #define CPLAY_LIS3DH_CS -1
67 #define CPLAY_LIS3DH_INTERRUPT 27
68 #define CPLAY_LIS3DH_ADDRESS 0x19
69 #else // Circuit Playground Express
70 #define CPLAY_LEFTBUTTON 4
71 #define CPLAY_RIGHTBUTTON 5
72 #define CPLAY_SLIDESWITCHPIN 7
73 #define CPLAY_NEOPIXELPIN 8
74 #define CPLAY_REDLED 13
75 #define CPLAY_IR_EMITTER 25
76 #define CPLAY_IR_RECEIVER 26
77 #define CPLAY_BUZZER A0
78 #define CPLAY_LIGHTSENSOR A8
79 #define CPLAY_THERMISTORPIN A9
80 #define CPLAY_SOUNDSENSOR A4
81 #define CPLAY_LIS3DH_CS -1
82 #define CPLAY_LIS3DH_INTERRUPT 27
83 #define CPLAY_LIS3DH_ADDRESS 0x19
84 #endif
85 
86 #define SERIESRESISTOR 10000
87 #define THERMISTORNOMINAL 10000
88 #define TEMPERATURENOMINAL \
89  25
90 
91 #define BCOEFFICIENT \
92  3380
93 
94 
100 #define LIGHT_SETTLE_MS 100
101 
102 /**************************************************************************/
107 /**************************************************************************/
109 public:
110  bool begin(uint8_t brightness = 20);
111 
116 
117 #if defined(__AVR__) || \
118  defined(ARDUINO_NRF52840_CIRCUITPLAY) // Circuit Playground 'classic' or
119  // bluefruit
121 #else
122  Adafruit_CPlay_FreeTouch cap[7];
123  IRrecvPCI irReceiver;
124  IRdecode irDecoder;
125  IRsend irSend;
126 #endif
127 
128  bool slideSwitch(void);
129  void redLED(bool v);
130  void playTone(uint16_t freq, uint16_t time, bool wait = true);
131  bool leftButton(void);
132  bool rightButton(void);
133  uint16_t lightSensor(void);
134  int16_t soundSensor(void);
135  float temperature(void);
136  float temperatureF(void);
137 
138  uint16_t readCap(uint8_t p, uint8_t samples = 10);
139 
140  // Accelerometer
141  float motionX(void);
142  float motionY(void);
143  float motionZ(void);
144 
145  /**************************************************************************/
153  /**************************************************************************/
154  void setAccelRange(lis3dh_range_t range) { lis.setRange(range); }
155  /**************************************************************************/
164  /**************************************************************************/
165  void setAccelTap(uint8_t c, uint8_t clickthresh) {
166  lis.setClick(c, clickthresh, 10, 20, 255);
167  }
168 
169  /**************************************************************************/
175  /**************************************************************************/
176  uint8_t getAccelTap(void) { return (lis.getClick() >> 8) & 0x3; }
177 
178  /**************************************************************************/
182  /**************************************************************************/
183  void clearPixels(void) {
184  strip.clear();
185  strip.show();
186  }
187 
188  /**************************************************************************/
196  /**************************************************************************/
197  void setPixelColor(uint8_t p, uint32_t c) {
198  strip.setPixelColor(p, c);
199  strip.show();
200  }
201 
202  /**************************************************************************/
215  /**************************************************************************/
216  void setPixelColor(uint8_t p, uint8_t r, uint8_t g, uint8_t b) {
217  strip.setPixelColor(p, r, g, b);
218  strip.show();
219  }
220 
224  void setBrightness(uint16_t b) { strip.setBrightness(b); }
225 
229  uint8_t sine8(uint8_t x) { return strip.sine8(x); }
230 
234  uint8_t gamma8(uint8_t x) { return strip.gamma8(x); }
235 
236  uint32_t colorWheel(uint8_t x);
237 
238  // Basic RGB color sensing with the light sensor and nearby neopixel.
239  // Both functions do the same thing and just differ in how they return the
240  // result, either as explicit RGB bytes or a 24-bit RGB color value.
241  void senseColor(uint8_t &red, uint8_t &green, uint8_t &blue);
242 
243  /**************************************************************************/
249  /**************************************************************************/
250  uint32_t senseColor() {
251  // Use the individual color component color sense function and then
252  // recombine tbe components into a 24-bit color value.
253  uint8_t red, green, blue;
254  senseColor(red, green, blue);
255  return ((uint32_t)red << 16) | ((uint32_t)green << 8) | blue;
256  }
257 
258  bool isExpress(void);
259 
260 private:
261 };
262 
265 
266 #endif
void setPixelColor(uint8_t p, uint8_t r, uint8_t g, uint8_t b)
set the color of a neopixel on the board
Definition: Adafruit_Circuit_Playground.h:216
uint8_t gamma8(uint8_t x)
Get a gamma-corrected value from a gamma table.
Definition: Adafruit_Circuit_Playground.h:234
void setPixelColor(uint8_t p, uint32_t c)
set the color of a neopixel on the board
Definition: Adafruit_Circuit_Playground.h:197
void setBrightness(uint8_t)
Adjust output brightness. Does not immediately affect what&#39;s currently displayed on the LEDs...
Definition: Adafruit_CPlay_NeoPixel.cpp:2509
void clearPixels(void)
turn off all neopixels on the board
Definition: Adafruit_Circuit_Playground.h:183
Class that stores state and functions for interacting with Adafruit_LIS3DH.
Definition: Adafruit_CPlay_LIS3DH.h:344
uint8_t sine8(uint8_t x)
Get a sinusoidal value from a sine table.
Definition: Adafruit_Circuit_Playground.h:229
uint32_t colorWheel(uint8_t x)
get a color value from the color wheel.
Definition: Adafruit_CircuitPlayground.cpp:380
IRrecvPCI irReceiver
the IR receiver object
Definition: Adafruit_Circuit_Playground.h:123
float temperature(void)
read the onboard thermistor.
Definition: Adafruit_CircuitPlayground.cpp:338
bool isExpress(void)
check whether or not this device is a CircuitPlayground Express.
Definition: Adafruit_CircuitPlayground.cpp:442
Class that stores state and functions for the microphone on CircuitPlayground boards.
Definition: Adafruit_CPlay_Mic.h:26
Adafruit_CPlay_LIS3DH lis
the accelerometer object
Definition: Adafruit_Circuit_Playground.h:113
IRdecode irDecoder
the IR decoder object
Definition: Adafruit_Circuit_Playground.h:124
float motionX(void)
read the X parameter of the onboard accelerometer. Value returned is defined by setAccelRange().
Definition: Adafruit_CircuitPlayground.cpp:300
uint8_t getClick(void)
Get uint8_t for single or double click.
Definition: Adafruit_CPlay_LIS3DH.cpp:312
void setBrightness(uint16_t b)
set the global brightness of all neopixels.
Definition: Adafruit_Circuit_Playground.h:224
void setAccelRange(lis3dh_range_t range)
set the range of the MEMS accelerometer.
Definition: Adafruit_Circuit_Playground.h:154
void setRange(lis3dh_range_t range)
Sets the g range for the accelerometer.
Definition: Adafruit_CPlay_LIS3DH.cpp:321
uint16_t readCap(uint8_t p, uint8_t samples=10)
read capacitive touch sensor
Definition: Adafruit_CircuitPlayground.cpp:112
static uint8_t gamma8(uint8_t x)
An 8-bit gamma-correction function for basic pixel brightness adjustment. Makes color transitions app...
Definition: Adafruit_CPlay_NeoPixel.h:289
void setAccelTap(uint8_t c, uint8_t clickthresh)
turn on tap detection. Tap detection can detect single taps or &#39;double taps&#39; (like a double-click)...
Definition: Adafruit_Circuit_Playground.h:165
bool rightButton(void)
read the right button
Definition: Adafruit_CircuitPlayground.cpp:199
Adafruit_CPlay_FreeTouch cap[7]
the array of capacitive touch sensors
Definition: Adafruit_Circuit_Playground.h:122
uint8_t getAccelTap(void)
test whether or not a tap has been detected
Definition: Adafruit_Circuit_Playground.h:176
Class that stores state and functions for interacting with CircuitPlayground hardware.
Definition: Adafruit_Circuit_Playground.h:108
Class that stores state and functions for the capacitive sensor on CircuitPlayground boards...
Definition: CPlay_CapacitiveSensor.h:34
void setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b)
Set a pixel&#39;s color using separate red, green and blue components. If using RGBW pixels, white will be set to 0.
Definition: Adafruit_CPlay_NeoPixel.cpp:2226
void clear(void)
Fill the whole NeoPixel strip with 0 / black / off.
Definition: Adafruit_CPlay_NeoPixel.cpp:2554
Adafruit_CircuitPlayground CircuitPlayground
instantiated by default
Definition: Adafruit_CircuitPlayground.cpp:451
float motionZ(void)
read the Z parameter of the onboard accelerometer. Value returned is defined by setAccelRange().
Definition: Adafruit_CircuitPlayground.cpp:326
void show(void)
Transmit pixel data in RAM to NeoPixels.
Definition: Adafruit_CPlay_NeoPixel.cpp:184
float temperatureF(void)
read the onboard thermistor.
Definition: Adafruit_CircuitPlayground.cpp:368
Adafruit_CPlay_Speaker speaker
the speaker object
Definition: Adafruit_Circuit_Playground.h:115
int16_t soundSensor(void)
read the onboard sound sensor. A reading of ~0 is silent, and loud audio will result in a reading bet...
Definition: Adafruit_CircuitPlayground.cpp:287
Adafruit_CPlay_Mic mic
the microphone object
Definition: Adafruit_Circuit_Playground.h:114
void redLED(bool v)
turn on or off the red LED on pin #13
Definition: Adafruit_CircuitPlayground.cpp:169
static uint8_t sine8(uint8_t x)
An 8-bit integer sine wave function, not directly compatible with standard trigonometric units like r...
Definition: Adafruit_CPlay_NeoPixel.h:275
uint32_t senseColor()
detect a color using the onboard light sensor
Definition: Adafruit_Circuit_Playground.h:250
Class that stores state and functions for the speaker on CircuitPlayground boards.
Definition: Adafruit_CPlay_Speaker.h:18
bool slideSwitch(void)
read the slide switch
Definition: Adafruit_CircuitPlayground.cpp:179
void setClick(uint8_t c, uint8_t clickthresh, uint8_t timelimit=10, uint8_t timelatency=20, uint8_t timewindow=255)
Set INT to output for single or double click.
Definition: Adafruit_CPlay_LIS3DH.cpp:281
Adafruit_CPlay_NeoPixel strip
the neopixel strip object
Definition: Adafruit_Circuit_Playground.h:112
void playTone(uint16_t freq, uint16_t time, bool wait=true)
play a tone on the onboard buzzer
Definition: Adafruit_CircuitPlayground.cpp:215
IRsend irSend
the IR send object
Definition: Adafruit_Circuit_Playground.h:125
float motionY(void)
read the Y parameter of the onboard accelerometer. Value returned is defined by setAccelRange().
Definition: Adafruit_CircuitPlayground.cpp:313
lis3dh_range_t
Definition: Adafruit_CPlay_LIS3DH.h:311
Class that stores state and functions for interacting with Adafruit NeoPixels and compatible devices...
Definition: Adafruit_CPlay_NeoPixel.h:200
bool leftButton(void)
read the left button
Definition: Adafruit_CircuitPlayground.cpp:189
uint16_t lightSensor(void)
read the onboard lightsensor
Definition: Adafruit_CircuitPlayground.cpp:276
bool begin(uint8_t brightness=20)
Set up the CircuitPlayground hardware.
Definition: Adafruit_CircuitPlayground.cpp:39