-
Notifications
You must be signed in to change notification settings - Fork 0
/
OsRAM_Arduino.ino
287 lines (230 loc) · 5.42 KB
/
OsRAM_Arduino.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
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
/*************************************
OsRAM
Controls the IPD2131 intelligent display
Heartbeat LED on pin 13.
Arduino documentation at http://www.arduino.cc
This example code is in the public domain.
modified November 3, 2015
by Rob Lund
***************************************/
//-------------
// definitions
//-------------
#define LEDFADER 13
#define MAX_ADDR_PINS 5
#define MAX_DATA_PINS 8
#define EXTRA_DEBUG false
//-------------
// globals
//-------------
const byte DATA_PINS[MAX_DATA_PINS] =
{
46, // D0
48, // D1
50, // D2
52, // D3
53, // D4
51, // D5
49, // D6
47, // D7
};
const byte ADDR_PINS[MAX_ADDR_PINS] =
{
31, // A0
29, // A1
27, // A2
25, // A3
23, // A4
};
const byte WR = 22;
const byte CE = 24;
const byte RST = 26;
const byte RD = 28;
const byte FL = 30;
// incoming serial byte
byte inByte = 0;
// address counter (must only use A0-A2)
#define BASE_ADDRESS 0b11111000
byte address;
#define CHAR_DELAY 5
String inputString = ""; // a string to hold incoming data
char inChar = 0;
boolean stringComplete = false; // whether the string is complete
int buttonState = 0; // variable for reading the pushbutton status
const int buttonPin = 35; // the number of the pushbutton pin
int bootupOption = false; // variable for running mode
// the setup function runs once when you press reset or power the board
void setup()
{
//Initialize serial and wait for port to open:
Serial.begin(9600);
// reserve 200 bytes for the inputString:
inputString.reserve(200);
// wait for serial port to connect. Needed for native USB port only
while (!Serial);
// button
pinMode(buttonPin, INPUT);
// prints title with ending line break
Serial.println(">>>>>>>> OsRAM intelligent LED display <<<<<<<<");
// setup the display buses
BusConfig();
// clear all characters
ResetDisplay();
// disable flashing
digitalWrite(FL, HIGH);
// bootup options
if (bootupOption = digitalRead(buttonPin))
{
Serial.println("\nboot mode #2, console mode");
// trap for closed switch
Serial.println("please release switch now!");
while (!digitalRead(buttonPin));
}
else
{
Serial.println("\nboot mode #1, normal mode");
}
}
// the loop function runs over and over again forever
void loop()
{
if (bootupOption == true)
{
StringWrite(" Z X Y W");
delay(1200);
//ResetDisplay();
StringWrite("abcdefgh");
delay(1200);
//ResetDisplay();
StringWrite("12345678");
delay(1200);
//ResetDisplay();
}
else
{
// look for console input
while (Serial.available())
{
// get the new byte:
inChar = (char)Serial.read();
// if the incoming character is a newline, set a flag
// so the main loop can do something about it:
if (inChar == '\n')
{
stringComplete = true;
}
// don't add newlines
else
{
// add characters to string
inputString += inChar;
}
}
// now print the string when ready
if (stringComplete)
{
// send to display
StringWrite(inputString);
// echo
Serial.println(inputString);
// clear the string:
inputString = "";
stringComplete = false;
}
}
}
// --------------------------
// bus port config
// --------------------------
void BusConfig(void)
{
int i;
for (i = 0; i < MAX_ADDR_PINS; i++)
{
pinMode(ADDR_PINS[i], OUTPUT);
}
for (i = 0; i < MAX_DATA_PINS; i++)
{
pinMode(DATA_PINS[i], OUTPUT);
}
pinMode(FL, OUTPUT);
pinMode(RST, OUTPUT);
pinMode(WR, OUTPUT);
pinMode(CE, OUTPUT);
pinMode(RD, OUTPUT);
}
/* ------------------------
data bus write function
input is a hex byte that
must be written 1 bit at at time
------------------------*/
void DataBusWrite(byte data)
{
// chip setup
digitalWrite(CE, 0);
delay(10);
digitalWrite(WR, 0);
for (int i = 0; i < MAX_DATA_PINS; i++)
{
// write the bus
digitalWrite(DATA_PINS[i], bitRead(data, i));
}
// chip disable
digitalWrite(WR, 1);
delay(10);
digitalWrite(CE, 1);
}
/* ------------------------
address bus write function
input is a hex byte that
must be written 1 bit at at time
------------------------*/
void AddressBusWrite(byte address)
{
for (int i = 0; i < MAX_ADDR_PINS; i++)
{
// write the bus
digitalWrite(ADDR_PINS[i], bitRead(address, i));
}
}
/*------------------------
string write function
input is an ASCII string that
must be written 1 character at a time
------------------------*/
void StringWrite(String message)
{
byte address = BASE_ADDRESS;
// first clear all characters
ResetDisplay();
#if EXTRA_DEBUG
Serial.println("\nstring length = ");
Serial.print(message.length());
#endif
for (int i = 0; i < message.length(); i++, address++)
{
#if EXTRA_DEBUG
Serial.println("\ncharacter = ");
Serial.print(message.charAt(i));
#endif
// set up the display character
AddressBusWrite(address);
// setup delay?
delay(CHAR_DELAY);
// write the string character to that display character
DataBusWrite(message.charAt(i));
delay(CHAR_DELAY);
}
}
/*------------------------
display reset function
clears all characters and blink
formats
------------------------*/
void ResetDisplay(void)
{
digitalWrite(RST, LOW);
delay(CHAR_DELAY);
digitalWrite(RST, HIGH);
delay(CHAR_DELAY);
}