DL1416B
Připojení k Arduinu
Pin DL1416B | Název pinu DL1416B | Pin Arduino |
---|
1 | D5 | A0 |
2 | D4 | A1 |
3 | D0 | A5 |
4 | D1 | A4 |
5 | D2 | A3 |
6 | D3 | A2 |
7 | CE | D11 (for 1st display) |
8 | WR | D4 |
9 | CU | D12 |
10 | A0 | D0 |
11 | A1 | D1 |
12 – 17 | NC | |
18 | V+ | 5V |
19 | V- | GND |
20 | D6 | D13 |
Zdrojový kód pro Arduino
//
// DL1416Test
// Original code from https://forum.arduino.cc/t/hpdl-1414/107676/5
//
enum PinAssignments {
encoderPinA = 2,
encoderPinB = 3,
buttonA = 6,
buttonB = 7,
buttonC = 8,
pinD0 = A5,
pinD1 = A4,
pinD2 = A3,
pinD3 = A2,
pinD4 = A1,
pinD5 = A0,
pinD6 = 13,
pinA0 = 0,
pinA1 = 1,
pinCE1 = 11,
pinCE2 = 5,
pinCE3 = 10,
pinCE4 = 9,
pinWR = 4,
pinCU = 12,
};
char msg[] = " *** DL1416 DEMO *** MORE DISPLAYS ON CTVRTKY.INFO/SBIRKA-DISPLEJU-LED ";
int msgsize = strlen(msg);
byte charset[128] ;
static boolean rotating=false; // debounce management
static int scrolling = 0;
static int editing = 1;
static int status = scrolling; // are we scrolling the message?
boolean A_set = false;
boolean B_set = false;
volatile int charPos = 0; // a counter for the dial
boolean debounce = false;
boolean skip = false;
int ct = 0;
void setup() {
// character set translation table.
charset[' '] = 0b0100000;
charset['!'] = 0b0100001;
charset['"'] = 0b0100010;
charset['#'] = 0b0100011;
charset['$'] = 0b0100100;
charset['%'] = 0b0100101;
charset['&'] = 0b0100110;
charset['\''] = 0b0100111;
charset['('] = 0b0101000;
charset[')'] = 0b0101001;
charset['*'] = 0b0101010;
charset['+'] = 0b0101011;
charset[','] = 0b0101100;
charset['-'] = 0b0101101;
charset['.'] = 0b0101110;
charset['/'] = 0b0101111;
charset['0'] = 0b0110000;
charset['1'] = 0b0110001;
charset['2'] = 0b0110010;
charset['3'] = 0b0110011;
charset['4'] = 0b0110100;
charset['5'] = 0b0110101;
charset['6'] = 0b0110110;
charset['7'] = 0b0110111;
charset['8'] = 0b0111000;
charset['9'] = 0b0111001;
charset[':'] = 0b0111010;
charset[';'] = 0b0111011;
charset['<'] = 0b0111100;
charset['='] = 0b0111101;
charset['>'] = 0b0111110;
charset['?'] = 0b0111111;
charset['@'] = 0b1000000;
charset['A'] = 0b1000001;
charset['B'] = 0b1000010;
charset['C'] = 0b1000011;
charset['D'] = 0b1000100;
charset['E'] = 0b1000101;
charset['F'] = 0b1000110;
charset['G'] = 0b1000111;
charset['H'] = 0b1001000;
charset['I'] = 0b1001001;
charset['J'] = 0b1001010;
charset['K'] = 0b1001011;
charset['L'] = 0b1001100;
charset['M'] = 0b1001101;
charset['N'] = 0b1001110;
charset['O'] = 0b1001111;
charset['P'] = 0b1010000;
charset['Q'] = 0b1010001;
charset['R'] = 0b1010010;
charset['S'] = 0b1010011;
charset['T'] = 0b1010100;
charset['U'] = 0b1010101;
charset['V'] = 0b1010110;
charset['W'] = 0b1010111;
charset['X'] = 0b1011000;
charset['Y'] = 0b1011001;
charset['Z'] = 0b1011010;
charset['['] = 0b1011011;
charset['\\'] = 0b1011100;
charset[']'] = 0b1011101;
charset['^'] = 0b1011110;
charset['_'] = 0b1011111;
charset['a'] = 0b1000001;
charset['b'] = 0b1000010;
charset['c'] = 0b1000011;
charset['d'] = 0b1000100;
charset['e'] = 0b1000101;
charset['f'] = 0b1000110;
charset['g'] = 0b1000111;
charset['h'] = 0b1001000;
charset['i'] = 0b1001001;
charset['j'] = 0b1001010;
charset['k'] = 0b1001011;
charset['l'] = 0b1001100;
charset['m'] = 0b1001101;
charset['n'] = 0b1001110;
charset['o'] = 0b1001111;
charset['p'] = 0b1010000;
charset['q'] = 0b1010001;
charset['r'] = 0b1010010;
charset['s'] = 0b1010011;
charset['t'] = 0b1010100;
charset['u'] = 0b1010101;
charset['v'] = 0b1010110;
charset['w'] = 0b1010111;
charset['x'] = 0b1011000;
charset['y'] = 0b1011001;
charset['z'] = 0b1011010;
pinMode(encoderPinA, INPUT);
pinMode(encoderPinB, INPUT);
pinMode(buttonA, INPUT);
pinMode(buttonB, INPUT);
pinMode(buttonC, INPUT);
// turn on pullup resistors
digitalWrite(encoderPinA, HIGH);
digitalWrite(encoderPinB, HIGH);
pinMode(pinD0, OUTPUT);
pinMode(pinD1, OUTPUT);
pinMode(pinD2, OUTPUT);
pinMode(pinD3, OUTPUT);
pinMode(pinD4, OUTPUT);
pinMode(pinD5, OUTPUT);
pinMode(pinD6, OUTPUT);
pinMode(pinA0, OUTPUT);
pinMode(pinA1, OUTPUT);
pinMode(pinCE1, OUTPUT);
pinMode(pinCE2, OUTPUT);
pinMode(pinCE3, OUTPUT);
pinMode(pinCE4, OUTPUT);
pinMode(pinWR, OUTPUT);
pinMode(pinCU, OUTPUT);
digitalWrite(pinD0, LOW);
digitalWrite(pinD1, LOW);
digitalWrite(pinD2, LOW);
digitalWrite(pinD3, LOW);
digitalWrite(pinD4, LOW);
digitalWrite(pinD5, LOW);
digitalWrite(pinD6, LOW);
digitalWrite(pinA0, LOW);
digitalWrite(pinA1, LOW);
digitalWrite(pinCE1, HIGH);
digitalWrite(pinCE2, HIGH);
digitalWrite(pinCE3, HIGH);
digitalWrite(pinCE4, HIGH);
digitalWrite(pinWR, HIGH);
digitalWrite(pinCU, HIGH);
// encoder pin on interrupt 0 (pin 2)
attachInterrupt(0, doEncoderA, CHANGE);
// encoder pin on interrupt 1 (pin 3)
attachInterrupt(1, doEncoderB, CHANGE);
}
// Main loop
int loop_cnt = 0;
void loop()
{
ct++;
if (!digitalRead(buttonA) && !debounce) // process A button
{
debounce = true;
if (status==scrolling)
status=editing;
else
status=scrolling;
delay(100);
}
if (!digitalRead(buttonC) && status==editing) // process B button
{
debounce = true;
if (msg[charPos] < 'z')
{
int searchIx = msg[charPos];
boolean found=false;
while ((searchIx < 128) && !found)
{
searchIx ++;
if ((charset[searchIx] && 0b01100000) != 0)
{
found = true;
}
}
msg[charPos] = searchIx;
}
delay(100);
}
if (!digitalRead(buttonB) && status==editing) // process C button
{
debounce = true;
if (msg[charPos] > ' ')
{
int searchIx = msg[charPos];
boolean found=false;
while ((searchIx >= 0) && !found)
{
searchIx --;
if ((charset[searchIx] && 0b01100000) != 0)
{
found = true;
}
}
msg[charPos] = searchIx;
}
delay(100);
}
if (digitalRead(buttonA) && digitalRead(buttonB) && digitalRead(buttonC) && debounce) // process A button
{
debounce = false;
}
// scroll message
delay(1);
for (int i=0;i<16;i++)
{
// Set up address
switch (i)
{
case 0:
case 4:
case 8:
case 12:
// select digit 3
digitalWrite(pinA0, HIGH);
digitalWrite(pinA1, HIGH);
break;
case 1:
case 5:
case 9:
case 13:
// select digit 2
digitalWrite(pinA0, LOW);
digitalWrite(pinA1, HIGH);
break;
case 2:
case 6:
case 10:
case 14:
// select digit 1
digitalWrite(pinA0, HIGH);
digitalWrite(pinA1, LOW);
break;
case 3:
case 7:
case 11:
case 15:
// select digit 0
digitalWrite(pinA0, LOW);
digitalWrite(pinA1, LOW);
break;
}
// Write digit
if ((i==0) && (status==editing) && ((ct%8)<4)) // if we are editing, make digit blink by blanking it half the time.
{
digitalWrite(pinD0, HIGH);
digitalWrite(pinD1, HIGH);
digitalWrite(pinD2, HIGH);
digitalWrite(pinD3, HIGH);
digitalWrite(pinD4, HIGH);
digitalWrite(pinD5, LOW);
digitalWrite(pinD6, HIGH);
}
else
{
digitalWrite(pinD0, ((charset[msg[charPos+i]]&1)==1)?HIGH:LOW);
digitalWrite(pinD1, ((charset[msg[charPos+i]]&2)==2)?HIGH:LOW);
digitalWrite(pinD2, ((charset[msg[charPos+i]]&4)==4)?HIGH:LOW);
digitalWrite(pinD3, ((charset[msg[charPos+i]]&8)==8)?HIGH:LOW);
digitalWrite(pinD4, ((charset[msg[charPos+i]]&16)==16)?HIGH:LOW);
digitalWrite(pinD5, ((charset[msg[charPos+i]]&32)==32)?HIGH:LOW);
digitalWrite(pinD6, ((charset[msg[charPos+i]]&64)==64)?HIGH:LOW);
}
delay(1);
// Latch into correct chip and display
int pinCS = 0;
switch (i)
{
case 0:
case 1:
case 2:
case 3:
pinCS = pinCE1;
break;
case 4:
case 5:
case 6:
case 7:
pinCS = pinCE2;
break;
case 8:
case 9:
case 10:
case 11:
pinCS = pinCE3;
break;
case 12:
case 13:
case 14:
case 15:
pinCS = pinCE4;
break;
}
// select chip
digitalWrite(pinCS, LOW);
digitalWrite(pinWR, LOW);
delay(1);
// deselect chip
digitalWrite(pinCS, HIGH);
digitalWrite(pinWR, HIGH);
}
if (status==scrolling)
{
charPos++;
if (charPos>msgsize-16)
charPos = 0;
delay(300);
}
}
// Interrupt on A changing state
void doEncoderA(){
if (status==editing)
{
// debounce
if ( rotating ) delay (1); // wait a little until the bouncing is done
// Test transition, did things really change?
if( digitalRead(encoderPinA) != A_set ) { // debounce once more
A_set = !A_set;
// adjust counter + if A leads B
if ( A_set && !B_set )
{
charPos += 1;
if (charPos>(msgsize-16))
charPos = msgsize-16;
}
rotating = false; // no more debouncing until loop() hits again
}
}
}
// Interrupt on B changing state, same as A above
void doEncoderB(){
if (status==editing)
{
if ( rotating ) delay (1);
if( digitalRead(encoderPinB) != B_set ) {
B_set = !B_set;
// adjust counter - 1 if B leads A
if( B_set && !A_set )
{
skip = false;
charPos -= 1;
if (charPos < 0) charPos = 0;
}
rotating = false;
}
}
}
Demo video