-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathSimplexServo.h
More file actions
57 lines (46 loc) · 1.24 KB
/
Copy pathSimplexServo.h
File metadata and controls
57 lines (46 loc) · 1.24 KB
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
/*
===============================================================================
SimplexServo - Cross-platform Servo control helper for SimplexNoise
By Jordan Shaw / 2025
Provides a unified interface for controlling servos on different Arduino
platforms (Standard Arduino, ESP32, etc.)
Part of the SimplexNoise library
===============================================================================
*/
#ifndef SIMPLEX_SERVO_H
#define SIMPLEX_SERVO_H
#include <Arduino.h>
#if defined(TEENSYDUINO)
#include <PWMServo.h>
#elif defined(ESP32)
#include <ESP32Servo.h>
#else
#include <Servo.h>
#endif
class SimplexServo {
public:
// Constructor
SimplexServo() : _pin(-1) {}
// Initialize servo with pin
void attach(int pin) {
_pin = pin;
_servo.attach(pin);
}
// Initialize servo with pin and optional min/max pulse widths
void attach(int pin, int min, int max) {
_pin = pin;
_servo.attach(pin, min, max);
}
// Write angle to servo (handles cross-platform differences)
void write(int angle) {
_servo.write(angle);
}
private:
#if defined(TEENSYDUINO)
PWMServo _servo;
#else
Servo _servo;
#endif
int _pin;
};
#endif // SIMPLEX_SERVO_H