Last active
May 22, 2016 06:55
-
-
Save hbhargava7/b52db38ee8a8de55b2a75443ff59ef8d to your computer and use it in GitHub Desktop.
Basics of controlling an electronic speed controller with an Arduino.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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