RoboAide
Project to improve a DIY robotic arm used for mobility assistance
Main Page
Related Pages
Packages
Classes
Files
File List
File Members
arduino_code
src
main
encoder
examples
TwoKnobs
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
}
setup
void setup()
Definition:
TwoKnobs.ino:17
positionRight
long positionRight
Definition:
TwoKnobs.ino:23
Encoder::write
void write(int32_t p)
Definition:
Encoder.h:127
loop
void loop()
Definition:
TwoKnobs.ino:25
Encoder
Definition:
Encoder.h:69
knobRight
Encoder knobRight(7, 8)
knobLeft
Encoder knobLeft(5, 6)
Encoder::read
int32_t read()
Definition:
Encoder.h:104
positionLeft
long positionLeft
Definition:
TwoKnobs.ino:22
Generated by
1.8.11