Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int val;
- int encoder0PinA = 5;
- int encoder0PinB = 6;
- int encoder0Direction = 0;
- int encoder0PinALast = LOW;
- int n = LOW;
- int pingTimeout = 1000;
- unsigned long lastPing = 0;
- void setup() {
- pinMode (encoder0PinA,INPUT);
- pinMode (encoder0PinB,INPUT);
- Serial.begin (115200);
- }
- void loop() {
- n = digitalRead(encoder0PinA);
- if ((encoder0PinALast == LOW) && (n == HIGH)) {
- if (digitalRead(encoder0PinB) == LOW) {
- encoder0Direction = -1;
- } else {
- encoder0Direction = 1;
- }
- Serial.println (encoder0Direction);
- }
- else{
- if(millis()-lastPing >= pingTimeout || millis() < 1000){
- Serial.println (0);
- lastPing = millis();
- }
- }
- encoder0PinALast = n;
- }
Advertisement
Add Comment
Please, Sign In to add comment