-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSnailbox.ino
137 lines (105 loc) · 2.74 KB
/
Snailbox.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
/****************************************************************************
SNAILBOX
this sketch is for a proejct called SNAILBOX, [email protected]
major features:
- connect to WPA SSID
- manage colors, intensity and animation of neopixel(ws2812b)
- read data coming from an 3x accelerometer (MMA7660) the grove one
******************************************************************************/
#include "axis.h"
#include "strip.h"
#include "wifi.h"
WiFiClient client;
int delayval = 200; // delay for half a second
int ldrPin = A1;
int threshold = 25; //threshold of LDR reed
bool rlx = false;
bool fcs = false;
bool sprt = false;
/*
SETUP
*/
void setup()
{
// IF YOU ARE USING AN AVR_ATtiny85 YOU NEED THIS
#if defined (__AVR_ATtiny85__)
if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
Serial.begin(9600);
//**********************************************************
//*************init led strip******************************
//**********************************************************
stripBegin();
//**********************************************************
//*************starting accellerometer setup****************
//**********************************************************
accelBegin();
//**********************************************************
//************STARTING CONNECTION***************************
//**********************************************************
startConnection();
}
/*
LOOP
*/
int f = 0;
int delta = 10;
int r = 0;
uint16_t s = 0;
void loop()
{
int mood = getPos();
int ldr = analogRead(ldrPin);
Serial.println(ldr);
if (ldr <= threshold) {
switch (mood) {
//**********************
//relax mood, warm light
case 0:
{
Serial.println("Relax");
if (!rlx) {
send_event("Relax");
rlx = true;
}
f = 0;
r = rainbow(20, r);
fcs = false;
sprt = false;
break;
}
//**********************
//focus mood, strong light
case 1:
{
Serial.println("Focus");
if (!fcs) {
send_event("Focus");
fcs = true;
}
r = 0;
f = focus(f);
rlx = false;
sprt = false;
break;
}
//**********************
//Sprint mood, rainbow light
case 2:
{
Serial.println("Sprint");
if (!sprt) {
send_event("Sprint");
sprt = true;
}
s = sprint(s);
rlx = false;
fcs = false;
break;
}
}
}
else offLamp();
delay(delayval);
}