-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDisplay.cpp
89 lines (74 loc) · 1.5 KB
/
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
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
#include <LiquidCrystal.h>
#include "Display.h"
#define GREEN_PIN 6
#define RED_PIN 7
LiquidCrystal lcd(5, 8, 9, 10, 11, 12); //RS, Enable, d0, d1, d2, d3
#include "Arduino.h"
#define BLINK_DELAY 100
int redTime = 0;
int greenTime = 0;
void DisplaySetup()
{
//Setup LCD
lcd.begin(16, 2);
lcd.home();
//Setup LEDs
pinMode(GREEN_PIN, OUTPUT);
pinMode(RED_PIN, OUTPUT);
digitalWrite(GREEN_PIN, HIGH);
digitalWrite(RED_PIN, HIGH);
DisplayBlinkRed();
DisplayBlinkGreen();
}
void DisplayUpdate()
{
int t = millis();
if (redTime && (t - redTime > BLINK_DELAY))
{
redTime = 0;
digitalWrite(RED_PIN, HIGH);
}
if (greenTime && (t - greenTime > BLINK_DELAY))
{
greenTime = 0;
digitalWrite(GREEN_PIN, HIGH);
}
}
void DisplayBlinkRed()
{
redTime = millis();
digitalWrite(RED_PIN, LOW);
}
void DisplayBlinkGreen()
{
greenTime = millis();
digitalWrite(GREEN_PIN, LOW);
}
void DisplayClear()
{
lcd.clear();
}
void DisplayWriteStr(const char * str, byte line, byte col)
{
lcd.home();
//lcd.setCursor(line, col); //Row / col
lcd.setCursor(col, line); //Row / col
lcd.print(str);
}
void DisplayWriteInt(int val, byte line, byte col)
{
lcd.home();
//lcd.setCursor(line, col); //Row / col
lcd.setCursor(col, line); //Row / col
lcd.print(val);
}
void DisplayCreateChar(byte array[8], byte id)
{
lcd.createChar(id, array);
}
void DisplayWriteChar(byte id, byte line, byte col)
{
lcd.home();
lcd.setCursor(col, line); //Row / col
lcd.write(id);
}