/*
ESC_Ramp
Based on the Sweep example in the Servo library, this allow a ramp up and down of the ESC speed based on the Min and Max values.
The Min and Max speed are defined so you can change them at one location and it will be used in the ramp as well.
*/
#include <ESC.h>
#define SPEED_MIN (1000) // Set the Minimum Speed in microseconds
#define SPEED_MAX (2000)// Set the Minimum Speed in microseconds
ESC myESC (2, SPEED_MIN, SPEED_MAX, 500);// ESC_Name (ESC PIN, Minimum Value, Maximum Value, Default Speed, Arm Value)
int deadmen= 0, oESC, cruiseButton = 1, pot = A0, val, curval = 1000;// Variable for the speed sent to the ESC
void setup() {
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);// LED Visual Output
pinMode(pot, INPUT);
pinMode(cruiseButton, INPUT);
myESC.arm();// Send the Arm value so the ESC will be ready to take commands
digitalWrite(LED_BUILTIN, HIGH);// LED High Once Armed
delay (5000);// Wait for a while
Serial.println("init finished");
}
void loop() {
Serial.println(val, DEC);
val = map(val, 800, 1023, 1000, 2000);//map potentiomater value (0-1024 to 1000-2000 micro seconds);
if (digitalRead(deadmen) == LOW){
if (digitalRead(cruiseButton) == LOW) {//check if cruise button is pressed, if it is dont modify the curval
// do nothing to curval
}
if (curval < val) { //check if curval is less than potentiometers mapped value
curval = curval + 8; // if it is less, add 5 to the curval
} else if (curval > val) { //check if curval is more than potentiometers mapped value
curval = curval - 10; //if it is more, remove 5 from the curval
}else if (curval > 1000) { //if deadmans switch isnt turned and curval is more than 1000ms (throttle down value)
curval = curval - 10; //remove 5 from curval to start slowing down if above condition is true
}
}
Serial.println(curval);
myESC.speed(curval); //write microseconds to esc
delay(50); //delay the loop 50ms
}