forked from SSR-Harvard/kilobotics-labs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_listener_mod.c
68 lines (59 loc) · 1.31 KB
/
test_listener_mod.c
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
#include <kilolib.h>
int new_message = 0;
int distance = 0;
int odd = 0;
void setup()
{
}
void loop()
{
if (new_message == 1)
{
new_message = 0;
// Near ...
if (distance <= 50)
{
// ... and even: set the LED red.
if (odd == 0)
{
set_color(RGB(1, 0, 0));
}
// ... and odd: set the LED green.
else
{
set_color(RGB(0, 1, 0));
}
}
// Far ...
else
{
// ... and even: set the LED blue.
if (odd == 0)
{
set_color(RGB(0, 0, 1));
}
// ... and odd: set the LED yellow.
else
{
set_color(RGB(1, 1, 0));
}
}
// Wherever you are: set LED off after 100 ms to achieve blink effect.
delay(100);
set_color(RGB(0, 0, 0));
}
}
void message_rx(message_t *message, distance_measurement_t *distance_measurement)
{
// Set flag on message reception.
new_message = 1;
distance = estimate_distance(distance_measurement);
odd = message->data[0];
}
int main()
{
kilo_init();
kilo_message_rx = message_rx;
kilo_start(setup, loop);
return 0;
}