COUNTER WITH LED MATRIX

counter matrix

The code can be downloaded at:

https://github.com/triantara/ARDUINO-TRIANTARA/blob/main/COUNTER%205X.zip

//The sketch below can list up to 50
const int buttonPin = 7; // the pin that the pushbutton is attached to
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button
int jumlah=0;
#include “LedControl.h”

LedControl lc=LedControl(12,11,10,2); // Pins: DIN,CLK,CS, # of Display connected

unsigned long delayTime=1000; // Delay between Frames

// Put values in arrays

byte one[] =
{
B00000000, // First frame of invader #1
B00000000,
B10000010,
B11111111,
B10000000,
B00000000,
B00000000,
B00000000
};
byte two[] =
{
B00000000, // First frame of invader #1
B00000000,
B11000010,
B10100001,
B10010001,
B10001001,
B10000110,
B00000000
};
byte three[] =
{
B00000000, // First frame of invader #1
B01000010,
B10000001,
B10001001,
B10001001,
B01110110,
B00000000,
B00000000
};
byte four[] =
{
B00000000, // First frame of invader #1
B00110000,
B00101000,
B00100100,
B00100010,
B11110001,
B00100000,
B00000000
};
byte five[] =
{
B00000000, // First frame of invader #1
B00000000,
B01001111,
B10001001,
B10001001,
B10001001,
B01110001,
B00000000
};
byte six[] =
{
B00000000, // First frame of invader #1
B00000000,
B01111110,
B10001001,
B10001001,
B10001001,
B01110010,
B00000000
};
byte seven[] =
{
B00000000, // First frame of invader #1
B00000000,
B10000001,
B01000001,
B00100001,
B00010001,
B00001111,
B00000000
};
byte eight[] =
{
B00000000, // First frame of invader #1
B00000000,
B01110110,
B10001001,
B10001001,
B10001001,
B01110110,
B00000000
};
byte nine[] =
{
B00000000, // First frame of invader #1
B00000000,
B01000110,
B10001001,
B10001001,
B10001001,
B01111110,
B00000000
};
byte zero[] =
{
B00000000, // First frame of invader #1
B00000000,
B01111110,
B10000001,
B10000001,
B10000001,
B01111110,
B00000000
};

void setup() {
// initialize the button pin as a input:
pinMode(buttonPin, INPUT);
// initialize serial communication:
Serial.begin(9600);
lc.shutdown(0,false); // Wake up displays
lc.shutdown(1,false);
lc.setIntensity(0,0); // Set intensity levels
lc.setIntensity(1,0);
lc.clearDisplay(0); // Clear Displays
lc.clearDisplay(1);
}

void sone()
{
for (int i = 0; i < 8; i++)
{
lc.setRow(0,i,one[i]);
}
}
void stwo()
{
for (int i = 0; i < 8; i++)
{
lc.setRow(0,i,two[i]);
}
}
void sthree()
{
for (int i = 0; i < 8; i++)
{
lc.setRow(0,i,three[i]);
}
}
void sfour()
{
for (int i = 0; i < 8; i++)
{
lc.setRow(0,i,four[i]);
}
}
void sfive()
{
for (int i = 0; i < 8; i++)
{
lc.setRow(0,i,five[i]);
}
}
void ssix()
{
for (int i = 0; i < 8; i++)
{
lc.setRow(0,i,six[i]);
}
}
void sseven()
{
for (int i = 0; i < 8; i++)
{
lc.setRow(0,i,seven[i]);
}
}
void seight()
{
for (int i = 0; i < 8; i++)
{
lc.setRow(0,i,eight[i]);
}
}
void snine()
{
for (int i = 0; i < 8; i++)
{
lc.setRow(0,i,nine[i]);
}
}
void szero()
{
for (int i = 0; i < 8; i++)
{
lc.setRow(0,i,zero[i]);
}
}

void sone1()
{
for (int i = 0; i < 8; i++)
{
lc.setRow(1,i,one[i]);
}
}
void stwo1()
{
for (int i = 0; i < 8; i++)
{
lc.setRow(1,i,two[i]);
}
}
void sthree1()
{
for (int i = 0; i < 8; i++)
{
lc.setRow(1,i,three[i]);
}
}
void sfour1()
{
for (int i = 0; i < 8; i++)
{
lc.setRow(1,i,four[i]);
}
}
void sfive1()
{
for (int i = 0; i < 8; i++)
{
lc.setRow(1,i,five[i]);
}
}
void ssix1()
{
for (int i = 0; i < 8; i++)
{
lc.setRow(1,i,six[i]);
}
}
void sseven1()
{
for (int i = 0; i < 8; i++)
{
lc.setRow(1,i,seven[i]);
}
}
void seight1()
{
for (int i = 0; i < 8; i++)
{
lc.setRow(1,i,eight[i]);
}
}
void snine1()
{
for (int i = 0; i < 8; i++)
{
lc.setRow(1,i,nine[i]);
}
}
void szero1()
{
for (int i = 0; i < 8; i++)
{
lc.setRow(1,i,zero[i]);
}
}

void sepuluh()
{
lc.clearDisplay(0);
lc.clearDisplay(1);
stwo1();
sone();
}

void loop() {
// read the pushbutton input pin:
buttonState = digitalRead(buttonPin);

// compare the buttonState to its previous state
if (buttonState != lastButtonState) {
// if the state has changed, increment the counter
if (buttonState == HIGH) {
// if the current state is HIGH then the button
// wend from off to on:
buttonPushCounter++;
Serial.println(“on”);
Serial.print(“number of button pushes: “);
Serial.println(buttonPushCounter);

// Delay a little bit to avoid bouncing
delay(100);
}
int jumlah = buttonPushCounter;
if (jumlah==1){
lc.clearDisplay(0);
lc.clearDisplay(1);
szero1();
sone();
}
if (jumlah==2){
lc.clearDisplay(0);
lc.clearDisplay(1);
szero1();
stwo();
}
if (jumlah==3){
lc.clearDisplay(0);
lc.clearDisplay(1);
szero1();
sthree();
}
if (jumlah==4){
lc.clearDisplay(0);
lc.clearDisplay(1);
szero1();
sfour();
}
if (jumlah==5){
lc.clearDisplay(0);
lc.clearDisplay(1);
szero1();
sfive();
}
if (jumlah==6){
lc.clearDisplay(0);
lc.clearDisplay(1);
szero1();
ssix();
}
if (jumlah==7){
lc.clearDisplay(0);
lc.clearDisplay(1);
szero1();
sseven();
}
if (jumlah==8){
lc.clearDisplay(0);
lc.clearDisplay(1);
szero1();
seight();
}
if (jumlah==9){
lc.clearDisplay(0);
lc.clearDisplay(1);
szero1();
snine();
}
if (jumlah==10){
lc.clearDisplay(0);
lc.clearDisplay(1);
sone1();
szero();
}
if (jumlah==11){
lc.clearDisplay(0);
lc.clearDisplay(1);
sone1();
sone();
}
if (jumlah==12){
lc.clearDisplay(0);
lc.clearDisplay(1);
sone1();
stwo();
}
if (jumlah==13){
lc.clearDisplay(0);
lc.clearDisplay(1);
sone1();
sthree();
}
if (jumlah==14){
lc.clearDisplay(0);
lc.clearDisplay(1);
sone1();
sfour();
}
if (jumlah==15){
lc.clearDisplay(0);
lc.clearDisplay(1);
sone1();
sfive();
}
if (jumlah==16){
lc.clearDisplay(0);
lc.clearDisplay(1);
sone1();
ssix();
}
if (jumlah==17){
lc.clearDisplay(0);
lc.clearDisplay(1);
sone1();
sseven();
}
if (jumlah==18){
lc.clearDisplay(0);
lc.clearDisplay(1);
sone1();
seight();
}
if (jumlah==19){
lc.clearDisplay(0);
lc.clearDisplay(1);
sone1();
snine();
}
if (jumlah==20){
lc.clearDisplay(0);
lc.clearDisplay(1);
stwo1();
szero();
}
if (jumlah==21){
lc.clearDisplay(0);
lc.clearDisplay(1);
stwo1();
sone();
}
if (jumlah==22){
lc.clearDisplay(0);
lc.clearDisplay(1);
stwo1();
stwo();
}
if (jumlah==23){
lc.clearDisplay(0);
lc.clearDisplay(1);
stwo1();
sthree();
}
if (jumlah==24){
lc.clearDisplay(0);
lc.clearDisplay(1);
stwo1();
sfour();
}
if (jumlah==25){
lc.clearDisplay(0);
lc.clearDisplay(1);
stwo1();
sfive();
}
if (jumlah==26){
lc.clearDisplay(0);
lc.clearDisplay(1);
stwo1();
ssix();
}
if (jumlah==27){
lc.clearDisplay(0);
lc.clearDisplay(1);
stwo1();
sseven();
}
if (jumlah==28){
lc.clearDisplay(0);
lc.clearDisplay(1);
stwo1();
seight();
}
if (jumlah==29){
lc.clearDisplay(0);
lc.clearDisplay(1);
stwo1();
snine();
}
if (jumlah==30){
lc.clearDisplay(0);
lc.clearDisplay(1);
sthree1();
szero();
}
if (jumlah==31){
lc.clearDisplay(0);
lc.clearDisplay(1);
sthree1();
sone();
}
if (jumlah==32){
lc.clearDisplay(0);
lc.clearDisplay(1);
sthree1();
stwo();
}
if (jumlah==33){
lc.clearDisplay(0);
lc.clearDisplay(1);
sthree1();
sthree();
}
if (jumlah==34){
lc.clearDisplay(0);
lc.clearDisplay(1);
sthree1();
sfour();
}
if (jumlah==35){
lc.clearDisplay(0);
lc.clearDisplay(1);
sthree1();
sfive();
}
if (jumlah==36){
lc.clearDisplay(0);
lc.clearDisplay(1);
sthree1();
ssix();
}
if (jumlah==37){
lc.clearDisplay(0);
lc.clearDisplay(1);
sthree1();
sseven();
}
if (jumlah==38){
lc.clearDisplay(0);
lc.clearDisplay(1);
sthree1();
seight();
}
if (jumlah==39){
lc.clearDisplay(0);
lc.clearDisplay(1);
sthree1();
snine();
}
if (jumlah==40){
lc.clearDisplay(0);
lc.clearDisplay(1);
sfour1();
szero();
}
if (jumlah==41){
lc.clearDisplay(0);
lc.clearDisplay(1);
sfour1();
sone();
}
if (jumlah==42){
lc.clearDisplay(0);
lc.clearDisplay(1);
sfour1();
stwo();
}
if (jumlah==43){
lc.clearDisplay(0);
lc.clearDisplay(1);
sfour1();
sthree();
}
if (jumlah==44){
lc.clearDisplay(0);
lc.clearDisplay(1);
sfour1();
sfour();
}
if (jumlah==45){
lc.clearDisplay(0);
lc.clearDisplay(1);
sfour1();
sfive();
}
if (jumlah==46){
lc.clearDisplay(0);
lc.clearDisplay(1);
sfour1();
ssix();
}
if (jumlah==47){
lc.clearDisplay(0);
lc.clearDisplay(1);
sfour1();
sseven();
}
if (jumlah==48){
lc.clearDisplay(0);
lc.clearDisplay(1);
sfour1();
seight();
}
if (jumlah==49){
lc.clearDisplay(0);
lc.clearDisplay(1);
sfour1();
snine();
}
if (jumlah==50){
lc.clearDisplay(0);
lc.clearDisplay(1);
sfive1();
szero();
}

if (jumlah==0){
lc.clearDisplay(0);
lc.clearDisplay(1);
//szero1();
//sone();
}

}

lastButtonState = buttonState;

}