forked from CedarvilleAsee/Hurricane-Rescue
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPT6961.cpp
More file actions
167 lines (143 loc) · 3.53 KB
/
PT6961.cpp
File metadata and controls
167 lines (143 loc) · 3.53 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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
PT6961.cpp - Library for communicating with PT6961 LED driver.
Created by Garrett Blanton January, 16, 2013.
Released into the public domain.
*/
#include "constants.h"
//0 - A
//1 - B
//2 - C
//3 - D
//4 - E
//5 - F
//6 - G
//7 - Colon
#include "Arduino.h"
#include "PT6961.h"
PT6961::PT6961(int DIN, int CLK, int CS)
{
pinMode(DIN, OUTPUT);
pinMode(CLK, OUTPUT);
pinMode(CS, OUTPUT);
_DIN = DIN;
_CLK = CLK;
_CS = CS;
}
void PT6961::initDisplay()
{
sendCmd(_DISPLAY_6X12);
sendCmd(_AUTO_INCREMENT);
initRAM();
sendCmd(_DISPLAY_14_16);
}
// Initializes RAM to all zeros
void PT6961::initRAM()
{
//first clear 8 bytes of the display RAM
digitalWrite(_CS,LOW);
shiftOut(_DIN, _CLK, LSBFIRST, 0xC0);
for(int i=0; i<8; i++){
shiftOut(_DIN, _CLK, LSBFIRST, 0x00);
}
digitalWrite(_CS,HIGH);
}
// Use to send command based on enumeration
void PT6961::sendCmd(char cmd)
{
digitalWrite(_CS,LOW);
shiftOut(_DIN, _CLK, LSBFIRST, cmd);
digitalWrite(_CS,HIGH);
}
void PT6961::sendDigit(char digit, char val)
{
digitalWrite(_CS,LOW);
shiftOut(_DIN, _CLK, LSBFIRST, digit);
shiftOut(_DIN, _CLK, LSBFIRST, val);
digitalWrite(_CS,HIGH);
}
void PT6961::sendNum(int num, char colon)
{
int digit1 = num / 1000;
int digit2 = (num % 1000) / 100;
int digit3 = (num % 100) / 10;
int digit4 = (num % 10);
sendDigits(digit1,digit2,digit3,digit4,colon);
}
void PT6961::sendDigits(char digit1, char digit2, char digit3, char digit4, char colon)
{
const char DISP[17] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x77, 0x7c, 0x58, 0x5e, 0x79, 0x71, 0x61};
digitalWrite(_CS,LOW);
shiftOut(_DIN, _CLK, LSBFIRST, 0xC0);
if(colon == 1)
{
shiftOut(_DIN, _CLK, LSBFIRST, DISP[digit1] | 0x80);
}
else
{
shiftOut(_DIN, _CLK, LSBFIRST, DISP[digit1]);
}
shiftOut(_DIN, _CLK, LSBFIRST, 0xC2);
if(colon == 1)
{
shiftOut(_DIN, _CLK, LSBFIRST, DISP[digit2] | 0x80);
}
else
{
shiftOut(_DIN, _CLK, LSBFIRST, DISP[digit2]);
}
shiftOut(_DIN, _CLK, LSBFIRST, 0xC4);
shiftOut(_DIN, _CLK, LSBFIRST, DISP[digit3]);
shiftOut(_DIN, _CLK, LSBFIRST, 0xC6);
shiftOut(_DIN, _CLK, LSBFIRST, DISP[digit4]);
digitalWrite(_CS,HIGH);
}
void PT6961::sendMessage(int message)
{
char lineDisp[4];
if(message == PICKUP_RIGHT) {
lineDisp[0] = 0x73; //P
lineDisp[1] = 0x00;
lineDisp[2] = 0x00;
lineDisp[3] = 0x50; //r
}
else if(message == PICKUP_LEFT) {
lineDisp[0] = 0x73; //P
lineDisp[1] = 0x00;
lineDisp[2] = 0x00;
lineDisp[3] = 0x38; //L
}
else if(message == PICKUP_EMPTY) {
lineDisp[0] = 0x73; //P
lineDisp[1] = 0x00;
lineDisp[2] = 0x00;
lineDisp[3] = 0x79; //E
}
else if(message == DEPOSITING) {
lineDisp[0] = 0x5E; //D
lineDisp[1] = 0x79; //E
lineDisp[2] = 0x73; //P
lineDisp[3] = 0x3F; //O
}
else if(message == DONE) {
lineDisp[0] = 0x5E; //D
lineDisp[1] = 0x3F; //O
lineDisp[2] = 0x54; //n
lineDisp[3] = 0x79; //E
}
else if(message == RACQUETBALL) {
lineDisp[0] = 0x7C; //b
lineDisp[1] = 0x77; //A
lineDisp[2] = 0x38; //L
lineDisp[3] = 0x38; //L
}
digitalWrite(_CS,LOW);
shiftOut(_DIN, _CLK, LSBFIRST, 0xC0);
shiftOut(_DIN, _CLK, LSBFIRST, lineDisp[0]);
shiftOut(_DIN, _CLK, LSBFIRST, 0xC2);
shiftOut(_DIN, _CLK, LSBFIRST, lineDisp[1]);
shiftOut(_DIN, _CLK, LSBFIRST, 0xC4);
shiftOut(_DIN, _CLK, LSBFIRST, lineDisp[2]);
shiftOut(_DIN, _CLK, LSBFIRST, 0xC6);
shiftOut(_DIN, _CLK, LSBFIRST, lineDisp[3]);
digitalWrite(_CS,HIGH);
}