-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsparkiSense.ino
70 lines (66 loc) · 1.78 KB
/
sparkiSense.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
#include <Sparki.h>
#define NO_ACCEL // disables the Accelerometer, frees up 598 Bytes Flash Memory
#define NO_MAG // disables the Magnetometer, frees up 2500 Bytes Flash Memory
//FUNCTIONS
void wallSense()
{
if(sparki.ping() != -1)
{
if(sparki.ping() < 20)
{
//lcd control
sparki.clearLCD();
sparki.drawRectFilled(0,54, 74,40); //draw a big exclamation mark
sparki.drawRectFilled(54,64, 74,50);
sparki.updateLCD();
//actions
sparki.RGB(RGB_RED);
sparki.moveStop(500); //stop for 500ms
sparki.moveBackward(5);
sparki.moveRight(45); //turn right 45 degree
sparki.RGB(RGB_GREEN);
}
}
}
void edgeSense()
{
if (sparki.edgeLeft() <= 200) //if left edge sensor detects a distance greater than or equal to 50
{
//lcd control
sparki.clearLCD();
sparki.drawRectFilled(0,54, 74,40); //draw a big exclamation mark
sparki.drawRectFilled(54,64, 74,50);
sparki.updateLCD();
//actions
sparki.RGB(RGB_RED); //turn light red
sparki.moveStop(500); //stop for 500ms
sparki.moveBackward(5); //move backwards 5cm
sparki.moveRight(45); //turn right 45 degrees
sparki.RGB(RGB_GREEN); //return light to green
}
if(sparki.edgeRight() <= 200)
{
//lcd control
sparki.clearLCD();
sparki.drawRectFilled(0,54, 74,40); //draw a big exclamation mark
sparki.drawRectFilled(54,64, 74,50);
sparki.updateLCD();
//actions
sparki.RGB(RGB_RED);
sparki.moveStop();
sparki.moveBackward(5);
sparki.moveLeft(45);
sparki.RGB(RGB_GREEN);
}
}
void setup()
{
sparki.servo(SERVO_CENTER); // Center the Servo
}
void loop()
{
edgeSense();
wallSense();
sparki.moveForward();
delay(100);
}