I have built a Brushless motor powerwheels for my daughter which is very fast for a 5 year old, she is used to the speed (12mph) but her friends would like to drive it and I am concerned that it will be too fast for them and would like to add a switch to limit the top speed of the motors to around 50%.
i copied the Arduino code from the net and it works great but am a complete novice when it comes to changing/adding code.
Could someone with more knowledge tell me the code for adding a high/low switch and what pin for the output from the switch to run in low mode.
this is the code I used (sorry for the format) and the picture is the wiring diagram for the arduino
#include <Servo.h>
const byte servoPin = 9; // signal pin for the ESC.
const byte potentiometerPin = A0; // analog input pin for the power pedal.
int pwmVal; //Output value to ESC
int revOn = 0; //Value for reverse switch HIGH/LOW
const byte revPin = 13; //Pin for revers switch
Servo servo; //Servo object
void setup() {
pinMode(revPin, INPUT);
servo.attach(servoPin);
servo.writeMicroseconds(1500); // send "stop" signal to ESC. Also necessary to arm the ESC.
delay(7000); // delay to allow the ESC to recognize the stopped signal.
}
void loop() {
revOn = digitalRead(revPin); //Check state of reverse switch
int potVal = analogRead(potentiometerPin); // read input from potentiometer.
//If reverse switch is on HIGH set reverse PWM range
// 1500 means no accel
// < 1500 is reverse
// > 1500 is forward
if(revOn == HIGH)
{
pwmVal = map(potVal,200, 850, 1450, 1000); // maps potentiometer values to PWM value in reverse range
} else {
pwmVal = map(potVal,170, 850, 1550, 2000); // maps potentiometer values to PWM value in forward range
}
if (pwmVal < 1555 and pwmVal > 1460) //Use a range to buffer for error if accel pedal is not pressed
{
pwmVal = 1500;
}
servo.writeMicroseconds(pwmVal); // Send signal to ESC.
}

