-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.nxc
60 lines (52 loc) · 1.36 KB
/
example.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "NXTViSy.nxc"
#define PORT IN_1
#define SIGNATURE 1
void PrintInitError(long error_code)
{
TextOut(0, LCD_LINE4, "NXTViSyInit error: ");
NumOut(90, LCD_LINE4, error_code);
while(1) {
;
}
}
void PrintGetDataError(byte error_code)
{
if (error_code == GET_DATA_I2C_BYTES_ERR) {
TextOut(0, LCD_LINE5, "I2CBytes error in function");
TextOut(0, LCD_LINE6, "GetData()");
while (true) {
;
}
}
if (error_code == GET_DATA_RECEIVED_BYTES_ERR) {
TextOut(0, LCD_LINE5, "Unexpected count of bytes");
TextOut(0, LCD_LINE6, "received in function GetData()");
while (true) {
;
}
}
}
task main()
{
SetSensorNXTViSy(PORT);
long err = NXTViSyInit(SIGNATURE, 10, 24 * 100);
if (err != NO_ERR) {
PrintInitError(err);
}
int distance;
byte action;
string writable_action = "x";
while (true) {
ClearScreen();
err = NXTViSyGetData(distance, action); // byte vyriable would by enough, but long can be used
if (err != NO_ERR) {
PrintGetDataError(err);
}
writable_action[0] = action;
TextOut(0, LCD_LINE4, "Distance: ");
NumOut(60, LCD_LINE4, distance);
TextOut(0, LCD_LINE5, "Action: ");
TextOut(48, LCD_LINE5, writable_action);
Wait(100);
}
}