Timer Lomba Wireless RF Link 433 Mhz Interface DMD P10
Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara untuk membuat sebuah timer lomba dengan start stop jarak jauh menggunakan modul RF Link 433 Mhz. alat ini menggunakan interface modul dmd p10 dengan sensor jarak sebagai sensornya. untuk lebih jelasnya berikut adalah koding skemanya.
1. Skema
2. Program Transmitter
// RF 433MHz Modules (Transmitter Circuit)
#include <RH_ASK.h>
// Serial Peripheral Interface (SPI)
#include <SPI.h> // Needed to compile
RH_ASK driver;
// digital pin 2 has a pushbutton attached to it. Give it a name:
int pushButton = 11;
// the setup routine runs once when you press reset:
void setup() {
Serial.begin (9600); // Debugging ONLY
if (!driver.init ())
Serial.println ("init failed");
pinMode(pushButton, INPUT_PULLUP);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input pin:
int buttonState = digitalRead(pushButton);
if(buttonState == 0){
const char *msg = "111";
driver.send((uint8_t *)msg, strlen(msg));
driver.waitPacketSent();
}
if(buttonState == 1){
const char *msg = "222";
driver.send((uint8_t *)msg, strlen(msg));
driver.waitPacketSent();
}
delay(100);
}
3. Program Receiver RF LINK
#include "Wire.h"
#include <RH_ASK.h>
#include <SPI.h> // Not actualy used but needed to compile
RH_ASK driver;
int relay = 8;
String a;
void setup() {
Serial.begin(9600);
pinMode(relay, OUTPUT);
if (!driver.init())
Serial.println("init failed");
}
void loop() {
uint8_t buf[12];
uint8_t buflen = sizeof(buf);
if (driver.recv(buf, &buflen)) // Non-blocking
{
int i;
// Message with a good checksum received, dump it.
int nilai = atoi((char*)buf);
Serial.println(nilai);
if(nilai == 111){
digitalWrite(relay,HIGH);
}
if(nilai == 222){
digitalWrite(relay,LOW);
}
}
delay(100);
}
4. Program Receiver DMD P10
#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 = 2;
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;
int kecepatan;
int jarak = 5;
long start_time = 0;
int lapa,lapb,lapc;
int finisha = 0;
void ScanDMD()
{
dmd.scanDisplayBySPI();
}
void setup(void)
{
pinMode(5,INPUT_PULLUP);
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(5);
Serial.println(lineA);
if(lineA == 1){
secondsa = seconds;
csa = cs;
finisha = 1;
dmd.clearScreen( true );
hasil();
dmd.clearScreen( true );
hasil2();
}
//=============================================
tombolx = digitalRead(tombol);
if((tombolx == 1)&&(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);
delay(5000);
}
void hasil2(){
kecepatan = jarak / secondsa;
sprintf(lineBuff, "%d ", kecepatan);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 35, 3, lineBuff, strlen(lineBuff), GRAPHICS_NORMAL);
hasil2();
}
5. VIDEO HASILNYA


