Difference between revisions of "Project:Arduino Rotary Encoder Menu System"
m (Fowkc moved page Arduino Rotary Encoder Menu System to Project:Arduino Rotary Encoder Menu System) |
|||
(One intermediate revision by one other user not shown) | |||
Line 289: | Line 289: | ||
+ | OK, using adaencoder on the Pi-arduino bridge! The Arduino is just saying what it sees over serial. | ||
+ | <div style ="height:300px;overflow-x:hidden;overflow-y:auto;border: 4px solid green;"> | ||
+ | '''Raspberry Pi menu for rotary encoder''' | ||
+ | <syntaxhighlight lang="cpp" line="GESHI_FANCY_LINE_NUMBERS" enclose="div"> | ||
+ | #include <PinChangeInt.h> // necessary otherwise we get undefined reference errors. | ||
+ | #include <AdaEncoder.h> | ||
− | + | #define a_PINA 10 | |
+ | #define a_PINB 11 | ||
+ | #define BTN 9 | ||
+ | #define LED 13 | ||
+ | #define b_PINA A3 | ||
+ | #define b_PINB A4 | ||
+ | |||
+ | int8_t clicks=0; | ||
+ | char id=0; | ||
+ | |||
+ | void setup() | ||
+ | { | ||
+ | Serial.begin(9600); | ||
+ | Serial.println("---------------------------------------"); | ||
+ | pinMode(BTN, INPUT); | ||
+ | pinMode(LED, OUTPUT); | ||
+ | digitalWrite(BTN, HIGH); | ||
+ | AdaEncoder::addEncoder('a', a_PINA, a_PINB); | ||
+ | // AdaEncoder::addEncoder('b', b_PINA, b_PINB); | ||
+ | } | ||
+ | |||
+ | void loop() | ||
+ | { | ||
+ | static unsigned long btnHeld = 0; | ||
+ | encoder *thisEncoder; | ||
+ | thisEncoder=AdaEncoder::genie(&clicks, &id); | ||
+ | if (thisEncoder != NULL) { | ||
+ | thisEncoder=AdaEncoder::getFirstEncoder(); | ||
+ | |||
+ | Serial.print(id); | ||
+ | Serial.print(':'); | ||
+ | Serial.print(clicks, DEC); | ||
+ | if (clicks > 0) { | ||
+ | Serial.println(" UP"); | ||
+ | } | ||
+ | if (clicks < 0) { | ||
+ | Serial.println(" DOWN"); | ||
+ | } | ||
+ | } | ||
+ | // Upon button press... | ||
+ | if((digitalRead(BTN) == LOW) && !btnHeld){ | ||
+ | btnHeld = millis(); | ||
+ | digitalWrite(LED, HIGH); | ||
+ | Serial.println("pressed"); | ||
+ | |||
+ | } | ||
+ | // Upon button release... | ||
+ | if((digitalRead(BTN) == HIGH) && btnHeld){ | ||
+ | long t = millis(); | ||
+ | digitalWrite(LED, LOW); | ||
+ | Serial.print("released: (after "); | ||
+ | t -= btnHeld; | ||
+ | Serial.print(t, DEC); | ||
+ | Serial.println(" ms)"); | ||
+ | |||
+ | btnHeld = 0; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | </syntaxhighlight> | ||
+ | </div> |
Latest revision as of 00:51, 12 June 2014
I have recovered a number of ALPS rotary encoders from discarded industrial CRT monitors. I'm working on building a user interface menu system that makes use of the rotary encoders as the sole input technique.
multiple encoders
Try out http://code.google.com/p/adaencoder/ and PinChangeInt library (http://code.google.com/p/arduino-pinchangeint/) see...
http://arduino.cc/playground/Main/RotaryEncoders#Example14
See if it can cope with two encoders at rapid rate usage.
OK, working well --Michael Erskine 18:10, 29 July 2012 (EST)
When using the Raspberry Pi as the menu display system we need to do a few things to a stock raspbian install...
- auto login and start X: use option in raspi-config
- switch off screen blanking: /etc/lightdm/lightdm.conf in SeatDefaults section "xserver-command=X -s 0 -dpms"
- auto start application
Here I'm building a Perl Tk menu application prototype using Tk::Canvas. I haven't yet wired up the serial as I'm just trying out some graphic styles on the small PAL LCD screen.
OK, using adaencoder on the Pi-arduino bridge! The Arduino is just saying what it sees over serial.