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
NoInterrupts
NoInterrupts.ino
Go to the documentation of this file.
1
/* Encoder Library - NoInterrupts Example
2
* http://www.pjrc.com/teensy/td_libs_Encoder.html
3
*
4
* This example code is in the public domain.
5
*/
6
7
// If you define ENCODER_DO_NOT_USE_INTERRUPTS *before* including
8
// Encoder, the library will never use interrupts. This is mainly
9
// useful to reduce the size of the library when you are using it
10
// with pins that do not support interrupts. Without interrupts,
11
// your program must call the read() function rapidly, or risk
12
// missing changes in position.
13
#define ENCODER_DO_NOT_USE_INTERRUPTS
14
#include <Encoder.h>
15
16
// Beware of Serial.print() speed. Without interrupts, if you
17
// transmit too much data with Serial.print() it can slow your
18
// reading from Encoder. Arduino 1.0 has improved transmit code.
19
// Using the fastest baud rate also helps. Teensy has USB packet
20
// buffering. But all boards can experience problems if you print
21
// too much and fill up buffers.
22
23
// Change these two numbers to the pins connected to your encoder.
24
// With ENCODER_DO_NOT_USE_INTERRUPTS, no interrupts are ever
25
// used, even if the pin has interrupt capability
26
Encoder
myEnc
(5, 6);
27
// avoid using pins with LEDs attached
28
29
void
setup
() {
30
Serial.begin(9600);
31
Serial.println(
"Basic NoInterrupts Test:"
);
32
}
33
34
long
position
= -999;
35
36
void
loop
() {
37
long
newPos =
myEnc
.
read
();
38
if
(newPos !=
position
) {
39
position
= newPos;
40
Serial.println(
position
);
41
}
42
// With any substantial delay added, Encoder can only track
43
// very slow motion. You may uncomment this line to see
44
// how badly a delay affects your encoder.
45
//delay(50);
46
}
myEnc
Encoder myEnc(5, 6)
setup
void setup()
Definition:
NoInterrupts.ino:29
Encoder
Definition:
Encoder.h:69
position
long position
Definition:
NoInterrupts.ino:34
loop
void loop()
Definition:
NoInterrupts.ino:36
Encoder::read
int32_t read()
Definition:
Encoder.h:104
Generated by
1.8.11