-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimpactsense.ino
28 lines (24 loc) · 951 Bytes
/
impactsense.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
int hits = 0; // impact count
int gAllTrig = 1000; // impact sensitivity
void setup() {
Serial.begin(9600); // initialize serial
}
void loop() {
// accelerometer data
AccelerationReading accel = { 0, 0, 0 };
accel = Bean.getAcceleration(8); uint16_t gAll = (abs(accel.xAxis)+abs(accel.yAxis)+abs(accel.zAxis));
// this detects impact so if you hit the bean
// or move it very quickly, the if is true
if ((gAll > gAllTrig)) {
Serial.println( hits );
delay(50); // prevent duplicate detection
// set led colour according to impact counter
if (hits == 1) { Bean.setLed(0,0,255); } // blue
if (hits == 2) { Bean.setLed(255,0,0); } // red
if (hits == 3) { Bean.setLed(0,255,0); } // green
if (hits == 4) { Bean.setLed(255,0,255); } // pink
if (hits == 5) { Bean.setLed(255,100,0); } // orange
if (hits == 6) { Bean.setLed(135,206,250); hits = 0; } // light blue
hits++; // increment counter
}
}