-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmshuffle_sensors.ic
126 lines (111 loc) · 2.53 KB
/
mshuffle_sensors.ic
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
/** File: mshuffle_sensors.ic
Purpose: Subroutines for sensor control and configuration.
Light sensors, "headlamp", and knob motor config.
Parameters: See config.ic
Author: Gabriel Krell
Initial commit date: 9/30
**/
int tapeR() {
return analog(RSENS) < R_THRESH;
}
int tapeL() {
return analog(LSENS) < L_THRESH;
}
int tapeValL = 0;
int tapeValR = 0;
int offValL = 0;
int offValR = 0;
void sens_config() {light_on();
while(!start_button()) {
printf("put L over tape\nLSENS = %d",analog(LSENS));
sleep(.1);
}
tapeValL = analog(LSENS);
beep();
sleep(1.0);
while(!start_button()) {
printf("take L off tape\nLSENS = %d",analog(LSENS));
sleep(.1);}
offValL = analog(LSENS);
beep();
sleep(1.0);
while(!start_button()) {
printf("put R over tape\nRSENS = %d",analog(RSENS));
sleep(.1);
}
tapeValR = analog(RSENS);
beep();
sleep(1.0);
while(!start_button()) {
printf("take R off tape\nRSENS = %d",analog(RSENS));
sleep(.1);}
offValR = analog(RSENS);
beep();
sleep(1.0);
L_THRESH = (tapeValL+offValL)/2;
R_THRESH = (tapeValR+offValR)/2;
printf("New thresholds:\nL:%d | R: %d",L_THRESH, R_THRESH);
}
void light_config() {
while(start_button() || stop_button()) {} // release buttons before pressing
while(1){
motor(LIGHT,norm_knob());
printf("L: %d /R: %d KNOB: %d\n",analog(LSENS),analog(RSENS),norm_knob());
sleep(0.25);
if (start_button()) {
LIGHT_POWER = norm_knob();
printf("LPOW set to %d",LIGHT_POWER);
tone(500.0,0.3);
break;
}
if (stop_button()) {
beep();
break;
}
}
printf("\n\n");
}
void light_on() {
motor(LIGHT,LIGHT_POWER);
LIGHT_STATE = 1;
}
void light_off() {
off(LIGHT);
LIGHT_STATE=0;
}
void toggle_light() {
if (LIGHT_STATE) {
light_on();
} else {
light_off();
}
LIGHT_STATE = !LIGHT_STATE;
}
int scrUpdatePID;
int rval;
int confirm_sens(char message[], int sensorPin, int cancellable) {
int scrUpdatePID = start_process(
sens_updates(message, sensorPin),1,250);
rval = -1;
while(start_button() || stop_button()) {} // release buttons before pressing
while(rval==-1){
if (start_button()) {
rval = 0; // continue
tone(500.0,0.3);
}
if (cancellable && stop_button()) {
rval = 1; // cancel
beep();
}
}
kill_process(scrUpdatePID);
return rval;
}
void sens_updates(char message[], int sensorPin) {
printf(message,analog(sensorPin));
msleep(500L); // sleep for .5 seconds
// will hopefully fix the difficult-to-read screen issue
}
int norm_knob() {
return knob()*100/255; // no casting, much better.
}