source: trunk/Arduino/libraries/Adafruit_Circuit_Playground/examples/mega_demo/SensorDemo.h

Last change on this file was 3, checked in by markus, 7 years ago

Setup project structure

File size: 1.7 KB
Line 
1#ifndef SENSORDEMO_H
2#define SENSORDEMO_H
3
4#include "Demo.h"
5
6// Define small, medium, large range of light sensor values.
7static int minLight[] = {  0,   0,    0};
8static int maxLight[] = { 50, 255, 1023};
9
10// Define small, medium, large range of temp sensor values (in Fahrenheit).
11static float minTempF[] = {  80.0,  70.0,  -32.0};
12static float maxTempF[] = {  85.0,  90.0, 212.0};
13
14// Define color for light sensor pixels.
15#define LIGHT_RED   0xFF
16#define LIGHT_GREEN 0x00
17#define LIGHT_BLUE  0x00
18
19// Define color for temp sensor pixels.
20#define TEMP_RED    0x00
21#define TEMP_GREEN  0x00
22#define TEMP_BLUE   0xFF
23
24class SensorDemo: public Demo {
25public:
26  SensorDemo() { mode = 0; }
27  ~SensorDemo() {}
28
29  virtual void loop() {
30    // Reset all lights to off.
31    for (int i=0; i<10; ++i) {
32      CircuitPlayground.strip.setPixelColor(i, 0);
33    }
34   
35    // Measure the light level and use it to light up its LEDs (right half).
36    uint16_t light = CircuitPlayground.lightSensor();
37    int level = (int)lerp(light, minLight[mode], maxLight[mode], 0.0, 5.0);
38    for (int i=9; i>9-level; --i) {
39      CircuitPlayground.strip.setPixelColor(i, LIGHT_RED, LIGHT_GREEN, LIGHT_BLUE);
40    }
41
42    // Measure the temperatue and use it to light up its LEDs (left half).
43    float tempF = CircuitPlayground.temperatureF();
44    level = (int)lerp(tempF, minTempF[mode], maxTempF[mode], 0.0, 5.0);
45    for (int i=0; i<level; ++i) {
46      CircuitPlayground.strip.setPixelColor(i, TEMP_RED, TEMP_GREEN, TEMP_BLUE);
47    }
48
49    // Light up the pixels!
50    CircuitPlayground.strip.show();
51  }
52
53  virtual void modePress() {
54    // Switch to one of three modes for small, medium, big ranges of measurements.
55    mode += 1;
56    if (mode > 2) {
57      mode = 0;
58    }
59  }
60
61private:
62  int mode;
63};
64
65#endif
Note: See TracBrowser for help on using the repository browser.