RoboAide
Project to improve a DIY robotic arm used for mobility assistance
TwoKnobs.ino
Go to the documentation of this file.
1 /* Encoder Library - TwoKnobs Example
2  * http://www.pjrc.com/teensy/td_libs_Encoder.html
3  *
4  * This example code is in the public domain.
5  */
6 
7 #include <Encoder.h>
8 
9 // Change these pin numbers to the pins connected to your encoder.
10 // Best Performance: both pins have interrupt capability
11 // Good Performance: only the first pin has interrupt capability
12 // Low Performance: neither pin has interrupt capability
13 Encoder knobLeft(5, 6);
14 Encoder knobRight(7, 8);
15 // avoid using pins with LEDs attached
16 
17 void setup() {
18  Serial.begin(9600);
19  Serial.println("TwoKnobs Encoder Test:");
20 }
21 
22 long positionLeft = -999;
23 long positionRight = -999;
24 
25 void loop() {
26  long newLeft, newRight;
27  newLeft = knobLeft.read();
28  newRight = knobRight.read();
29  if (newLeft != positionLeft || newRight != positionRight) {
30  Serial.print("Left = ");
31  Serial.print(newLeft);
32  Serial.print(", Right = ");
33  Serial.print(newRight);
34  Serial.println();
35  positionLeft = newLeft;
36  positionRight = newRight;
37  }
38  // if a character is sent from the serial monitor,
39  // reset both back to zero.
40  if (Serial.available()) {
41  Serial.read();
42  Serial.println("Reset both knobs to zero");
43  knobLeft.write(0);
44  knobRight.write(0);
45  }
46 }
void setup()
Definition: TwoKnobs.ino:17
long positionRight
Definition: TwoKnobs.ino:23
void write(int32_t p)
Definition: Encoder.h:127
void loop()
Definition: TwoKnobs.ino:25
Encoder knobRight(7, 8)
Encoder knobLeft(5, 6)
int32_t read()
Definition: Encoder.h:104
long positionLeft
Definition: TwoKnobs.ino:22