ampel-firmware.ino 1.88 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
/***
 *       ____ ___ ____       _                         _
 *      / ___/ _ \___ \     / \   _ __ ___  _ __   ___| |
 *     | |  | | | |__) |   / _ \ | '_ ` _ \| '_ \ / _ \ |
 *     | |__| |_| / __/   / ___ \| | | | | | |_) |  __/ |
 *      \____\___/_____| /_/__ \_\_| |_| |_| .__/ \___|_|         _
 *     | | | |/ _|_   _| / ___|| |_ _   _| |_| |_ __ _  __ _ _ __| |_
 *     | |_| | |_  | |   \___ \| __| | | | __| __/ _` |/ _` | '__| __|
 *     |  _  |  _| | |    ___) | |_| |_| | |_| || (_| | (_| | |  | |_
 *     |_| |_|_|   |_|   |____/ \__|\__,_|\__|\__\__, |\__,_|_|   \__|
 *                                               |___/
 */

14
15
16
17
18
19
// Small example, with CO2 sensor and LED ring.
// Required libraries:
//  LED Ring:
#include "src/lib/Adafruit_NeoPixel/Adafruit_NeoPixel.h"

// How many LEDs on the ring?
Eric Duminil's avatar
Eric Duminil committed
20
const int LED_COUNT = 16;
21
22
23
24
25
26
27
// Where is LED ring connected to micro-controller?
const int NEOPIXELS_PIN = 5;

// Define LED ring and CO2 sensor
Adafruit_NeoPixel led_ring(LED_COUNT, NEOPIXELS_PIN, NEO_GRB + NEO_KHZ800);

// Define variables
Eric Duminil's avatar
Eric Duminil committed
28
uint32_t n;
29

Eric Duminil's avatar
Eric Duminil committed
30
// The code in setup() will be run once, at startup.
31
void setup() {
32
33
  // Transmission speed
  Serial.begin(115200);
Eric Duminil's avatar
Eric Duminil committed
34

35
36
37
  // Initialize LED ring.
  led_ring.begin();
  led_ring.setBrightness(255);
Eric Duminil's avatar
Eric Duminil committed
38

39
40
}

Eric Duminil's avatar
Eric Duminil committed
41
// The code in loop() will be run as long as the micro-controller is powered up, in an infinite loop.
42
void loop() {
43
44
45
  // First, disable every LED
  led_ring.clear();
  // Check if air is good enough
Eric Duminil's avatar
Eric Duminil committed
46
47
  for (int i = 0; i < LED_COUNT; ++i) {
    if ((n >> i) & 1) {
Eric Duminil's avatar
Eric Duminil committed
48
49
      led_ring.setPixelColor(i, 0x00ff84); // Sophie BlueGreen
//      led_ring.setPixelColor(i, led_ring.ColorHSV(n * 1023 + 60000));
Eric Duminil's avatar
Eric Duminil committed
50
    }
51
  }
Eric Duminil's avatar
Eric Duminil committed
52
53
54
  Serial.print(n);
  Serial.print(" = ");
  Serial.println(n, BIN);
55
  led_ring.show();
Eric Duminil's avatar
Eric Duminil committed
56
  n = n + 1;
57

Eric Duminil's avatar
...    
Eric Duminil committed
58
59
// Wait half a second before next loop.
// Micro-controller might crash if it has too much work to do. Please don't remove it!
Eric Duminil's avatar
Eric Duminil committed
60
  delay(1000);
61
}