Alat ini bekerja sebagai penghitung skor futsal, skor ditambah dan dikurangi dengan menekan tombol dan hasilnya ditampilkan pada 7 segment.
Seven segment sebagai display skor tim 1 dan tim 2 yang masing masing tim terdapat 2 digit seven segment. Sedangkan untuk kontrol naik dan turunya skor menggunakan tombol UP dan DOWN. Tombol RESET digunakan untuk mengembalikan skor menjadi nol kembali. Data skor disimpan pada EEPROM agar saat listrik mati data masih tersimpan.
Kebutuhan Hardware
- Modul Seven segment 2 digit x 2
- 5 Tombol push ON
- Modul Arduino UNO
- Power supply +5 Volt
Diagram Blok
Schematic
7-Segment CA Wiring | Source
Koneksi Arduino UNO dengan tombol
Source Code/Sketch
#include <EEPROM.h>
long lastButton = 0;
long delayAntiBouncing = 50;
byte skor1, skor2;
byte seven_seg_digits[10][7] = { { ,0,0,0,0,0,1 }, // = 0
{ 1,0,0,1,1,1,1 }, // = 1
{ 0,0,1,0,0,1,0 }, // = 2
{ 0,0,0,0,1,1,0 }, // = 3
{ 1,0,0,1,1,0,0 }, // = 4
{ 0,1,0,0,1,0,0 }, // = 5
{ 0,1,0,0,0,0,0 }, // = 6
{ 0,0,0,1,1,1,1 }, // = 7
{ 0,0,0,0,0,0,0 }, // = 8
{ 0,0,0,0,1,0,0 }, // = 9
};
void setup(){
for(char i=2; i<13; i++){
pinMode(i,OUTPUT);
}
pinMode(A0,INPUT);
pinMode(A1,INPUT);
pinMode(A2,INPUT);
pinMode(A3,INPUT);
pinMode(A4,INPUT);
digitalWrite(A0,HIGH);
digitalWrite(A1,HIGH);
digitalWrite(A2,HIGH);
digitalWrite(A3,HIGH);
digitalWrite(A4,HIGH);
skor1 = EEPROM.read(1);
skor2 = EEPROM.read(2);
if(skor1 == 255)skor1 = 0;
if(skor2 == 255)skor2 = 0;
}
void loop(){
tampilSkor();
tombol();
}
void tampilSkor(){
digitalWrite(10,LOW); digitalWrite(11,HIGH);
digitalWrite(12,HIGH); digitalWrite(13,HIGH);
sevenSegWrite(skor1 / 10);
delay(5);
digitalWrite(10,HIGH); digitalWrite(11,LOW);
digitalWrite(12,HIGH); digitalWrite(13,HIGH);
sevenSegWrite(skor1 % 10);
delay(5);
digitalWrite(10,HIGH); digitalWrite(11,HIGH);
digitalWrite(12,LOW); digitalWrite(13,HIGH);
sevenSegWrite(skor2 / 10);
delay(5);
digitalWrite(10,HIGH); digitalWrite(11,HIGH);
digitalWrite(12,HIGH); digitalWrite(13,LOW);
sevenSegWrite(skor2 % 10);
delay(5);
}
void sevenSegWrite(byte segment){
byte pin = 2;
for (byte segCount = 0; segCount < 7; ++segCount) {
digitalWrite(pin, seven_seg_digits[segment][segCount]);
++pin;
}
}
void tombol(){
//-----------------tombol UP 1
if(digitalRead(A0)==0){
if ((millis() - lastButton) > delayAntiBouncing){
if (skor1 < 99){
skor1++;
EEPROM.write(1, skor1);
}
}
lastButton = millis();
}
//---------------tombol DOWN 1
if(digitalRead(A1)==0){
if ((millis() - lastButton) > delayAntiBouncing){
if (skor1 > 0){
skor1--;
EEPROM.write(1, skor1);
}
}
lastButton = millis();
}
//-----------------tombol UP 2
if(digitalRead(A2)==0){
if ((millis() - lastButton) > delayAntiBouncing){
if (skor2 < 99){
skor2++;
EEPROM.write(2, skor2);
}
}
lastButton = millis();
}
//---------------tombol DOWN 2
if(digitalRead(A3)==0){
if ((millis() - lastButton) > delayAntiBouncing){
if (skor2 > 0){
skor2--;
EEPROM.write(2, skor2);
}
}
lastButton = millis();
}
//---------------tombol RESET
if(digitalRead(A4)==0){
if ((millis() - lastButton) > delayAntiBouncing){
skor1=0;
skor2=0;
EEPROM.write(1, skor1);
EEPROM.write(2, skor2);
}
lastButton = millis();
}
}
long lastButton = 0;
long delayAntiBouncing = 50;
byte skor1, skor2;
byte seven_seg_digits[10][7] = { { ,0,0,0,0,0,1 }, // = 0
{ 1,0,0,1,1,1,1 }, // = 1
{ 0,0,1,0,0,1,0 }, // = 2
{ 0,0,0,0,1,1,0 }, // = 3
{ 1,0,0,1,1,0,0 }, // = 4
{ 0,1,0,0,1,0,0 }, // = 5
{ 0,1,0,0,0,0,0 }, // = 6
{ 0,0,0,1,1,1,1 }, // = 7
{ 0,0,0,0,0,0,0 }, // = 8
{ 0,0,0,0,1,0,0 }, // = 9
};
void setup(){
for(char i=2; i<13; i++){
pinMode(i,OUTPUT);
}
pinMode(A0,INPUT);
pinMode(A1,INPUT);
pinMode(A2,INPUT);
pinMode(A3,INPUT);
pinMode(A4,INPUT);
digitalWrite(A0,HIGH);
digitalWrite(A1,HIGH);
digitalWrite(A2,HIGH);
digitalWrite(A3,HIGH);
digitalWrite(A4,HIGH);
skor1 = EEPROM.read(1);
skor2 = EEPROM.read(2);
if(skor1 == 255)skor1 = 0;
if(skor2 == 255)skor2 = 0;
}
void loop(){
tampilSkor();
tombol();
}
void tampilSkor(){
digitalWrite(10,LOW); digitalWrite(11,HIGH);
digitalWrite(12,HIGH); digitalWrite(13,HIGH);
sevenSegWrite(skor1 / 10);
delay(5);
digitalWrite(10,HIGH); digitalWrite(11,LOW);
digitalWrite(12,HIGH); digitalWrite(13,HIGH);
sevenSegWrite(skor1 % 10);
delay(5);
digitalWrite(10,HIGH); digitalWrite(11,HIGH);
digitalWrite(12,LOW); digitalWrite(13,HIGH);
sevenSegWrite(skor2 / 10);
delay(5);
digitalWrite(10,HIGH); digitalWrite(11,HIGH);
digitalWrite(12,HIGH); digitalWrite(13,LOW);
sevenSegWrite(skor2 % 10);
delay(5);
}
void sevenSegWrite(byte segment){
byte pin = 2;
for (byte segCount = 0; segCount < 7; ++segCount) {
digitalWrite(pin, seven_seg_digits[segment][segCount]);
++pin;
}
}
void tombol(){
//-----------------tombol UP 1
if(digitalRead(A0)==0){
if ((millis() - lastButton) > delayAntiBouncing){
if (skor1 < 99){
skor1++;
EEPROM.write(1, skor1);
}
}
lastButton = millis();
}
//---------------tombol DOWN 1
if(digitalRead(A1)==0){
if ((millis() - lastButton) > delayAntiBouncing){
if (skor1 > 0){
skor1--;
EEPROM.write(1, skor1);
}
}
lastButton = millis();
}
//-----------------tombol UP 2
if(digitalRead(A2)==0){
if ((millis() - lastButton) > delayAntiBouncing){
if (skor2 < 99){
skor2++;
EEPROM.write(2, skor2);
}
}
lastButton = millis();
}
//---------------tombol DOWN 2
if(digitalRead(A3)==0){
if ((millis() - lastButton) > delayAntiBouncing){
if (skor2 > 0){
skor2--;
EEPROM.write(2, skor2);
}
}
lastButton = millis();
}
//---------------tombol RESET
if(digitalRead(A4)==0){
if ((millis() - lastButton) > delayAntiBouncing){
skor1=0;
skor2=0;
EEPROM.write(1, skor1);
EEPROM.write(2, skor2);
}
lastButton = millis();
}
}
Jalannya Alat
1. Tampilan normal menampilkan skor 00 pada masing-masing skor tim
3. Tekan tombol RESET untuk mengembalikan skor menjadi nol semua.
Video untuk Proyek I - 11. Papan Skor menggunakan 7-Segment berbasis Arduino
KONTAK KAMI 085743320570 (adi sanjaya)
kode nya itu aja gan..?
ReplyDelete