Created
May 14, 2016 04:21
-
-
Save SysOverdrive/9938e69e84322a0c8f222cee495145b7 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
//PINS | |
int outputPinAnalog = 11; | |
int interuptPin = 3; | |
//VALUES | |
unsigned long timp1, timp2; | |
float frecventa; | |
int motorValue = 125;//jumatate din viteza | |
void setup() | |
{ timp1 = millis(); | |
Serial.begin(115200); | |
//motor | |
writePwm(240);//max 255 | |
delay(3000); | |
//encoder | |
attachInterrupt(digitalPinToInterrupt(interuptPin), ISRFunction, RISING); | |
} | |
void loop() | |
{ | |
writePwm(motorValue); | |
} | |
void writePwm(int motorValue) | |
{ | |
analogWrite(outputPinAnalog, motorValue); | |
} | |
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