Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ESC control using servo library
- //
- // ESC connector black wire -> Arduino GND
- // ESC connector red wire -> Arduino 5V
- // ESC connector white/yellow wire -> Arduino pin defined below
- // Include servo library
- #include <Servo.h>
- // Define new instance of servo library
- Servo ESC;
- // Define pinout
- const int ESC_PIN = 2;
- // Define min. & max. HIGH-time (usually 1000us and
- // 2000us, but some ESCs might work over a greater
- // range so change as needed)
- const int minOnTime = 1000;
- const int maxOnTime = 2000;
- // Create variable for rpm set point in % (may be
- // changed at any time in your program to match your
- // desired rpm)
- float rpmPercentage = 100;
- void setup()
- {
- // Set ESC output pin
- ESC.attach(ESC_PIN);
- }
- void loop()
- {
- // Calculate HIGH-time for given rpm
- int onTime = map(rpm, 0, 100, minOnTime, maxOnTime);
- // Set ESC signal
- ESC.writeMicroseconds(onTime);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement