-
Notifications
You must be signed in to change notification settings - Fork 1
/
led_panic.ino
49 lines (40 loc) · 958 Bytes
/
led_panic.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
/*
Sine fade
Takes a linear input from an analog sensor
and produces a sinusoidal fade curve
created 30 Jan 2019
by Tom Igoe and lighting & interactivity 2019 class
*/
int intensity = 255;
int change = 4;
void setup() {
Serial.begin(9600);
pinMode(2, INPUT);
}
void loop() {
if (intensity <= 0 || intensity >= 255) {
change = -change;
}
intensity = intensity + change;
float result = sineFade1(intensity, 0, 255);
if (digitalRead(6) == HIGH) {
result = 0;
}
analogWrite(10, result);
if (result == 189.31) {
delay(500);
} else {
delay(5);
}
Serial.println(result);
}
float sineFade1(int inValue, int minValue, int maxValue) {
float angle = map(inValue, minValue, maxValue, 0, 179);
if (angle >= 60) {
float result = (sin((angle * PI / 180) + PI / 2) + 1) * 172.5;
return result;
} else {
float result = (sin((angle * PI / 180) + PI / 2) + 1) * 70;
return result;
}
}