JeVois Tutorials  1.21
JeVois Smart Embedded Machine Vision Tutorials
 
Share this page:
Loading...
Searching...
No Matches
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
12char instr[INLEN + 1];
13
14// Our desired object: should be one of the 1000 ImageNet category names
15#define CATEGORY "computer_keyboard"
16
17void setup()
18{
19 SERIAL.begin(115200);
20 SERIAL.setTimeout(500);
21
22 pinMode(LEDPIN, OUTPUT);
23 digitalWrite(LEDPIN, HIGH);
24}
25
26void 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}
#define LEDPIN
Definition ardublinkez.C:4
void setup()
Definition ardublinkez.C:17
#define INLEN
Definition ardublinkez.C:11
#define CATEGORY
Definition ardublinkez.C:15
#define SERIAL
Definition ardublinkez.C:8
char instr[INLEN+1]
Definition ardublinkez.C:12
void loop()
Definition ardublinkez.C:26