JeVois Tutorials
1.22
JeVois Smart Embedded Machine Vision Tutorials
Share this page:
Tweet
Loading...
Searching...
No Matches
doc
snip
ardublinkez.C
Go to the documentation of this file.
1
// JeVois + Arduino blink for X - easy version
2
3
// Pin for LED, blinks as we receive serial commands:
4
#define LEDPIN 17
5
6
// Serial port to use: on chips with USB (e.g., 32u4), that usually is Serial1.
7
// On chips without USB, use Serial:
8
#define SERIAL Serial1
9
10
// Buffer for received serial port bytes:
11
#define INLEN 256
12
char
instr
[
INLEN
+ 1];
13
14
// Our desired object: should be one of the 1000 ImageNet category names
15
#define CATEGORY "computer_keyboard"
16
17
void
setup
()
18
{
19
SERIAL
.begin(115200);
20
SERIAL
.setTimeout(500);
21
22
pinMode(
LEDPIN
, OUTPUT);
23
digitalWrite(
LEDPIN
, HIGH);
24
}
25
26
void
loop
()
27
{
28
// Read a line of data from JeVois:
29
byte
len =
SERIAL
.readBytesUntil(
'\n'
,
instr
,
INLEN
);
30
31
// Make sure the string is null-terminated:
32
instr
[len--] =
'\0'
;
33
34
// Cleanup any trailing whitespace:
35
while
(len >= 0 &&
instr
[len] ==
' '
||
instr
[len] ==
'\r'
||
instr
[len] ==
'\n'
)
instr
[len--] =
'\0'
;
36
37
// If empty (including timeout), stop here:
38
if
(len < 0)
39
{
40
digitalWrite(
LEDPIN
, HIGH);
// turn LED off (it has inverted logic)
41
return
;
42
}
43
44
// If the message is a match for our desired category, turn led on, otherwise off:
45
if
(strcmp(
instr
,
"TO "
CATEGORY
) == 0)
46
digitalWrite(
LEDPIN
, LOW);
// turn LED on (it has inverted logic)
47
else
48
digitalWrite(
LEDPIN
, HIGH);
// turn LED off
49
}
LEDPIN
#define LEDPIN
Definition
ardublinkez.C:4
setup
void setup()
Definition
ardublinkez.C:17
INLEN
#define INLEN
Definition
ardublinkez.C:11
CATEGORY
#define CATEGORY
Definition
ardublinkez.C:15
SERIAL
#define SERIAL
Definition
ardublinkez.C:8
instr
char instr[INLEN+1]
Definition
ardublinkez.C:12
loop
void loop()
Definition
ardublinkez.C:26
Please help us improve this page: Edit it on
GitHub
or
email us your edits and suggestions.
Generated by
1.9.8