fb11e647
vrobic
reseau statique a...
|
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
|
/*
Arduino Hello-World @ RIOT
Prints 'Hello Arduino!' once on the serial port during startup, toggles the
default LED twice each seconds and echoes incoming characters on the serial
port.
*/
// Per convention, RIOT defines a macro that is assigned the pin number of an
// on-board LED. If no LED is available, the pin number defaults to 0. For
// compatibility with the Arduino IDE, we also fall back to pin 0 here, if the
// RIOT macro is not available
#ifndef ARDUINO_LED
#define ARDUINO_LED (0)
#endif
// Assign the default LED pin
int ledPin = ARDUINO_LED;
// input buffer for receiving chars on the serial port
int buf[64];
// counter that counts the number of received chars
int count = 0;
void setup(void)
{
// configure the LED pin to be output
pinMode(ledPin, OUTPUT);
// configure the first serial port to run with a baudrate of 115200
Serial.begin(115200);
// say hello
Serial.println("Hello Arduino!");
}
void loop(void)
{
// toggle the LED
digitalWrite(ledPin, !digitalRead(ledPin));
// test if some chars were received
while (Serial.available() > 0) {
// read a single character
int tmp = Serial.read();
// if we got a line end, we echo the buffer
if (tmp == '\n') {
// start with printing 'ECHO: '
Serial.write("Echo: ");
// echo the buffer
for (int i = 0; i < count; i++) {
Serial.write(buf[i]);
}
// terminate the string with a newline
Serial.write('\n');
// reset the count variable
count = 0;
}
// else we just remember the incoming char
else {
buf[count++] = tmp;
}
}
// wait for half a second
delay(500);
}
|