-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDecoderTest.ino
More file actions
52 lines (47 loc) · 1.52 KB
/
DecoderTest.ino
File metadata and controls
52 lines (47 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Decoder TEST v0.21 -- Andrew Micklich -- September 2016
// ------------------------------------------
// SETUP:
// Connect Arduino MEGA digital pins 22-29 to D0-D7 on the HTCL
// Connect digital pin 31 to X/Y
// Connect digital pins 33 and 32 to EN1, EN2 respectively
// Connect digital pin 34 to SEL2
// Connect digital pin 36 to SEL1
// Connect digital pin 35 to RSTX
// Connect digital pin 30 to RSTY
// Connect digital pin 36 to OE
// Connect digital pin 38 to CLK
// Connect 5V Arduino pin to 5V input on optical encoder and V_DD on HTCL
// Connect GND Arduino pin to GND on optical encoder and V_SS on HTCL
// Connect Channel A on encoder to CHA_X on HTCL
// Connect Channel B on encoder to CHB_X on HTCL
// NOTE: Index Channel not yet supported in code
// TEST TEXT
// --------------------------------------------
// Known Bugs:
// None
// --------------------------------------------
// Known Limitations:
// If encoder is turned too rapidly, will not record (Hardware limits? Clock limits?)
// Only 16-bit count currently, eventually can support 32-bit if necessary
#include <Decoder.h>
Decoder decoder;
void setup() {
// put your setup code here, to run once:
decoder.start();
Serial.println("Start");
}
int16_t Result;
int16_t Result_old;
int Result_lo;
int Result_3rd;
void loop() {
digitalWrite(38, HIGH);
Result_lo = decoder.readLSB(0);
Result_3rd = decoder.read3SB(0);
Result = Result_lo + (256*Result_3rd);
if (Result != Result_old) {
Serial.println(Result);
}
digitalWrite(38,LOW);
Result_old = Result;
}