forked from sysrun/Reflecta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReflectaServo.cpp
36 lines (30 loc) · 930 Bytes
/
ReflectaServo.cpp
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
#include "Reflecta.h"
#include "ReflectaServo.h"
namespace ReflectaServo {
Servo servos[MAX_SERVOS];
// TODO(jay): Support variant attach(pin, min, max)
void servoAttach() {
int8_t pin = reflectaFunctions::pop();
servos[pin].attach(pin);
}
void servoDetach() {
int8_t pin = reflectaFunctions::pop();
servos[pin].detach();
}
void servoWrite() {
int8_t pin = reflectaFunctions::pop();
int8_t val = reflectaFunctions::pop();
servos[pin].write(val);
}
void servoWriteMicroseconds() {
int8_t pin = reflectaFunctions::pop();
int8_t val = reflectaFunctions::pop16();
servos[pin].writeMicroseconds(val);
}
void setup() {
reflectaFunctions::bind("srvo1", servoAttach);
reflectaFunctions::bind("srvo1", servoDetach);
reflectaFunctions::bind("srvo1", servoWrite);
reflectaFunctions::bind("srvo1", servoWriteMicroseconds);
}
}; // namespace reflectaServo