hi all, my name is mike from new zealand,
i have been experimenting with microcontrollers on and off for a while,however i have not yet done any programming,but i thought id give it a try with aduino to get my feet wet.
i have a question for those that are able to help,
there is a code posted by a user on youtube to run a hdd motor through a model brushless esc,speed controlled via a pot. i have copied the sketch and tried to verify it, however it throws up some error codes,which i cannot copy and paste...i know i need to do some reading on how to program,but i just want to get this setup going to get started, as i plan to build an electric car speed controller that is 4wd and i think this code is a good one to build onto.
would someone be kind enough to run me through what i should be doing to make this operational?
for arguments sake, i could use A0 PIN 9 as an output to the controller and AREF PIN0 as the input for the pot.
thanks so much in advance!
mike
=========================================
/*
DEMO sketch for arming and running a generic ESC brushless motor controller from an Arduino and using a potentiometer to vary the motor speed.
Tested and working.
19 Feb 2011
*/
#include (Servo.h)
Servo myservo;
int val; //Value for motor speed.
int analogPin = 3; //Potentiometer on pin 3
int servoPin = 9; //ESC on pin 9
int armValue=20; //"ZERO" position for arming ESC. As some wont arm with a '0' value from the arduino. (may need to experiment)
void arm(){ //Arming sequence of sending a minimum or 'joystick zero' for 2 seconds to simulate radio gear is ON and operational. myservo.write(armValue);
delay(2500); //Delay for the ESC to activate. (may need to experiment)
}
void setup() { Serial.begin(9600);
myservo.attach(servoPin); arm();
}
void loop(){
int val = analogRead(analogPin); //Make a analogue reading. This is from 0-1023
val = map(val, 0, 1023, armValue, 180); //Scale input to use it with the servo ie from the arming value to 180.
myservo.write(val); //Send servo position - Motor speed to ESC.
Serial.println(val); delay(100);