-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper_functions.ino
118 lines (109 loc) · 2.27 KB
/
helper_functions.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
void updateDisplay(int totalSeconds, int temperature)
{
char buffer[32];
sprintf(buffer, "%02d:%02d Temp: %02dC", int(totalSeconds / 60), int(totalSeconds % 60), temperature);
lcd.setCursor(0,1);
lcd.print(buffer);
}
byte wait(char line1[16], char line2[16])
{
byte button=0;
drawDisplay(line1, line2);
while(!button)
button = lcd.readButtons();
lcd.clear();
delay(250);
return button;
}
void drawDisplay(char line1[16], char line2[16])
{
lcd.clear();
lcd.print(line1);
lcd.setCursor(0,1);
lcd.print(line2);
}
double collectTemperatures()
{
sensors.requestTemperatures();
if(sensors.getAddress(thermometer, 0))
{
return double(sensors.getTempC(thermometer));
}
return -255;
}
void runMotor()
{
byte rpm = MOTOR_RPM;
byte directionInterval = 5;
bool runMotor = true;
char buffer[32];
byte button=0;
sprintf(buffer, "RPM %02d : I %02d", rpm, directionInterval);
drawDisplay("Turning Rotary", buffer);
while(true)
{
if(runMotor)
controlMotor(toSpeed(rpm), directionInterval);
else
controlMotor(0, 0);
button = lcd.readButtons();
if(button)
{
Serial.println("In button if");
switch(button)
{
case BUTTON_UP:
{
if(rpm < MOTOR_RPM)
++rpm;
button = 0;
break;
}
case BUTTON_DOWN:
{
if(rpm > MOTOR_MIN_RPM)
--rpm;
button = 0;
break;
}
case BUTTON_LEFT:
{
if(directionInterval > 1)
--directionInterval;
button = 0;
break;
}
case BUTTON_RIGHT:
{
if(directionInterval < 255)
++directionInterval;
button = 0;
break;
}
case BUTTON_SELECT:
{
if(runMotor)
{
drawDisplay("Turning Rotary", "Paused");
runMotor = false;
}
else
runMotor = true;
}
}
if(runMotor)
{
sprintf(buffer, "RPM %02d : I %02d", rpm, directionInterval);
drawDisplay("Running Motor", buffer);
}
}
}
}
int toRPM(byte value)
{
return map(value, 0, 255, 0, MOTOR_RPM);
}
int toSpeed(byte value)
{
return map(value, 0, MOTOR_RPM, 0, 255);
}