Volgorde Arduino LED matrixklok nu juist.., (Computertechniek)
door alle vier de 8x8 matrix modules uit hun voetje te lichten en apart op een print te solderen en te bedraden. Zo zijn ze makkelijk in de juiste volgorde te zetten en staat er bijvoorbeeld geen 537:1 maar 17:35
De klok blijkt helemaal geen aparte bibliotheek te hebben op de Arduino MEGA 2560 als ik de sketch hieronder bekijk. De enige bibliotheek is de #include "LedControl.h"
Ik kom er niet uit hoe de volgorde van de vier 8x8 LED modules worden aangestuurd, wellicht heeft iemand een tip.
Ik experimenteer overigens ook in de void loop()met de delay(970) want moet dat getal verlagen omdat de klok te langzaam loopt. Ik heb in de void loop() van 970 nu 925 gemaakt en klok loopt nu beter (sneller)
Hieronder de sketch.
#include "LedControl.h"
LedControl lc=LedControl(2,3,4,4);
//----Time Var----------
int TimeHours10s = 0;
int TimeHours1s = 0;
int TimeMinutes10s = 0;
int TimeMinutes1s = 0;
int TimeSeconds10s = 0;
int TimeSeconds1s = 0;
//----------------------
//---Input Pins for setting Time--
int TimeSet = 7;
int Min = 8;
int Hour = 9;
int Buzzer =10;
//---------------------------------
void setup()
{
// initialize I/O pins----------------------------
pinMode(TimeSet, INPUT_PULLUP); //Bit_7
pinMode(Hour, INPUT_PULLUP); //Bit_8
pinMode(Min, INPUT_PULLUP); //Bit_9
pinMode(Buzzer, OUTPUT); //Bit_10
//-----------------------------------------------
lc.shutdown(0,false);
lc.shutdown(1,false);
lc.shutdown(2,false);
lc.shutdown(3,false);
//set a medium brightness for the Leds
lc.setIntensity(0,2);
lc.setIntensity(1,2);
lc.setIntensity(2,2);
lc.setIntensity(3,2);
}
void loop()
{
CalculateTime();
ShowTime();
delay(925); // origineel: delay(970);
//-------------------------------------Adj Time Value--------------
if(digitalRead(TimeSet)== LOW && digitalRead(Min)== LOW)
{
TimeMinutes1s++;
//delay(500);
CalculateTime();
}
if(digitalRead(TimeSet)== LOW && digitalRead(Hour)== LOW)
{
TimeHours1s++;
//delay(500);
CalculateTime();
}
//------------------------------------------------------------------
}
void SendDataDotMatrix(int DispNumber,int Digit)
{
int dp;
if(Digit == 1)
{
if(DispNumber == 2)//
dp = 0x01;
else
dp = 0x00;
//-----------------Show 1----------------------
lc.setRow(DispNumber,0,0x18 );
lc.setRow(DispNumber,1,0x38 );
lc.setRow(DispNumber,2,0x18 | dp);
lc.setRow(DispNumber,3,0x18 );
lc.setRow(DispNumber,4,0x18 );
lc.setRow(DispNumber,5,0x18 | dp);
lc.setRow(DispNumber,6,0x18 );
lc.setRow(DispNumber,7,0x3c );
//---------------------------------------------
}
if(Digit == 2)
{
if(DispNumber == 2)//
dp = 0x01;
else
dp = 0x00;
//-----------------Show 2----------------------
lc.setRow(DispNumber,0,0x38);
lc.setRow(DispNumber,1,0x4c);
lc.setRow(DispNumber,2,0xc | dp);
lc.setRow(DispNumber,3,0x8);
lc.setRow(DispNumber,4,0x10);
lc.setRow(DispNumber,5,0x20 | dp);
lc.setRow(DispNumber,6,0x40);
lc.setRow(DispNumber,7,0x7c);
}
//---------------------------------------------
if(Digit == 3)
{
if(DispNumber == 2)//
dp = 0x01;
else
dp = 0x00;
//-----------------Show 3----------------------
lc.setRow(DispNumber,0,0x38);
lc.setRow(DispNumber,1,0x4c);
lc.setRow(DispNumber,2,0xc| dp);
lc.setRow(DispNumber,3,0x38);
lc.setRow(DispNumber,4,0xc);
lc.setRow(DispNumber,5,0xc| dp);
lc.setRow(DispNumber,6,0x4c);
lc.setRow(DispNumber,7,0x38);
}
//---------------------------------------------
if(Digit == 4)
{
if(DispNumber == 2)//
dp = 0x01;
else
dp = 0x00;
//-----------------Show 4----------------------
lc.setRow(DispNumber,0,0x4c);
lc.setRow(DispNumber,1,0x4c);
lc.setRow(DispNumber,2,0x4c | dp);
lc.setRow(DispNumber,3,0x4c);
lc.setRow(DispNumber,4,0x3c);
lc.setRow(DispNumber,5,0xc | dp);
lc.setRow(DispNumber,6,0xc);
lc.setRow(DispNumber,7,0xc);
}
//---------------------------------------------
if(Digit == 5)
{
if(DispNumber == 2)//
dp = 0x01;
else
dp = 0x00;
//-----------------Show 5----------------------
lc.setRow(DispNumber,0,0x7c);
lc.setRow(DispNumber,1,0x40);
lc.setRow(DispNumber,2,0x40 | dp);
lc.setRow(DispNumber,3,0x38);
lc.setRow(DispNumber,4,0xc);
lc.setRow(DispNumber,5,0xc | dp);
lc.setRow(DispNumber,6,0xc);
lc.setRow(DispNumber,7,0x78);
}
//---------------------------------------------
if(Digit == 6)
{
if(DispNumber == 2)//
dp = 0x01;
else
dp = 0x00;
//-----------------Show 6----------------------
lc.setRow(DispNumber,0,0x38);
lc.setRow(DispNumber,1,0x44);
lc.setRow(DispNumber,2,0x40 | dp);
lc.setRow(DispNumber,3,0x78);
lc.setRow(DispNumber,4,0x4c);
lc.setRow(DispNumber,5,0x4c | dp);
lc.setRow(DispNumber,6,0x4c);
lc.setRow(DispNumber,7,0x38);
}
//---------------------------------------------
if(Digit == 7)
{
if(DispNumber == 2)//
dp = 0x01;
else
dp = 0x00;
//-----------------Show 7----------------------
lc.setRow(DispNumber,0,0x7c);
lc.setRow(DispNumber,1,0xc);
lc.setRow(DispNumber,2,0xc | dp);
lc.setRow(DispNumber,3,0x08);
lc.setRow(DispNumber,4,0x10);
lc.setRow(DispNumber,5,0x20 | dp);
lc.setRow(DispNumber,6,0x40);
lc.setRow(DispNumber,7,0x40);
}
//---------------------------------------------
if(Digit == 8)
{
if(DispNumber == 2)//
dp = 0x01;
else
dp = 0x00;
//-----------------Show 8----------------------
lc.setRow(DispNumber,0,0x38);
lc.setRow(DispNumber,1,0x4c);
lc.setRow(DispNumber,2,0x4c | dp);
lc.setRow(DispNumber,3,0x38);
lc.setRow(DispNumber,4,0x4c);
lc.setRow(DispNumber,5,0x4c | dp);
lc.setRow(DispNumber,6,0x4c);
lc.setRow(DispNumber,7,0x38);
}
//---------------------------------------------
if(Digit == 9)
{
if(DispNumber == 2)//
dp = 0x01;
else
dp = 0x00;
//-----------------Show 9----------------------
lc.setRow(DispNumber,0,0x38);
lc.setRow(DispNumber,1,0x4c);
lc.setRow(DispNumber,2,0x4c | dp);
lc.setRow(DispNumber,3,0x3c);
lc.setRow(DispNumber,4,0xc);
lc.setRow(DispNumber,5,0xc | dp);
lc.setRow(DispNumber,6,0x4c);
lc.setRow(DispNumber,7,0x38);
}
//---------------------------------------------
if(Digit == 0)
{
if(DispNumber == 2)//
dp = 0x01;
else
dp = 0x00;
//-----------------Show 0----------------------
lc.setRow(DispNumber,0,0x38);
lc.setRow(DispNumber,1,0x4c);
lc.setRow(DispNumber,2,0x4c | dp);
lc.setRow(DispNumber,3,0x4c);
lc.setRow(DispNumber,4,0x4c);
lc.setRow(DispNumber,5,0x4c | dp);
lc.setRow(DispNumber,6,0x4c);
lc.setRow(DispNumber,7,0x38);
}
}
void ShowTime()
{
//--------------------------------------------
SendDataDotMatrix(0,TimeMinutes1s);
SendDataDotMatrix(1,TimeMinutes10s);
SendDataDotMatrix(2,TimeHours1s);
if(TimeHours10s == 0)
lc.shutdown(3,true);
else
{
lc.shutdown(3,false);
SendDataDotMatrix(3,TimeHours10s);
}
//---------------------------------------------
}
void CalculateTime()
{
TimeSeconds1s++;
if(TimeSeconds1s == 10)
{
TimeSeconds1s = 0;
TimeSeconds10s++;
}
if(TimeSeconds10s == 6)
{
TimeSeconds10s = 0;
TimeSeconds1s = 0;
TimeMinutes1s++;
}
if(TimeMinutes1s == 10)
{
TimeMinutes1s = 0;
TimeSeconds10s = 0;
TimeSeconds1s = 0;
TimeMinutes10s++;
}
if(TimeMinutes10s == 6)
{
TimeMinutes10s = 0;
TimeMinutes1s = 0;
TimeSeconds10s = 0;
TimeSeconds1s = 0;
TimeHours1s++;
}
if(TimeHours1s == 10)
{
TimeHours1s=0;
TimeMinutes10s = 0;
TimeMinutes1s = 0;
TimeSeconds10s = 0;
TimeSeconds1s = 0;
TimeHours10s++;
}
if(TimeHours10s == 2 && TimeHours1s == 4)
{
TimeHours10s=0;
TimeHours1s=0;
TimeMinutes10s = 0;
TimeMinutes1s = 0;
TimeSeconds10s = 0;
TimeSeconds1s = 0;
}
}
Ik heb het wel voor elkaar geregen de cijfers mooier te maken door de code's te veranderen die lopen van 00 t/m FF per rij van 8 LED's. Was wel even een uitzoekerij maar heb alles op lijst gezet.
Dank alvast.
Hans
--
Hans van Kampen
Complete draad:
- Volgorde Arduino LED matrixklok nu juist.., -
Hans van Kampen,
17-08-2019, 23:20
- Volgorde Arduino LED matrixklok nu juist.., -
Otto,
18-08-2019, 07:13
- Volgorde Arduino LED matrixklok nu echt juist !! -
Hans van Kampen,
18-08-2019, 11:12
- Volgorde Arduino LED matrixklok nu echt juist !! -
Roland Huisman,
18-08-2019, 12:44
- Volgorde Arduino LED matrixklok nu echt juist !! -
Hans van Kampen,
18-08-2019, 13:10
- Volgorde Arduino LED matrixklok nu echt juist !! -
Oldtimer,
18-08-2019, 13:26
- Volgorde Arduino LED matrixklok nu echt juist !! - Hans van Kampen, 18-08-2019, 19:45
- Volgorde Arduino LED matrixklok nu echt juist !! -
Oldtimer,
18-08-2019, 13:26
- Volgorde Arduino LED matrixklok nu echt juist !! -
Hans van Kampen,
18-08-2019, 13:10
- Volgorde Arduino LED matrixklok nu echt juist !! -
Roland Huisman,
18-08-2019, 12:44
- Volgorde Arduino LED matrixklok nu echt juist !! -
Hans van Kampen,
18-08-2019, 11:12
- Volgorde Arduino LED matrixklok nu juist.., -
Otto,
18-08-2019, 07:13