Skip to content

Instantly share code, notes, and snippets.

@SysOverdrive
Created May 14, 2016 04:21
Show Gist options
  • Save SysOverdrive/9938e69e84322a0c8f222cee495145b7 to your computer and use it in GitHub Desktop.
Save SysOverdrive/9938e69e84322a0c8f222cee495145b7 to your computer and use it in GitHub Desktop.
//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