-
Notifications
You must be signed in to change notification settings - Fork 1
/
display.cpp
48 lines (39 loc) · 954 Bytes
/
display.cpp
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
#include "display.h"
#include <Adafruit_RGBLCDShield.h>
static const char *menu_items[] = {
"duty-cycle ",
"frequency ",
"intensity "
};
extern Adafruit_RGBLCDShield lcd;
void display_menu(uint8_t num)
{
lcd.setCursor(0,1);
lcd.print(menu_items[num]);
}
void display_value(uint8_t x, uint8_t width, const char *str)
{
lcd.setCursor(x,1);
lcd.print(str);
for(int i=0; i<width-(uint8_t)String(str).length(); i++)
lcd.print(" ");
}
void display_intensity(uint8_t intensity, uint8_t width)
{
String str(intensity);
display_value(10, width, str.c_str());
}
void display_frequency(float freq, uint8_t width)
{
String decimal = String(int(freq*100.) % 100);
String str(String(int(freq)) + (decimal.length()==1?".0":".") + decimal);
display_value(10, width, str.c_str());
}
void display_dutycycle(uint8_t delay, uint8_t width)
{
display_value(11, width,
delay==1?"100%":
delay==2?"50%":
delay==3?"33%":
"25%");
}