Changeset 1172 in t29-www


Ignore:
Timestamp:
Mar 20, 2017, 10:26:20 PM (3 years ago)
Author:
heribert
Message:

Encoder-Programm korrigiert

File:
1 edited

Legend:

Unmodified
Added
Removed
  • physical-computing/encoder-mit-interrupt/encoder-mit-interrupt.ino

    r1171 r1172  
    22 * Rotary-Encoder Sketch mit Interrupt Nr. 2
    33 * beachte: Bei schnellen Vorgaengen verlangsamt der Serielle-Monitor den Sketch!
    4  * 
     4 * Wenn der Button (Switch) zum Rueckstellen ins Programm eingebaut wird, muss
     5 * man den INPUT mit PULLUP versehen!
     6 *
    57 * read a rotary encoder with interrupts
    68   Encoder hooked up with common to GROUND,
     
    1517#define encoder0PinA  2
    1618#define encoder0PinB  3
    17 #define buttonPin 4
    1819
    1920volatile int encoder0Pos = 0;
     
    2324  pinMode(encoder0PinA, INPUT);
    2425  pinMode(encoder0PinB, INPUT);
    25   pinMode(buttonPin, INPUT_PULLUP);
    26 
     26 
    2727  attachInterrupt(0, doEncoder, CHANGE);  // encoder pin on interrupt 0 - pin 2
    2828  Serial.begin (9600);
    29   Serial.println("Start");               
     29  Serial.println("Start des Programms");               
    3030}
    3131
     
    3939   */
    4040  if (digitalRead(encoder0PinA) == digitalRead(encoder0PinB)) {
     41    encoder0Pos++;
     42  } else {
    4143    encoder0Pos--;
    42   } else {
    43     encoder0Pos++;
    4444  }
    4545   Serial.print("    ");
     
    4747}
    4848
    49   // you don't want serial slowing down your program if not needed
     49 
    5050
Note: See TracChangeset for help on using the changeset viewer.
© 2008 - 2013 technikum29 • Sven Köppel • Some rights reserved
Powered by Trac
Expect where otherwise noted, content on this site is licensed under a Creative Commons 3.0 License