Source Code für Arduino
//
Genuino Uno einstellen
// by Hans-Jörg Faißt 31.01.2016
#include <LedControl.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(8, 9, true); // RX, TX
#define DISP_SEGMENT 0
#define DISP_MATRIX 1
int i=0;
float time=0.0;
char RxByte[10];
bool Debug = false;
int DisplayType = DISP_MATRIX;
/*
* Create a new LedControl.
* We use pins 16,15 and 10 on the Arduino for the SPI
interface
* Pin 16 is connected to the DATA IN-pin of the first MAX7221
* Pin 15 is connected to the CLK-pin of the first MAX7221
* Pin 10 is connected to the LOAD(/CS)-pin of the first
MAX7221
*/
LedControl Disp=LedControl(16,15,10,2);
byte Null[4]={B00000000,B01111111,B01000001,B01111111};
byte Eins[4]={B00000000,B00000000,B01111111,B00000000};
byte Zwei[4]={B00000000,B01111001,B01001001,B01001111};
byte Drei[4]={B00000000,B01001001,B01001001,B01111111};
byte Vier[4]={B00000000,B00001111,B00001000,B01111111};
byte Funf[4]={B00000000,B01001111,B01001001,B01111001};
byte Sech[4]={B00000000,B01111111,B01001001,B01111001};
byte Sieb[4]={B00000000,B00000001,B00000001,B01111111};
byte Acht[4]={B00000000,B01111111,B01001001,B01111111};
byte Neun[4]={B00000000,B01001111,B01001001,B01111111};
void setup()
{
// We start the serial library to output our messages.
if (Debug)
{
Serial.begin(57600);
while (!Serial) ;
Serial.println("Start Test");
Serial.println("Startup StackWatch");
}
/*
The MAX72XX is in power-saving mode on startup,
we have to do a wakeup call
*/
Disp.shutdown(0,false);
Disp.setIntensity(0,4); // brightness medium
Disp.clearDisplay(0);
if (DisplayType == DISP_MATRIX)
{ // second MAX7219
Disp.shutdown(1,false);
Disp.setIntensity(1,4);
Disp.clearDisplay(1);
}
mySerial.begin(1200);
}
void Matrix(int panel, int digit, int value)
{
int row=0;
if (digit==1) row = 4;
else row = 0;
switch (value)
{
case 0:
Disp.setRow(panel,row+0,Null[0]);
Disp.setRow(panel,row+1,Null[1]);
Disp.setRow(panel,row+2,Null[2]);
Disp.setRow(panel,row+3,Null[3]);
break;
case 1:
Disp.setRow(panel,row+0,Eins[0]);
Disp.setRow(panel,row+1,Eins[1]);
Disp.setRow(panel,row+2,Eins[2]);
Disp.setRow(panel,row+3,Eins[3]);
break;
case 2:
Disp.setRow(panel,row+0,Zwei[0]);
Disp.setRow(panel,row+1,Zwei[1]);
Disp.setRow(panel,row+2,Zwei[2]);
Disp.setRow(panel,row+3,Zwei[3]);
break;
break;
case 3:
Disp.setRow(panel,row+0,Drei[0]);
Disp.setRow(panel,row+1,Drei[1]);
Disp.setRow(panel,row+2,Drei[2]);
Disp.setRow(panel,row+3,Drei[3]);
break;
case 4:
Disp.setRow(panel,row+0,Vier[0]);
Disp.setRow(panel,row+1,Vier[1]);
Disp.setRow(panel,row+2,Vier[2]);
Disp.setRow(panel,row+3,Vier[3]);
break;
case 5:
Disp.setRow(panel,row+0,Funf[0]);
Disp.setRow(panel,row+1,Funf[1]);
Disp.setRow(panel,row+2,Funf[2]);
Disp.setRow(panel,row+3,Funf[3]);
break;
case 6:
Disp.setRow(panel,row+0,Sech[0]);
Disp.setRow(panel,row+1,Sech[1]);
Disp.setRow(panel,row+2,Sech[2]);
Disp.setRow(panel,row+3,Sech[3]);
break;
case 7:
Disp.setRow(panel,row+0,Sieb[0]);
Disp.setRow(panel,row+1,Sieb[1]);
Disp.setRow(panel,row+2,Sieb[2]);
Disp.setRow(panel,row+3,Sieb[3]);
break;
case 8:
Disp.setRow(panel,row+0,Acht[0]);
Disp.setRow(panel,row+1,Acht[1]);
Disp.setRow(panel,row+2,Acht[2]);
Disp.setRow(panel,row+3,Acht[3]);
break;
case 9:
Disp.setRow(panel,row+0,Neun[0]);
Disp.setRow(panel,row+1,Neun[1]);
Disp.setRow(panel,row+2,Neun[2]);
Disp.setRow(panel,row+3,Neun[3]);
break;
case -1:
Disp.setRow(panel,row+0,0);
Disp.setRow(panel,row+1,0);
Disp.setRow(panel,row+2,0);
Disp.setRow(panel,row+3,0);
break;
case -2:
Disp.setRow(panel,row+0,0);
Disp.setRow(panel,row+1,B00011000);
Disp.setRow(panel,row+2,B00011000);
Disp.setRow(panel,row+3,0);
break;
}
}
void loop()
{
if (mySerial.available())
{
RxByte[i] = mySerial.read();
if (Debug) Serial.print(RxByte[i]);
if ((RxByte[i] == 13) || (i == 9)) // end
of message
{
i = 0;
if (DisplayType ==
DISP_SEGMENT)
{
if (RxByte[0] ==
'I') Disp.setChar(0,5,' ',false);
if (RxByte[0] ==
'L') Disp.setChar(0,7,'H',false); else Disp.setChar(0,7,' ',false);
if (RxByte[0] ==
'R') Disp.setChar(0,0,'H',false); else Disp.setChar(0,0,' ',false);
if (RxByte[0] ==
'C') Disp.setChar(0,0,'C',false);
if (RxByte[0] ==
'A') Disp.setChar(0,0,'A',false);
if (RxByte[0] == '
') Disp.setChar(0,0,' ',false);
if (RxByte[2] >
48) Disp.setChar(0,5, RxByte[2],false);
if
(isDigit(RxByte[3])) Disp.setChar(0,4,RxByte[3],true);
if
(isDigit(RxByte[4])) Disp.setChar(0,3,RxByte[4],false);
if
(isDigit(RxByte[5])) Disp.setChar(0,2,RxByte[5],false);
}
if (DisplayType == DISP_MATRIX)
{
if (RxByte[0] ==
'I') Matrix(0,0,-1);
if (RxByte[0] ==
'L') Matrix(0,0,-2);
if (RxByte[0] ==
'R') Matrix(0,0,-2);
if (RxByte[0] == '
') Matrix(0,0,-1);
if (RxByte[2] >
48) Matrix(0,0,RxByte[2]-48);
if
(isDigit(RxByte[3])) Matrix(0,1,RxByte[3]-48);
if
(isDigit(RxByte[4])) Matrix(1,0,RxByte[4]-48);
if
(isDigit(RxByte[5])) Matrix(1,1,RxByte[5]-48);
Disp.setRow(1,0,B10000000); // Punkt
}
}
else i++;
}
}
|
|