beide op een interrupt.....?
Code: Selecteer alles
int PWM_Out = 0;
int CounterValue = 1;
int StepPin = 7;
int DirPin = 8;
void setup() {
pinMode(DirPin, INPUT);
pinMode(StepPin, INPUT);
attachInterrupt(digitalPinToInterrupt(StepPin), Count, RISING);
attachInterrupt(digitalPinToInterrupt(DirPin), ChangeDir, CHANGE);
}
void loop() {
if (PWM_Out > 254)
{
PWM_Out = 254;
}
if (PWM_Out < 0)
{
PWM_Out = 0;
}
analogWrite(9, PWM_Out);
}
void Count()
{
PWM_Out = PWM_Out + CounterValue;
}
void ChangeDir()
{
CounterValue = 1;
if (digitalRead(DirPin))
{
CounterValue = -1;
}
}