forked from stelgenhof/AiLight
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAiLight_Rainbow.ino
58 lines (50 loc) · 1.38 KB
/
AiLight_Rainbow.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
A simple example making the AiLight showing a rainbow effect using the
AiLight library.
This file is part of the AiLight library.
Copyright (c) 2017 Sacha Telgenhof (<stelgenhof at gmail dot com>). All
rights reserved.
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
*/
#include "AiLight.hpp"
#define RAINBOW_DELAY 10 // Time to wait for next colour (in milliseconds)
/**
* @brief Show a rainbow effect
*
* Thanks to Xose Pérez for the rainbow effect code
* (https://github.com/xoseperez/my9291)
*
* @param index an index to determine the colour to be displayed
*
* @return void
*/
void rainbowEffect(uint8_t index) {
if (index < 85) {
AiLight.setColor(index * 3, 255 - index * 3, 0);
} else if (index < 170) {
index -= 85;
AiLight.setColor(255 - index * 3, 0, index * 3);
} else {
index -= 170;
AiLight.setColor(0, index * 3, 255 - index * 3);
}
}
/**
* @brief Bootstrap/Initialisation
*/
void setup() {
AiLight.setState(true); // Switch on the light
}
/**
* @brief Main loop
*/
void loop() {
static unsigned long previousMillis = millis();
// Show the rainbow...
if (millis() - previousMillis > RAINBOW_DELAY) {
static uint8_t count = 0;
previousMillis = millis();
rainbowEffect(count++);
}
}