-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMoveSensor.nxc
45 lines (38 loc) · 1016 Bytes
/
MoveSensor.nxc
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
#define SCANNERMOTOR OUT_A
#define SCANNORMOTORDIPANGLE 73
#define SCANNERSENSOR S1
#define SCANNERTHRESHOLD 38
#define DEBUGSENSOR
byte readBit() {
RotateMotor(SCANNERMOTOR, 20, -SCANNORMOTORDIPANGLE);
Wait(200);
SetSensorColorGreen(SCANNERSENSOR);
ResetSensor(SCANNERSENSOR);
unsigned int val = Sensor(SCANNERSENSOR);
TextOut(15, LCD_LINE4, StrCat(StrCat("RAW: ", NumToStr(val)), " "));
for (int x=0; x < 9; x++) {
SetSensorColorGreen(SCANNERSENSOR);
ResetSensor(SCANNERSENSOR);
Wait(50);
val += Sensor(SCANNERSENSOR);
}
val = val / 10;
TextOut(15, LCD_LINE5, StrCat(StrCat("AVG: ", NumToStr(val)), " "));
if (val < SCANNERTHRESHOLD) {
TextOut(15, LCD_LINE6, "Result: 1");
}
else {
TextOut(15, LCD_LINE6, "Result: 0");
}
SetSensorColorNone(SCANNERSENSOR);
ResetSensor(SCANNERSENSOR);
RotateMotor(SCANNERMOTOR, 30, SCANNORMOTORDIPANGLE);
Wait(10);
return val < SCANNERTHRESHOLD ? 1 : 0;
}
task main() {
for (int i=0; i < 20; i++) {
readBit();
Wait(1000);
}
}