further work on 2nd display

This commit is contained in:
Stefan Ostermann 2021-08-22 22:15:19 +02:00
parent ee665ae432
commit 3312649c01
3 changed files with 161 additions and 206 deletions

View File

@ -2,9 +2,8 @@
byte buffer[7]; // "width,height,data[5]" single character buffer.
unsigned char reverse(unsigned char b) {
unsigned char reverse(unsigned char b)
{
b = (b & 0xF0) >> 4 | (b & 0x0F) << 4;
b = (b & 0xCC) >> 2 | (b & 0x33) << 2;
b = (b & 0xAA) >> 1 | (b & 0x55) << 1;
@ -27,3 +26,75 @@ void printChar(char c, LedControl lc)
{
printCharOffset(c, 2, lc);
}
void shiftPrintChar(char c, int delayTime, LedControl lc)
{
for (int i = 0; i < 8; i++)
{
printCharOffset(c, i, lc);
delay(delayTime);
lc.setColumn(0, i, 0);
}
}
void printStringWithShift(char *s, int delayTime, LedControl lc)
{
while (*s != 0)
{
shiftPrintChar(*s, delayTime, lc);
s++;
}
}
void printStringWithWait(char *s, int delayTime, LedControl lc)
{
while (*s != 0)
{
printChar(*s, lc);
delay(delayTime);
lc.clearDisplay(0);
s++;
}
}
void printString(char *s, LedControl lc)
{
int offset = 0;
int display = 0;
while (*s != 0)
{
if (*s < 32)
return;
*s -= 32;
memcpy_P(buffer, CH + 7 * *s, 7);
for (int i = 0; i <= buffer[0]; i++)
{
if (i+offset>7) {
offset = offset-8;
display++;
}
lc.setRow(display, i + offset, reverse(buffer[i + 2]));
}
offset+=buffer[0];
offset++;
s++;
}
}
void fadeOut(int max, int time, LedControl lc)
{
for (int i = 0; i < max; i++)
{
lc.setIntensity(0, max - i);
delay(time / max);
}
}
void fadeIn(int max, int time, LedControl lc)
{
for (int i = 0; i < max; i++)
{
lc.setIntensity(0, i);
delay(time / max);
}
}

View File

@ -4,7 +4,22 @@
#include <avr/pgmspace.h>
#include "LedControl.h"
void printCharOffset(char c, int offset, LedControl lc);
void printChar(char c,LedControl lc);
void shiftPrintChar(char c, int delayTime, LedControl lc);
void printStringWithShift(char* s, int delayTime, LedControl lc);
void printStringWithWait(char* s, int delayTime, LedControl lc);
void printString(char* s, LedControl lc);
void fadeOut(int max, int time, LedControl lc);
void fadeIn(int max, int time, LedControl lc);
// Data array is stored in program memory (see memcpy_P for access).
// Parameters are width, height, character data...
@ -38,8 +53,8 @@ PROGMEM const unsigned char CH[] = {
4, 8, B1100001, B0010001, B0001001, B0000111, B0000000, // 7
4, 8, B0110110, B1001001, B1001001, B0110110, B0000000, // 8
4, 8, B0000110, B1001001, B1001001, B0111110, B0000000, // 9
2, 8, B01010000, B0000000, B0000000, B0000000, B0000000, // :
2, 8, B10000000, B01010000, B0000000, B0000000, B0000000, // ;
1, 8, B01010000, B0000000, B0000000, B0000000, B0000000, // :
1, 8, B10000000, B01010000, B0000000, B0000000, B0000000, // ;
3, 8, B0010000, B0101000, B1000100, B0000000, B0000000, // <
3, 8, B0010100, B0010100, B0010100, B0000000, B0000000, // =
3, 8, B1000100, B0101000, B0010000, B0000000, B0000000, // >
@ -109,8 +124,6 @@ PROGMEM const unsigned char CH[] = {
4, 8, B0001000, B0000100, B0001000, B0000100, B0000000, // ~
};
void printCharOffset(char c, int offset, LedControl lc);
void printChar(char c,LedControl lc);
#endif

View File

@ -28,12 +28,8 @@ We have only a single MAX72XX.
*/
int iteration = 0;
// initialize RTC library
RTC_DS1307 rtc;
DateTime now;
@ -45,14 +41,12 @@ DateTime now;
#define OLED_RESET D8 - 1 // Reset pin # (or -1 if sharing Arduino reset pin)
//Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// Max7219 PINs:
#define MAX_CLK D5
#define MAX_CS D6
#define MAX_DIN D7
LedControl lc = LedControl(MAX_DIN, MAX_CLK, MAX_CS, 1);
LedControl lc = LedControl(MAX_DIN, MAX_CLK, MAX_CS, 2);
/* we always wait a bit between updates of the display */
@ -97,6 +91,7 @@ Serial.begin(115200);
/* The MAX72XX is in power-saving mode on startup, we have to do a wakeup call */
lc.shutdown(0, false);
lc.shutdown(1, false);
int devices = lc.getDeviceCount();
Serial.print("devices: ");
@ -108,27 +103,29 @@ Serial.begin(115200);
lc.clearDisplay(0);
lc.setIntensity(1, 15);
lc.clearDisplay(1);
for (int i=0;i<8;i++) {
lc.setDigit(1,i,8,true);
}
/* and clear the display */
Serial.println("starting");
delay(3000); // wait for console opening
//rtc.begin();
if (! rtc.begin()) {
if (!rtc.begin())
{
Serial.println("Couldn't find RTC");
//while (1);
return;
}
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
void configModeCallback(WiFiManager *myWiFiManager)
@ -139,8 +136,8 @@ void configModeCallback(WiFiManager *myWiFiManager)
Serial.println(myWiFiManager->getConfigPortalSSID());
}
void printNumber(int v) {
void printNumber(int v)
{
int ones;
int tens;
int hundreds;
@ -148,7 +145,8 @@ void printNumber(int v) {
if (v < -999 || v > 999)
return;
if(v<0) {
if (v < 0)
{
negative = true;
v = v * -1;
}
@ -157,11 +155,13 @@ void printNumber(int v) {
tens = v % 10;
v = v / 10;
hundreds = v;
if(negative) {
if (negative)
{
//print character '-' in the leftmost column
lc.setChar(0, 3, '-', false);
}
else {
else
{
//print a blank in the sign column
lc.setChar(0, 3, ' ', false);
}
@ -171,121 +171,6 @@ void printNumber(int v) {
lc.setDigit(0, 0, (byte)ones, false);
}
/*
x and y swapped
*/
void setColumn(LedControl lc,int addr, int col, byte value) {
byte val;
if(col<0 || col>7)
return;
for(int row=7;row>=0;row--) {
val=value >> (7-row);
val=val & 0x01;
lc.setLed(addr,col,row,val);
}
}
//int two[] = {0,130,193,161,145,137,135,0};
int two[] = {65,131,133,137,145,97};
void drawChar(int arr[],int size,int offset) {
lc.clearDisplay(0);
for (int i=0;i<size;i++) {
//lc.setColumn(0,i,two[i]);
setColumn(lc,0,i+offset,arr[i]);
}
/*
lc.setLed(0,2,0,true);
lc.setLed(0,3,0,true);
lc.setLed(0,4,0,true);
lc.setLed(0,5,0,true);
lc.setLed(0,1,1,true);
lc.setLed(0,6,1,true);
lc.setLed(0,6,2,true);
lc.setLed(0,5,3,true);
lc.setLed(0,4,4,true);
lc.setLed(0,3,5,true);
lc.setLed(0,2,6,true);
lc.setLed(0,1,7,true);
lc.setLed(0,2,7,true);
lc.setLed(0,3,7,true);
lc.setLed(0,4,7,true);
lc.setLed(0,5,7,true);
lc.setLed(0,6,7,true);
*/
}
void writeArduinoOnMatrix() {
/* here is the data for the characters */
byte a[5]={B01111110,B10001000,B10001000,B10001000,B01111110};
byte r[5] ={B00111110,B00010000,B00100000,B00100000,B00010000};
byte d[5]={B00011100,B00100010,B00100010,B00010010,B11111110};
byte u[5]={B00111100,B00000010,B00000010,B00000100,B00111110};
byte i[5]={B00000000,B00100010,B10111110,B00000010,B00000000};
byte n[5]={B00111110,B00010000,B00100000,B00100000,B00011110};
byte o[5]={B00011100,B00100010,B00100010,B00100010,B00011100};
/* now display them one by one with a small delay */
lc.setRow(0,0,a[0]);
lc.setRow(0,1,a[1]);
lc.setRow(0,2,a[2]);
lc.setRow(0,3,a[3]);
lc.setRow(0,4,a[4]);
delay(delaytime);
lc.setRow(0,0,r[0]);
lc.setRow(0,1,r[1]);
lc.setRow(0,2,r[2]);
lc.setRow(0,3,r[3]);
lc.setRow(0,4,r[4]);
delay(delaytime);
lc.setRow(0,0,d[0]);
lc.setRow(0,1,d[1]);
lc.setRow(0,2,d[2]);
lc.setRow(0,3,d[3]);
lc.setRow(0,4,d[4]);
delay(delaytime);
lc.setRow(0,0,u[0]);
lc.setRow(0,1,u[1]);
lc.setRow(0,2,u[2]);
lc.setRow(0,3,u[3]);
lc.setRow(0,4,u[4]);
delay(delaytime);
lc.setRow(0,0,i[0]);
lc.setRow(0,1,i[1]);
lc.setRow(0,2,i[2]);
lc.setRow(0,3,i[3]);
lc.setRow(0,4,i[4]);
delay(delaytime);
lc.setRow(0,0,n[0]);
lc.setRow(0,1,n[1]);
lc.setRow(0,2,n[2]);
lc.setRow(0,3,n[3]);
lc.setRow(0,4,n[4]);
delay(delaytime);
lc.setRow(0,0,o[0]);
lc.setRow(0,1,o[1]);
lc.setRow(0,2,o[2]);
lc.setRow(0,3,o[3]);
lc.setRow(0,4,o[4]);
delay(delaytime);
lc.setRow(0,0,0);
lc.setRow(0,1,0);
lc.setRow(0,2,0);
lc.setRow(0,3,0);
lc.setRow(0,4,0);
delay(delaytime);
}
void loop()
{
@ -305,26 +190,15 @@ DateTime now = rtc.now();
Serial.print(now.second(), DEC);
Serial.println();
Serial.println();
//printStringWithShift("TEST", 150, lc);
lc.setIntensity(0, 15);
//lc.setDigit(0,3,now.hour()/10,false);
//lc.setDigit(0,2,now.hour()%10,false);
//lc.setDigit(0,1,now.minute()/10,false);
//lc.setDigit(0,0,now.minute()%10,false);
char str[24];
sprintf(str, "%02d%02d", now.hour(), now.minute());
printString(str, lc);
delay(800);
/*
for (int i=0;i<8;i++) {
for (int j=0;j<8;j++) {
lc.clearDisplay(0);
//lc.setDigit(i,j,now.second()%10,true);
//lc.setLed(i,j,0,false);
lc.setLed(0,j,i,true);
delay(100);
}
}*/
//drawChar(two,6,1);
//writeArduinoOnMatrix();
int dl = 500;
printChar('1',lc);
delay(dl);
@ -346,7 +220,7 @@ DateTime now = rtc.now();
delay(dl);
printChar('0',lc);
delay(dl);
*/
/*
lc.setDigit(0,0,3,false);
lc.setDigit(0,1,2,false);
@ -354,7 +228,4 @@ DateTime now = rtc.now();
lc.setDigit(0,3,0,false);
*/
//delay(1000);
}