Using the tymkrs “Turn Me” with an Arduino




/* Read Quadrature Encoder
 * Connect Encoder to Pins encoder0PinA, encoder0PinB, and +5V.
 * Sketch by max wolf / www.meso.net
 * v. 0.1 - very basic functions - mw 20061220
 * Sketch updated by Brooke Hedrick / www.millamilla.com
 * v. 0.2 - Added the "S" pin for encoders with push-down support - bth 09292013
 *        - Put a limit of 255 and 0 in place.  It rolls over automatically at the limits - bth 09292013
 *
 */
 Using the tymkrs “Turn Me” with an Arduino




int val;
int encoder0PinA = 3;
int encoder0PinB = 4;
int encoder0PinS = 5;
int encoder0PosUp = 0;
int encoder0PosDown = 0;
int encoder0PinALast = LOW;
int n = LOW;
int encoder0UpDown = LOW;
void setup() {
  pinMode(encoder0PinA,INPUT);
  pinMode(encoder0PinB,INPUT);
  pinMode(encoder0PinS,INPUT);
  Serial.begin (9600);
}
void loop() {
  encoder0UpDown = digitalRead(encoder0PinS);
  n = digitalRead(encoder0PinA);
  if ((encoder0PinALast == LOW) && (n == HIGH)) {
    //Serial.print("up down:");
    //Serial.println(encoder0UpDown);
    if (digitalRead(encoder0PinB) == LOW) {
      if (encoder0UpDown == LOW) {
        encoder0PosUp--;
        if (encoder0PosUp < 0) {
            encoder0PosUp = 255;
        }
      } else {
        encoder0PosDown--;
        if (encoder0PosDown < 0) {
            encoder0PosDown = 255;
        }
      }
    } else {
      if (encoder0UpDown == LOW) {
        encoder0PosUp++;
        if (encoder0PosUp > 255) {
          encoder0PosUp = 0;
        }
      } else {
        encoder0PosDown++;
        if (encoder0PosDown > 255) {
          encoder0PosDown = 0;
        }
      }
    }
    Serial.print(encoder0PosUp);
    Serial.print(" ");
    Serial.println(encoder0PosDown);
  }
  encoder0PinALast = n;
}
Using the tymkrs “Turn Me” with an Arduinooutput_window




Clip to Evernote

Leave a Comment

(Spamcheck Enabled)

Read previous post:
Theremin w/Zapper,laser,Arduino using arduino

I created this Theremin like device after seeing this article in Make magazine: http://m-cdn.dashdigital.com/make/vol15/?pg=69#pg67 While this looked pretty straight forward...

Close
Scroll to top