-
Notifications
You must be signed in to change notification settings - Fork 0
/
druchiikragen.ino
140 lines (116 loc) · 3.52 KB
/
druchiikragen.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define DATAPIN 7
#define PULSEPIN 3
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(74, DATAPIN, NEO_GRB + NEO_KHZ800);
// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel. Avoid connecting
// on a live circuit...if you must, connect GND first.
int event_activatePulse;
int event_setdefault;
int event_switchoff;
int pulseRunning;
int flickerRunning;
void setup() {
Serial.begin(9600);
// if analog input pin 0 is unconnected, random analog
// noise will cause the call to randomSeed() to generate
// different seed numbers each time the sketch runs.
// randomSeed() will then shuffle the random function.
randomSeed(analogRead(0));
pinMode(PULSEPIN, INPUT_PULLUP);
event_setdefault = 1;
event_activatePulse = 0;
event_switchoff = 0;
pulseRunning = 0;
flickerRunning = 0;
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
int pulsepushed = digitalRead(PULSEPIN); // Read the state of the switch
if (pulsepushed == LOW && pulseRunning == 0){
event_activatePulse = 1;
delay(300);
} else if(pulsepushed == LOW && pulseRunning == 1){
event_switchoff = 1;
delay(2000);
}
if (event_switchoff == 1){
event_switchoff = 0;
oneColor(strip.Color(0, 0, 0)); //out
event_setdefault = 0;
pulseRunning = 0;
flickerRunning = 0;
} else {
if (event_activatePulse == 1 || pulseRunning == 1){
pulse();
pulseRunning = 1;
flickerRunning = 0;
event_activatePulse = 0;
Serial.println("make it pulse!");
}
if (event_setdefault == 1 || flickerRunning == 1) {
flicker();
flickerRunning = 1;
event_setdefault = 0;
Serial.println("make it flicker!");
}
}
}
void flicker(){
int r = 125;
int b = 75;
for (uint16_t i=0; i < strip.numPixels(); i = i +2) {
strip.setPixelColor(i, strip.Color(71, 5, 95));
strip.show();
}
for (int i = 0; i < 35; i++){
int flickerLed = random(0,strip.numPixels());
if (flickerLed % 2 == 0){
strip.setPixelColor(flickerLed, strip.Color(50, 0, 75));
strip.show();
}
}
delay(200);
}
void oneColor (uint32_t color){
for (uint16_t i=0; i < strip.numPixels(); i = i +2) {
strip.setPixelColor(i, color);
strip.show();
}
}
void pulse (){
//RGB 71, 5, 95
float r = 71;
float b = 95;
while(r >= 25){
for (uint16_t i=0; i < strip.numPixels(); i = i +2) {
strip.setPixelColor(i, strip.Color(r, 0, b));
strip.show();
}
delay(200);
r = r - (r / 1.1);
b = b - (b / 1.1);
}
while(r <= 71){
for (uint16_t y=0; y < strip.numPixels(); y = y +2) {
strip.setPixelColor(y, strip.Color(r, 0, b));
strip.show();
}
delay(200);
r = r + (r * 1.1);
b = b + (b * 1.1);
}
}