TIMER LOMBA LARI DIGITAL 3 JALUR / LINE DMD P10 ARDUINO SENSOR LASER
Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang digunakan untuk timer lomba lari digital dengan menggunakan penampil dmd p10 dan sensor laser. alat ini menggunakan arduino sebagai kontrolernya. untuk lebih jelasnya berikut adalah komponen dan kodingnya.
a. Komponen
b. Program Arduino IDE
#include <Wire.h>
#include <SPI.h> //SPI.h must be included as DMD is written by SPI (the IDE complains otherwise)
#include <DMD.h> //Library DMD yang menyediakan fungsi penampilan teks, gambar dsb
#include <TimerOne.h> //Library peripheral Timer1 untuk menjalankan prosedur pindai panel DMD
#include <Time.h> //Library waktu yang menyediakan tipe data, struktur, dan obyek waktu
#include "Arial_black_16.h"
#include "Arial_Black_16_ISO_8859_1.h"
#include "Arial14.h"
#include "DejaVuSans9.h"
#include "Droid_Sans_12.h"
#include "Droid_Sans_16.h"
#include "DejaVuSansItalic9.h"
#include "Mono5x7.h"
#include "SystemFont5x7.h"
#define DISPLAY_COLUMN_COUNT 3
#define DISPLAY_ROW_COUNT 1
#define PIXELS_PER_COLUMN 32
#define PIXELS_PER_ROW 16
DMD dmd(DISPLAY_COLUMN_COUNT, DISPLAY_ROW_COUNT);
unsigned char show = 0;
char lineBuff[20];
char lineBuff2[20];
char lineBuff3[20];
int tombol = 5;
int tombolx;
int lineA;
int lineB;
int lineC;
int mulai;
int seconds;
int cs;
int secondsa;
int csa;
int secondsb;
int csb;
int secondsc;
int csc;
long start_time = 0;
int lapa,lapb,lapc;
int finisha = 0;
int finishb = 0;
int finishc = 0;
void ScanDMD()
{
dmd.scanDisplayBySPI();
}
void setup(void)
{
pinMode(2,INPUT);
pinMode(3,INPUT);
pinMode(4,INPUT);
pinMode(tombol,INPUT_PULLUP);
dmd.clearScreen( true ); //true is normal (all pixels off), false is negative (all pixels on)
Serial.begin(9600);
//initialize TimerOne's interrupt/CPU usage used to scan and refresh the display
Timer1.initialize( 1000 ); //period in microseconds to call ScanDMD. Anything longer than 5000 (5ms) and you can see flicker.
Timer1.attachInterrupt( ScanDMD ); //attach the Timer1 interrupt to ScanDMD which goes to dmd.scanDisplayBySPI()
//clear/init the DMD pixels held in RAM
dmd.clearScreen( true );
}
void loop(void)
{
//Serial.print(lineA);
//Serial.print(lineB);
//Serial.println(lineC);
//============================================
lineA = digitalRead(2);
lineB = digitalRead(3);
lineC = digitalRead(4);
if((lineA == 0)&&(lineB == 1)&&(lineC == 1)&&(mulai == 1)&&(finisha == 0)){
secondsa = seconds;
csa = cs;
finisha = 1;
}
if((lineA == 1)&&(lineB == 0)&&(lineC == 1)&&(mulai == 1)&&(finishb == 0)){
secondsb = seconds;
csb = cs;
finishb = 1;
}
if((lineA == 1)&&(lineB == 1)&&(lineC == 0)&&(mulai == 1)&&(finishc == 0)){
secondsc = seconds;
csc = cs;
finishc = 1;
}
if((finisha == 1)&&(finishb == 1)&&(finishc == 1)){
hasil();
}
//=============================================
tombolx = digitalRead(tombol);
if((tombolx == 0)&&(mulai == 0)){
delay(200);
sprintf(lineBuff3, "GO ", seconds, cs);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 70, 3, lineBuff3, strlen(lineBuff3), GRAPHICS_NORMAL);
mulai = 1;
start_time = millis();
}
if(mulai == 1){
seconds = (millis() - start_time) / 1000;
cs = ((millis() - start_time) / 10) % 100;;
}
//===========================================================================
sprintf(lineBuff, "%d:%d ", seconds, cs);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 35, 3, lineBuff, strlen(lineBuff), GRAPHICS_NORMAL);
sprintf(lineBuff2, "%d/%d/%d ", finisha, finishb, finishc);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 1, 3, lineBuff2, strlen(lineBuff2), GRAPHICS_NORMAL);
//===========================================================================
delay(1);
}
void hasil(){
sprintf(lineBuff, "%d:%d ", secondsa, csa);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 1, 3, lineBuff, strlen(lineBuff), GRAPHICS_NORMAL);
sprintf(lineBuff2, "%d:%d ", secondsb, csb);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 35, 3, lineBuff2, strlen(lineBuff2), GRAPHICS_NORMAL);
sprintf(lineBuff3, "%d:%d ", secondsc, csc);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 67, 3, lineBuff3, strlen(lineBuff3), GRAPHICS_NORMAL);
delay(30000);
hasil();
}
c. VIDEO HASILNYA
No comments:
Post a Comment