-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdesklamp.ino
105 lines (84 loc) · 2.65 KB
/
desklamp.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <FastLED.h>
#include <Arduino.h>
FASTLED_USING_NAMESPACE
// This pattern shows you a rainbowsnake and afterwards it is brighten the desk lamp
//
// Based on example by Mark Kriegsman, December 2014
#if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3001000)
#warning "Requires FastLED 3.1 or later; check github for latest code."
#endif
#define DATA_PIN 8
#define LED_TYPE WS2811
#define COLOR_ORDER BRG
#define NUM_LEDS 67
CRGB leds[NUM_LEDS];
#define BRIGHTNESS 255
#define FRAMES_PER_SECOND 120
bool startup = true;
bool worklightReady = true;
void setup() {
Serial.begin(9600);
Serial.println("Hello");
delay(3000); // 3 second delay for recovery
// tell FastLED about the LED strip configuration
FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
//FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
// set master brightness control
FastLED.setBrightness(BRIGHTNESS);
}
// List of patterns to cycle through. Each is defined as a separate function below.
typedef void (*SimplePatternList[])();
SimplePatternList gPatterns = { sinelon, worklight, setWorklightOn };
uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current
uint8_t gHue = 0; // rotating "base color" used by many of the patterns
void loop()
{
// Call the current pattern function once, updating the 'leds' array
if (startup) {
gPatterns[gCurrentPatternNumber]();
} else if (worklightReady) {
setWorklightOn();
} else {
gPatterns[1]();
}
// send the 'leds' array out to the actual LED strip
FastLED.show();
// insert a delay to keep the framerate modest
FastLED.delay(1000 / FRAMES_PER_SECOND);
EVERY_N_MILLISECONDS( 7200 ) {
startup = false;
}
}
#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
void sinelon()
{
Serial.println("doing sinelon Pattern");
// do some periodic updates
EVERY_N_MILLISECONDS( 20 ) {
gHue++; // slowly cycle the "base color" through the rainbow
}
// a colored dot sweeping back and forth, with fading trails
fadeToBlackBy( leds, NUM_LEDS, 20);
int pos = beatsin16( 13, 0, NUM_LEDS - 1 );
leds[pos] += CHSV( gHue, 255, 192);
}
int brightness = 0;
void worklight()
{
if (brightness >= 255) return;
Serial.println("doing worklight Pattern");
FastLED.setBrightness(brightness);
FastLED.show();
delay(50);
brightness++;
}
void setWorklightOn()
{
Serial.println("setting up worklight Pattern");
FastLED.setBrightness(0);
for (int j = 0; j < NUM_LEDS; j++) {
leds[j] = TypicalSMD5050 & CarbonArc;
FastLED.show();
}
worklightReady = false;
}