-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworking_sketch.ino
66 lines (57 loc) · 1.54 KB
/
working_sketch.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
#include <Adafruit_NeoPixel.h>
//Define variables:
#define SENSOR_PIN A4
const int LED_PIN = 6;
const int NUMPIXELS = 75;
const int INIT_BRIGHTNESS = 255;
int sensor_state;
//Initialize pixel strip
Adafruit_NeoPixel strip (NUMPIXELS, LED_PIN, NEO_GRB + NEO_KHZ800);
//Custom function, triggered when someone step on platform
void react(int init_brightness=INIT_BRIGHTNESS) {
int reaction_brightness = init_brightness;
strip.setBrightness(reaction_brightness);
strip.fill(strip.Color(141, 90, 151), 0, NUMPIXELS);
strip.show();
while (reaction_brightness > 0){
strip.setBrightness(reaction_brightness);
strip.show();
reaction_brightness -= 5;
delay(50);
}
}
//setup function (required for Arduino)
void setup() {
pinMode(SENSOR_PIN, INPUT);
strip.begin();
strip.setBrightness(INIT_BRIGHTNESS);
strip.show();
}
//Loop function: required for Arduino, main logic defined here:
void loop(){
strip.clear();
strip.setBrightness(INIT_BRIGHTNESS);
strip.show();
int loop_brightness = INIT_BRIGHTNESS;
sensor_state = digitalRead(SENSOR_PIN);
if (sensor_state == 0 ) {
strip.setPixelColor(random(NUMPIXELS),strip.Color(65, 211, 189));
strip.show();
while (loop_brightness > 0){
sensor_state = digitalRead(SENSOR_PIN);
if (sensor_state > 0){
break;
}
strip.setBrightness(loop_brightness);
strip.show();
loop_brightness = loop_brightness - 10;
delay(30);
}
if (sensor_state > 0){
react();
}
}
else {
react();
}
}