-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWelcome-Sign.ino
106 lines (81 loc) · 2.36 KB
/
Welcome-Sign.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
/*
* Maker Space - Welcome Sign
*
* - Arduino Pro Mini
* - RCWL-0516 Doppler Radar Microwave Sensor
* - 64 NeoPixels
*/
#include <Adafruit_NeoPixel.h>
#define PROXSENOR_PIN (11)
#define NEOPIXEL_PIN (10)
#define NUMPIXELS (64)
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800);
#define NUMBER_OF_POINTS (24)
struct Point
{
uint32_t color;
uint8_t location;
uint8_t speed;
uint8_t duration;
boolean displayed;
};
Point points[NUMBER_OF_POINTS];
void setup(void)
{
pinMode(PROXSENOR_PIN, INPUT);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
initPoints();
clearPixels();
pixels.begin();
pixels.show();
}
void loop(void)
{
boolean proximity = digitalRead(PROXSENOR_PIN) == LOW;
calculateNextState();
clearPixels();
displayPoints(proximity);
pixels.show();
digitalWrite(LED_BUILTIN, (proximity ? HIGH: LOW));
delay(20);
}
void clearPixels(void)
{
for (int pixelIndex = 0; pixelIndex < NUMPIXELS; pixelIndex++)
pixels.setPixelColor(pixelIndex, pixels.Color(0, 0, 0));
}
void initPoints(void)
{
for (int pointIndex = 0; pointIndex < NUMBER_OF_POINTS; pointIndex++)
randonizePoint(pointIndex);
}
void randonizePoint(int pointIndex)
{
points[pointIndex].color = pixels.Color(random(0, 256), random(0, 256), random(0, 256));
points[pointIndex].location = random(0, NUMPIXELS);
points[pointIndex].speed = (random(0, 2) == 0 ? -1: 1);
points[pointIndex].duration = random(16, 32);
points[pointIndex].displayed = (random(0, 2) == 0);
}
void displayPoints(boolean proximity)
{
for (int pointIndex = 0; pointIndex < NUMBER_OF_POINTS; pointIndex++)
if (points[pointIndex].displayed)
pixels.setPixelColor(points[pointIndex].location, points[pointIndex].color);
if (proximity)
pixels.setBrightness(63);
else
pixels.setBrightness(255);
}
void calculateNextState(void)
{
for (int pointIndex = 0; pointIndex < NUMBER_OF_POINTS; pointIndex++)
{
points[pointIndex].duration = points[pointIndex].duration - 1;
if (points[pointIndex].duration == 0)
randonizePoint(pointIndex);
else
points[pointIndex].location = ((points[pointIndex].location + NUMPIXELS) + points[pointIndex].speed) % NUMPIXELS;
}
}