Created
May 8, 2016 22:11
-
-
Save SysOverdrive/d86af226a7e559cc3fd343a3ea447835 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 DUPA MIC | |
*/ | |
#include <Servo.h> | |
Servo myServo; // create servo object to control a servo | |
//PINS | |
int myservoPin = 9; | |
int potPin = A0; | |
int outputPinAnalog = 11; | |
int interuptPin = 3; | |
//VALUES | |
int valueOfPotentiometer; | |
int val; | |
unsigned long timp1, timp2; | |
float frecventa; | |
void setup() | |
{ timp1 = millis(); | |
Serial.begin(115200); | |
/* add setup code here */ | |
//motor | |
myServo.attach(myservoPin); // attaches the servo on pin 9 to the servo object | |
myServo.write(0); | |
pinMode(outputPinAnalog, OUTPUT); | |
//analogWrite(9,0); | |
delay(3000); | |
pinMode(2, OUTPUT); //TEST RELEU | |
digitalWrite(2, HIGH); //REZULTAT TEST NU ARE DESTUL CURENT ARDUINO | |
//encoder | |
attachInterrupt(digitalPinToInterrupt(interuptPin), ISRFunction, RISING); | |
} | |
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);//pin 9 | |
} | |
void ISRFunction() | |
{ | |
frecventa =1000000/(float)(micros() - timp2); //Din cauza decentrarii avem variatie de 10 Hz | |
timp2 = micros(); | |
Serial.println(frecventa); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment