TIMER LOMBA LARI DRAG RACE 1 LINE
Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dipakai untuk timer lomba lari yang mana alat ini memiliki beberapa komponen yaitu DMD P10 Panel dan Arduino. untuk sensor menggunakan sensor proximity. untuk lebih jelasnya berikut adalah 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 2
#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];
int tombol = 12;
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;
void ScanDMD()
{
dmd.scanDisplayBySPI();
}
void setup(void)
{
pinMode(2,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)
{
//============================================
lineA = digitalRead(2);
if(lineA == 0){
secondsa = seconds;
csa = cs;
finisha = 1;
dmd.clearScreen( true );
hasil();
}
//=============================================
tombolx = digitalRead(tombol);
if((tombolx == 0)&&(mulai == 0)){
delay(200);
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);
//===========================================================================
delay(1);
}
void hasil(){
sprintf(lineBuff, "%d:%d ", secondsa, csa);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 35, 3, lineBuff, strlen(lineBuff), GRAPHICS_NORMAL);
hasil();
}
c. VIDEO HASILNYA
No comments:
Post a Comment