Skip to content

Instantly share code, notes, and snippets.

@hbhargava7
Last active May 22, 2016 06:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hbhargava7/b52db38ee8a8de55b2a75443ff59ef8d to your computer and use it in GitHub Desktop.
Save hbhargava7/b52db38ee8a8de55b2a75443ff59ef8d to your computer and use it in GitHub Desktop.
Basics of controlling an electronic speed controller with an Arduino.
/* Created by Hersh Bhargava of H2 Micro (www.h2micro.com) */
#include <Servo.h>
Servo esc1; //Create a servo object to control a servo.
int xPotPin = 0; //Pins for analog potentiometers.
int esc1Value;
void setup() {
Serial.begin(9600);
}
void loop() {
esc1.attach(11); //Attach to the servo on the desired pin.
esc1Value = analogRead(xPotPin);
esc1Value = map(esc1Value, 0, 512, 0, 179); //Map values for the speed controller given the predetermined range.
esc1.write(esc1Value); //Write the values to the speed controller, thereby executing the speed change.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment