-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLEDCeilingRotaryEncoderFinal.ino
More file actions
62 lines (51 loc) · 1.34 KB
/
Copy pathLEDCeilingRotaryEncoderFinal.ino
File metadata and controls
62 lines (51 loc) · 1.34 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
53
54
55
56
57
58
59
60
61
62
/* Encoder Library - Basic Example
* http://www.pjrc.com/teensy/td_libs_Encoder.html
*
* This example code is in the public domain.
*/
#include <Encoder.h>
// Change these two numbers to the pins connected to your encoder.
// Best Performance: both pins have interrupt capability
// Good Performance: only the first pin has interrupt capability
// Low Performance: neither pin has interrupt capability
Encoder myEnc(2, 3);
const int encButton = 7;
// avoid using pins with LEDs attached
void setup() {
Serial.begin(9600);
pinMode(encButton, INPUT_PULLUP);
}
long oldPosition = 0;
int effect_id = 0;
void loop() {
long newPosition = myEnc.read();
if (newPosition < 0){ //set the effect_id down limit to 0
oldPosition = 0;
newPosition = 0;
myEnc.write(0);
}
if (newPosition > 234){ //set the effect_id upper limit to 117 (234/2)
oldPosition = 234;
newPosition = 234;
myEnc.write(234);
}
if (newPosition != oldPosition) {
oldPosition = newPosition;
//Serial.println(newPosition);
}
if (newPosition < 0){
effect_id = 0;
}
if (newPosition > 0){
effect_id = newPosition;
}
if (digitalRead(encButton) == 0){
oldPosition = 0;
newPosition = 0;
myEnc.write(0);
effect_id = newPosition;
}
Serial.print("effect_id: ");
Serial.println(effect_id/2);
delay(100);
}