Seperti stop watch pada umumnya yaitu menghitung waktu penekanan awal (start) sampai penekanan akhir (stop) dengan jeda waktu mili detik.
Alat ini menggunakan Arduino UNO sebagi pengolah sistemnya. Tombol START digunakan untuk memulai perhitungan waktu. Tombol STOP untuk menghentikan penghitungan waktu. Tombol RESET untuk meng-nol-kan kembali nilai stop watch. Sedangkan seven segment 4 digit sebagai penampil hasil perhitungan stopwatch.
Kebutuhan Hardware
- Modul sevent segment 4 digit
- 2 Tombol push ON
- Modul Arduino UNO
- Power supply +5 Volt
7-Segment | Source
Diagram Blok
Schematic
7-Segment CA Wiring | Source
Koneksi Arduino UNO dengan 7-Segment dan Tombol
Source Code/Sketch
char stopWatch;
char menit, pulDetik, satDetik, ratMilli;
int sisaBagi;
unsigned long pengurang, dataStopWatch, dataPaus;
int segA = 2;
int segB = 3;
int segC = 4;
int segD = 5;
int segE = 6;
int segF = 7;
int segG = 8;
int segH = 9;
int dig1 = 10;
int dig2 = 11;
int dig3 = 12;
int dig4 = 13;
void setup() {
for(char i=2; i<14; i++){
pinMode(i,OUTPUT);
}
pinMode(A0,INPUT);
pinMode(A1,INPUT);
digitalWrite(A0,1);
digitalWrite(A1,1);
}
void loop() {
pengurang=millis();
if (digitalRead(A0)==0){
delay(100);
stopWatch = 1;
while(stopWatch){
dataStopWatch = ((millis() - pengurang)/100)+ dataPaus;
displaySeg();
if (digitalRead(A0)==0){
delay(100);
stopWatch = 0;
dataPaus = dataStopWatch;
}
}
}
else if(digitalRead(A1)==0){
dataStopWatch = 0;
dataPaus = 0;
}
displaySeg();
}
void displaySeg(){
menit = dataStopWatch / 600;
sisaBagi = dataStopWatch % 600;
pulDetik = sisaBagi / 100;
sisaBagi = sisaBagi % 100;
satDetik = sisaBagi / 10;
sisaBagi = sisaBagi % 10;
ratMilli = sisaBagi;
digitalWrite(dig4,1);
digitalWrite(dig1,0);
Seg(menit);
delay(6);
digitalWrite(dig1,1);
digitalWrite(dig2,0);
Seg(pulDetik);
delay(6);
digitalWrite(dig2,1);
digitalWrite(dig3,0);
digitalWrite(segH,0);
Seg(satDetik);
delay(6);
digitalWrite(segH,1);
digitalWrite(dig3,1);
digitalWrite(dig4,0);
Seg(ratMilli);
delay(6);
}
void Seg(char segment){
switch (segment){
case 0: digitalWrite(segA,0);
digitalWrite(segB,0);
digitalWrite(segC,0);
digitalWrite(segD,0);
digitalWrite(segE,0);
digitalWrite(segF,0);
digitalWrite(segG,1);
break;
case 1: digitalWrite(segA,1);
digitalWrite(segB,0);
digitalWrite(segC,0);
digitalWrite(segD,1);
digitalWrite(segE,1);
digitalWrite(segF,1);
digitalWrite(segG,1);
break;
case 2: digitalWrite(segA,0);
digitalWrite(segB,0);
digitalWrite(segC,1);
digitalWrite(segD,0);
digitalWrite(segE,0);
digitalWrite(segF,1);
digitalWrite(segG,0);
break;
case 3: digitalWrite(segA,0);
digitalWrite(segB,0);
digitalWrite(segC,0);
digitalWrite(segD,0);
digitalWrite(segE,1);
digitalWrite(segF,1);
digitalWrite(segG,0);
break;
case 4: digitalWrite(segA,1);
digitalWrite(segB,0);
digitalWrite(segC,0);
digitalWrite(segD,1);
digitalWrite(segE,1);
digitalWrite(segF,0);
digitalWrite(segG,0);
break;
case 5: digitalWrite(segA,0);
digitalWrite(segB,1);
digitalWrite(segC,0);
digitalWrite(segD,0);
digitalWrite(segE,1);
digitalWrite(segF,0);
digitalWrite(segG,0);
break;
case 6: digitalWrite(segA,0);
digitalWrite(segB,1);
digitalWrite(segC,0);
digitalWrite(segD,0);
digitalWrite(segE,0);
digitalWrite(segF,0);
digitalWrite(segG,0);
break;
case 7: digitalWrite(segA,0);
digitalWrite(segB,0);
digitalWrite(segC,0);
digitalWrite(segD,1);
digitalWrite(segE,1);
digitalWrite(segF,1);
digitalWrite(segG,1);
break;
case 8: digitalWrite(segA,0);
digitalWrite(segB,0);
digitalWrite(segC,0);
digitalWrite(segD,0);
digitalWrite(segE,0);
digitalWrite(segF,0);
digitalWrite(segG,0);
break;
case 9: digitalWrite(segA,0);
digitalWrite(segB,0);
digitalWrite(segC,0);
digitalWrite(segD,0);
digitalWrite(segE,1);
digitalWrite(segF,0);
digitalWrite(segG,0);
break;
}
}
char menit, pulDetik, satDetik, ratMilli;
int sisaBagi;
unsigned long pengurang, dataStopWatch, dataPaus;
int segA = 2;
int segB = 3;
int segC = 4;
int segD = 5;
int segE = 6;
int segF = 7;
int segG = 8;
int segH = 9;
int dig1 = 10;
int dig2 = 11;
int dig3 = 12;
int dig4 = 13;
void setup() {
for(char i=2; i<14; i++){
pinMode(i,OUTPUT);
}
pinMode(A0,INPUT);
pinMode(A1,INPUT);
digitalWrite(A0,1);
digitalWrite(A1,1);
}
void loop() {
pengurang=millis();
if (digitalRead(A0)==0){
delay(100);
stopWatch = 1;
while(stopWatch){
dataStopWatch = ((millis() - pengurang)/100)+ dataPaus;
displaySeg();
if (digitalRead(A0)==0){
delay(100);
stopWatch = 0;
dataPaus = dataStopWatch;
}
}
}
else if(digitalRead(A1)==0){
dataStopWatch = 0;
dataPaus = 0;
}
displaySeg();
}
void displaySeg(){
menit = dataStopWatch / 600;
sisaBagi = dataStopWatch % 600;
pulDetik = sisaBagi / 100;
sisaBagi = sisaBagi % 100;
satDetik = sisaBagi / 10;
sisaBagi = sisaBagi % 10;
ratMilli = sisaBagi;
digitalWrite(dig4,1);
digitalWrite(dig1,0);
Seg(menit);
delay(6);
digitalWrite(dig1,1);
digitalWrite(dig2,0);
Seg(pulDetik);
delay(6);
digitalWrite(dig2,1);
digitalWrite(dig3,0);
digitalWrite(segH,0);
Seg(satDetik);
delay(6);
digitalWrite(segH,1);
digitalWrite(dig3,1);
digitalWrite(dig4,0);
Seg(ratMilli);
delay(6);
}
void Seg(char segment){
switch (segment){
case 0: digitalWrite(segA,0);
digitalWrite(segB,0);
digitalWrite(segC,0);
digitalWrite(segD,0);
digitalWrite(segE,0);
digitalWrite(segF,0);
digitalWrite(segG,1);
break;
case 1: digitalWrite(segA,1);
digitalWrite(segB,0);
digitalWrite(segC,0);
digitalWrite(segD,1);
digitalWrite(segE,1);
digitalWrite(segF,1);
digitalWrite(segG,1);
break;
case 2: digitalWrite(segA,0);
digitalWrite(segB,0);
digitalWrite(segC,1);
digitalWrite(segD,0);
digitalWrite(segE,0);
digitalWrite(segF,1);
digitalWrite(segG,0);
break;
case 3: digitalWrite(segA,0);
digitalWrite(segB,0);
digitalWrite(segC,0);
digitalWrite(segD,0);
digitalWrite(segE,1);
digitalWrite(segF,1);
digitalWrite(segG,0);
break;
case 4: digitalWrite(segA,1);
digitalWrite(segB,0);
digitalWrite(segC,0);
digitalWrite(segD,1);
digitalWrite(segE,1);
digitalWrite(segF,0);
digitalWrite(segG,0);
break;
case 5: digitalWrite(segA,0);
digitalWrite(segB,1);
digitalWrite(segC,0);
digitalWrite(segD,0);
digitalWrite(segE,1);
digitalWrite(segF,0);
digitalWrite(segG,0);
break;
case 6: digitalWrite(segA,0);
digitalWrite(segB,1);
digitalWrite(segC,0);
digitalWrite(segD,0);
digitalWrite(segE,0);
digitalWrite(segF,0);
digitalWrite(segG,0);
break;
case 7: digitalWrite(segA,0);
digitalWrite(segB,0);
digitalWrite(segC,0);
digitalWrite(segD,1);
digitalWrite(segE,1);
digitalWrite(segF,1);
digitalWrite(segG,1);
break;
case 8: digitalWrite(segA,0);
digitalWrite(segB,0);
digitalWrite(segC,0);
digitalWrite(segD,0);
digitalWrite(segE,0);
digitalWrite(segF,0);
digitalWrite(segG,0);
break;
case 9: digitalWrite(segA,0);
digitalWrite(segB,0);
digitalWrite(segC,0);
digitalWrite(segD,0);
digitalWrite(segE,1);
digitalWrite(segF,0);
digitalWrite(segG,0);
break;
}
}
Jalannya Alat
1. Koneksikan antara sistem Arduino dengan peripheral lain seperti pada rangkaian (skematik).
2. Pasang power supply.
3. Upload Program Arduino diatas.
4. Tampilan pertama pada seven segment:
5. Tekan tombol Start/Paus, sehingga stopwatch menghitung waktu
6. Tekan tombol Start/Paus lagi, sehingga stopwatch berhenti menghitung
7. Untuk melanjutkan perhitungan stopwatch tekan tombol Start/Paus lagi.
8. Jika ingin me-Reset ulang waktu stopwatch maka kondisikan stopwatch pada posisi PAUSE lalu
tekan tombol RESET, maka data stopwatch tampil nol lagi.
Video untuk Project I - 3. Stopwatch dengan 4 Digit 7-Segment berbasis Arduino
KONTAK KAMI 085743320570 (adi sanjaya)
No comments:
Post a Comment