Last active
May 8, 2016 09:54
-
-
Save SysOverdrive/00c8f9ed4e912e71862f101277c375b6 to your computer and use it in GitHub Desktop.
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
/* | |
Folosim un Potentiometru pentru a simula throthle -ul de pe telecomanda legat la JR connector | |
ESC NOU SE PORNESTE CU PWM MARE SI CU DE AKA NUC | |
*/ | |
#include <Servo.h> | |
Servo myServo; // create servo object to control a servo | |
int potPin = A0; | |
int outputPinAnalog = 11; | |
int valueOfPotentiometer; | |
int val; | |
void setup() | |
{ | |
/* add setup code here */ | |
myServo.attach(9); // attaches the servo on pin 9 to the servo object | |
myServo.write(0); | |
pinMode(outputPinAnalog, OUTPUT); | |
//analogWrite(9,0); | |
delay(3000); | |
} | |
void loop() | |
{ | |
writePwmSignalByPotentiometer(); | |
/* add main program code here */ | |
} | |
void writePwmSignalByPotentiometer() | |
{ | |
valueOfPotentiometer = analogRead(potPin); // read the input pin | |
analogWrite(outputPinAnalog, valueOfPotentiometer / 3); // analogRead values go from 0 to 1023, analogWrite values from 0 to 255 (Impartim la 3 pentru ca functioneaza la 3,3 inloc de 5 pin de la ) | |
val = valueOfPotentiometer; | |
val = map(val, 0, 700, 0, 180); | |
myServo.write(val); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment