forked from LesMargoulins/Margoulineur2000
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrotary_encoder.ino
76 lines (72 loc) · 1.82 KB
/
rotary_encoder.ino
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# include "margoulinade.h"
void encoderMenu()
{
int newPosition = myEnc.read();
if ((newPosition != oldPosition) )
{
oldPosition = newPosition;
if(oldPosition > (MENUELEMENTS * ENCODERSTEPS) - 1)
{
myEnc.write(0);
}
else if(oldPosition < 0)
{
myEnc.write(MENUELEMENTS * ENCODERSTEPS - 1);
}
Serial.println(newPosition / ENCODERSTEPS);
cycleMenu = (abs(newPosition) / ENCODERSTEPS) / MENUELEMENTS;
lcd.clear();
}
}
int encoderWrite()
{
int newPosition;
myEnc.write(0);
Serial.print(F("jeej"));
lcd.print(F("Loading..."));
delay(500);
oldPosition = -1;
while(digitalRead(encButton))
{
newPosition = myEnc.read();
if ((newPosition != oldPosition) )
{
if (newPosition < VALMIN * ENCODERSTEPS)
{
myEnc.write(VALMIN * ENCODERSTEPS);
newPosition = 0;
}
else if (newPosition > VALMAX * ENCODERSTEPS)
{
myEnc.write(VALMAX * ENCODERSTEPS);
newPosition = 40;
}
else
{
lcd.clear();
lcd.print(F("New balance :"));
lcd.setCursor(0,1);
lcd.print(newPosition / ENCODERSTEPS);
oldPosition = newPosition;
Serial.println(newPosition / ENCODERSTEPS);
}
}
}
myEnc.write(0);
oldPosition = -1;
return (newPosition / ENCODERSTEPS);
}
void wait4button()
{
Serial.println(F("\n\nDONE ! waiting 4 the button"));
digitalWrite(readLedPin, LOW);
digitalWrite(writeLedPin, LOW);
if (OPTIMIZATION_MODE)
delay(500);
while(digitalRead(encButton))
{
}
delay(500);
Serial.print(F("end read = "));Serial.println(oldPosition);
lcd.clear();
}