-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshh.ino
157 lines (144 loc) · 3.62 KB
/
shh.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define NUMLEDS 70
#define PIN 4
int sensorValue = 0;
int sensorMin = 1023;
int sensorMax = 0;
const int sensorPin = A0;
const int buttonPin = 2;
const int ledPin = 4;
const int thresh = 700;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMLEDS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
Serial.begin(9600);
strip.begin();
strip.show();
}
void loop() {
if (!digitalRead(buttonPin)) {
digitalWrite(ledPin, HIGH);
Serial.println(analogRead(0));
if (analogRead(0) > thresh) {
Serial.println("shh");
meteorRain(50, 255, 0, 10, 64, true, 20);
}
} else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}
void colorWipe(uint32_t c, uint8_t wait) {
for (uint16_t i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
void TwinkleRandom(int Count, int SpeedDelay, boolean OnlyOne) {
// Vertical Patern
setAll(0, 0, 0);
for (int i = 0; i < Count; i++) {
setPixel(random(NUMLEDS), random(0, 255), random(0, 255), random(0, 255));
strip.show();
delay(SpeedDelay);
if (OnlyOne) {
setAll(0, 0, 0);
}
}
delay(SpeedDelay);
}
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if (WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if (WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {
setAll(0, 0, 0);
for (int i = 0; i < NUMLEDS + NUMLEDS; i++) {
// fade brightness all LEDs one step
for (int j = 0; j < NUMLEDS; j++) {
if ( (!meteorRandomDecay) || (random(10) > 5) ) {
fadeToBlack(j, meteorTrailDecay );
}
}
// draw meteor
for (int j = 0; j < meteorSize; j++) {
if ( ( i - j < NUMLEDS) && (i - j >= 0) ) {
setPixel(i - j, red, green, blue);
}
}
showStrip();
delay(SpeedDelay);
}
}
void fadeToBlack(int ledNo, byte fadeValue) {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
uint32_t oldColor;
uint8_t r, g, b;
int value;
oldColor = strip.getPixelColor(ledNo);
r = (oldColor & 0x00ff0000UL) >> 16;
g = (oldColor & 0x0000ff00UL) >> 8;
b = (oldColor & 0x000000ffUL);
r = (r <= 10) ? 0 : (int) r - (r * fadeValue / 256);
g = (g <= 10) ? 0 : (int) g - (g * fadeValue / 256);
b = (b <= 10) ? 0 : (int) b - (b * fadeValue / 256);
strip.setPixelColor(ledNo, r, g, b);
#endif
}
void showStrip() {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
strip.show();
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
FastLED.show();
#endif
}
void setPixel(int Pixel, byte red, byte green, byte blue) {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
strip.setPixelColor(Pixel, strip.Color(red, green, blue));
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
leds[Pixel].r = red;
leds[Pixel].g = green;
leds[Pixel].b = blue;
#endif
}
void setAll(byte red, byte green, byte blue) {
for (int i = 0; i < NUMLEDS; i++ ) {
setPixel(i, red, green, blue);
}
showStrip();
}
//void callibrate () {
// while (millis() < 5000) {
// sensorValue = analogRead(sensorPin);
//
// // record the maximum sensor value
// if (sensorValue > sensorMax) {
// sensorMax = sensorValue;
// }
//
// // record the minimum sensor value
// if (sensorValue < sensorMin) {
// sensorMin = sensorValue;
// }
// }
//}