|
|
Taal:
|
|
int PWM_Out = 64; int CounterValue = 1; int StepPin = 7; int DirPin = 8; int Mode = 3; int OnOff = 2; int Laser = 9; void setup() { pinMode(DirPin, INPUT_PULLUP); pinMode(StepPin, INPUT_PULLUP); pinMode(Mode, INPUT_PULLUP); pinMode(OnOff, INPUT_PULLUP); analogWriteResolution(8); pinMode(Laser, OUTPUT); attachInterrupt(digitalPinToInterrupt(StepPin), Count, RISING); attachInterrupt(digitalPinToInterrupt(DirPin), ChangeDir, CHANGE); } void loop() { if (digitalRead(Mode) == HIGH) { if (digitalRead(OnOff) == HIGH) { PWM_Out = 254; } else { PWM_Out = 0; } } analogWrite(Laser, PWM_Out); } void Count() { PWM_Out = PWM_Out + CounterValue; if (PWM_Out > 254) { PWM_Out = 254; } if (PWM_Out < 0) { PWM_Out = 0; } } void ChangeDir() { CounterValue = 1; if (digitalRead(DirPin)) { CounterValue = -1; } }