-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnerf.ino
74 lines (62 loc) · 2.05 KB
/
nerf.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
#include "RgbLed.h"
#include "Vibro.h"
#include "Switcher.h"
#include "AnimationsController.h"
#include "AnimationsForLed.h"
#include "AnimationsForVibro.h"
RgbLed led(5, 6, 9);
Vibro vibro(3);
Switcher switcher(8, 200);
AnimationsController animations;
void playPowerOnAnimations()
{
animations.since(micros())
.add(80, new FadeInLedAnimation(led, ColorRgb(0, 150, 150)))
.pause(80)
.add(80, new FadeOutLedAnimation(led, ColorRgb(0, 150, 150)));
while(!animations.empty())
{
animations.process(micros());
}
delay(100);
}
void setup()
{
playPowerOnAnimations();
}
void loop()
{
long currTime = micros();
if (switcher.checkChanges(currTime))
{
const bool noAmmo = switcher.state() == Switcher::On;
animations.clear();
if (noAmmo)
{
animations.since(currTime + 150 * 1000)
.add(300, new VibroAnimation(vibro, 255)).pause(50)
.add(200, new VibroAnimation(vibro, 127))
.add(50, new VibroAnimation(vibro, 0))
.add(200, new VibroAnimation(vibro, 127))
.add(0, new VibroAnimation(vibro, 0));
const ColorRgb clr(255, 0, 0);
animations.since(currTime)
.add(250, new FadeInLedAnimation(led, clr)).pause(100)
.add(100, new FadeInLedAnimation(led, clr)).pause(50)
.add(100, new FadeInLedAnimation(led, clr));
}
else // have Ammo
{
animations.since(currTime + 300 * 1000)
.add(150, new VibroAnimation(vibro, 63))
.add(150, new VibroAnimation(vibro, 127))
.add(150, new VibroAnimation(vibro, 255))
.add(10, new VibroAnimation(vibro, 0));
const ColorRgb clr(0, 255, 0);
animations.since(currTime)
.add(150, new FadeInLedAnimation(led, clr)).pause(100)
.add(250, new FadeInLedAnimation(led, clr));
}
}
animations.process(currTime);
}