-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwait_for_light.c
More file actions
61 lines (54 loc) · 1.69 KB
/
Copy pathwait_for_light.c
File metadata and controls
61 lines (54 loc) · 1.69 KB
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
#include <kovan/kovan.h>
void wait_for_light_save(int light_port_)
{
int xBut, l_on_, l_off_, l_mid_, OK = 0;
xBut = get_extra_buttons_visible();
set_extra_buttons_visible(0);
set_a_button_text("-");
set_c_button_text("-");
set_analog_pullup(light_port_, 1);
while (!OK) {
set_b_button_text("Light is On");
display_clear();
display_printf (0, 0, "CALIBRATE: sensor port #%d", light_port_);
display_printf(0, 1, " press button when light is on");
while(b_button_clicked() == 0) {
l_on_ = analog (light_port_);
display_printf(0,1," light on value is = %d ", l_on_);
msleep(50);
}
l_on_ = analog(light_port_); /* sensor value when light is on */
set_b_button_text("Light is Off");
display_printf(0,1," light on value is = %d ", l_on_);
msleep(200);
display_printf(0,2," press button when light off");
while(b_button_clicked() == 0) {
l_off_ = analog(light_port_);
display_printf(0,3," light off value is = %d ", l_off_);
msleep(50);
}
l_off_ = analog(light_port_); /* sensor value when light is off */
display_printf(0,3," light off value is = %d ", l_off_);
msleep(200);
if((l_off_ - l_on_) >= 60) { /* bright = small values */
OK = 1;
l_mid_ = (l_on_ + l_off_) / 3;
display_printf(0, 5, "Good Calibration!");
display_printf(0, 7, "Diff = %d: WAITING", l_off_ - l_on_);
int start = 0;
while(!start){
while(analog(light_port_) > l_mid_);
msleep(250);
if(analog(light_port_) < l_mid_){
start = 1;
}
}
} else {
display_printf(0,7,"BAD CALIBRATION");
}
}
set_extra_buttons_visible(xBut);
set_a_button_text("A");
set_b_button_text("B");
set_c_button_text("C");
}