-
Notifications
You must be signed in to change notification settings - Fork 0
/
CommanderRobot.ino
65 lines (50 loc) · 1.11 KB
/
CommanderRobot.ino
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
64
65
#include <serde-commander.h>
// TX commands
struct Feedback
{
float batteryLevel;
};
SERDE_COMMANDER_CREATE_TX(CommanderTX, Feedback);
// RX Commands --
struct Move
{
int x;
int y;
};
struct Rotate
{
float angle;
};
struct RequestFeedback {}; // Command has no arguments
// Callbacks must have the following signature:
// void onTypeNameReceived(const TypeName&)
void onMoveReceived(const Move& move)
{
analogWrite(5, move.x);
analogWrite(6, move.y);
}
void onRotateReceived(const Rotate& rotate)
{
analogWrite(10, rotate.angle);
}
void onRequestFeedbackReceived(const RequestFeedback& /* unused */)
{
Feedback feedback;
feedback.batteryLevel = 1.f;
CommanderTX::send(feedback, SERIAL_PORT_HARDWARE);
}
SERDE_COMMANDER_CREATE_RX(CommanderRX, Move, Rotate, RequestFeedback);
// --
void setup()
{
pinMode(5, OUTPUT); // PWM
pinMode(6, OUTPUT); // PWM
pinMode(10, OUTPUT); // PWM
// SERIAL_PORT_HARDWARE aliases to the default
// hardware serial port on your board.
SERIAL_PORT_HARDWARE.begin(115200);
}
void loop()
{
CommanderRX::read(SERIAL_PORT_HARDWARE);
}