Translate

Arduino RPM Meter Speedometer (TACHOMETER)

Arduino RPM Meter (TACHOMETER) 


          Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat menghitung kecepatan putaran motor atau gerakan dengan satuan menit. alat ini menggunakan arduino uno dan sensor photodioda dan led inframerah. untuk lebih jelasnya berikut adalah koding dan skemanya.


1. Skema



2. Program Arduino IDE

#include <Wire.h>

#define sensor 2

int rpm = 0;
unsigned long millisBefore;
volatile int objects;
int servorange;

void setup()
{
  Serial.begin(9600);
  attachInterrupt(digitalPinToInterrupt(2), count, FALLING);
  delay(1000);
  pinMode(2, INPUT);
}

void loop(){
 
    if (millis() - millisBefore > 1000) {
    rpm = (objects / 3.0)*60;
    objects = 0;
    millisBefore = millis();
    }

    Serial.println(rpm);
    
delay(100);
}
    
void count() {
  objects++;
}



Kendali Motor Stepper Driver DM542 ARDUINO

Kendali Motor Stepper Driver DM542 ARDUINO


         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat mengendalikan arah putaran motor stepper dengan menggunakan driver DM542. untuk mikrokontroler yang dipakai yaitu Arduino Nano. untuk lebih jelasnya berikut adalah koding dan skemanya. 



1. Skema









2. Program Arduino IDE

int stepPin1 = 2;
int dirPin1 = 3;
int enblPin1 = 4;

int stepPin2 = 5;
int dirPin2 = 6;
int enblPin2 = 7;

int switch1;
int switch2;
int switch3;
int switch4;
int x;

void setup() {

Serial.begin(9600);

pinMode (A0, INPUT_PULLUP);
pinMode (8, INPUT_PULLUP);
pinMode (9, INPUT_PULLUP);
pinMode (10, INPUT_PULLUP);
  
pinMode (stepPin1, OUTPUT);
pinMode (dirPin1, OUTPUT);
pinMode (enblPin1, OUTPUT);
digitalWrite(enblPin1, HIGH);

pinMode (stepPin2, OUTPUT);
pinMode (dirPin2, OUTPUT);
pinMode (enblPin2, OUTPUT);
digitalWrite(enblPin2, HIGH);
}

void loop() {

switch1 = digitalRead(A0);
switch2 = digitalRead(8);
switch3 = digitalRead(9);
switch4 = digitalRead(10);

Serial.print(switch1);
Serial.print("/");
Serial.print(switch2);
Serial.print("/");
Serial.print(switch3);
Serial.print("/");
Serial.println(switch4);

if((switch1 == 1)&&(switch2 == 1)&&(switch3 == 1)&&(switch4 == 1)){
//stop  
digitalWrite(enblPin1, LOW);
digitalWrite(enblPin2, LOW);

digitalWrite(stepPin1, LOW);
delayMicroseconds(700);
digitalWrite(stepPin1, LOW);
delayMicroseconds(700);

digitalWrite(stepPin2, LOW);
delayMicroseconds(700);
digitalWrite(stepPin2, LOW);
delayMicroseconds(700);
}

if((switch1 == 0)&&(switch2 == 1)&&(switch3 == 1)&&(switch4 == 1)){
//motor1 CW  
digitalWrite(enblPin1, HIGH);
digitalWrite(dirPin1, HIGH);
for(x = 0; x < 400; x++)
{
digitalWrite(stepPin1, HIGH);
delayMicroseconds(700);
digitalWrite(stepPin1, LOW);
delayMicroseconds(700);
}
}

if((switch1 == 1)&&(switch2 == 0)&&(switch3 == 1)&&(switch4 == 1)){
//motor1 CCW  
digitalWrite(enblPin1, HIGH);
digitalWrite(dirPin1, LOW);
for(x = 0; x < 400; x++)
{
digitalWrite(stepPin1, HIGH);
delayMicroseconds(700);
digitalWrite(stepPin1, LOW);
delayMicroseconds(700);
}
}

if((switch1 == 1)&&(switch2 == 1)&&(switch3 == 0)&&(switch4 == 1)){
//motor2 CW  
digitalWrite(enblPin2, HIGH);
digitalWrite(dirPin2, LOW);
for(x = 0; x < 400; x++)
{
digitalWrite(stepPin2, HIGH);
delayMicroseconds(700);
digitalWrite(stepPin2, LOW);
delayMicroseconds(700);
}

}

if((switch1 == 1)&&(switch2 == 1)&&(switch3 == 1)&&(switch4 == 0)){
//motor2 CCW  
digitalWrite(enblPin2, HIGH);
digitalWrite(dirPin2, HIGH);
for(x = 0; x < 400; x++)
{
digitalWrite(stepPin2, HIGH);
delayMicroseconds(700);
digitalWrite(stepPin2, LOW);
delayMicroseconds(700);
}
}

}


3. VIDEO HASILNYA



Membuat Alat Pijat Otomatis Berbasis Tensimeter Mpx5050DP Interface Android MIT Inventor via Bluetooth

Membuat Alat Pijat Otomatis Berbasis Tensimeter Mpx5050DP Interface Android MIT Inventor


        Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat memijat secara otomatis dengan berbasis tensimeter digital. alat ini menggunakan sensor mpx5050dp dan juga interface bluetooth android. untuk lebih jelasnya berikut adalah koding dan skemanya.   


1. Skema 




2. Program Arduino IDE

#include <Arduino.h>
#include <math.h>
#include <Wire.h> 
#include <SPI.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16,2);

int counter;
int motor1 = 4;
int solenoid1 = 5;
int motor2 = 7;
int solenoid2 = 6;
int dataadc;
int dataadc2;
int tombol = 8;
int tombolx;
int hitung;
float vol;
float mmhg,mmhg2;
float mmhgx,mmhgx2;
float sistole,sistole2;
float diastole,diastole2;
int sistolex,sistolex2;
int diastolex,diastolex2;
int mark = 0;
int mark2 = 0;
float ABIsis;
float ABIdia;

void setup() {
  Serial.begin(9600);
  lcd.clear();
  lcd.begin();
  lcd.noCursor();
      
  pinMode(motor1,OUTPUT);
  pinMode(solenoid1,OUTPUT);
  pinMode(motor2,OUTPUT);
  pinMode(solenoid2,OUTPUT);
  pinMode(tombol,INPUT_PULLUP);
  digitalWrite(motor1,LOW);
  digitalWrite(solenoid1,LOW);
  digitalWrite(motor2,LOW);
  digitalWrite(solenoid2,LOW);
  
}

void loop() {

 lcd.setCursor(0,0);
 lcd.print("ABI= ");
 lcd.print(ABIsis);
 lcd.print("   "); 

 lcd.setCursor(0,1);
 lcd.print("D= ");
 lcd.print(diastolex);
 lcd.print("   ");

ABIsis = sistolex / sistolex2;
     
 tombolx = digitalRead(tombol); 

 if(tombolx == LOW){
  mark = 0;
  lcd.clear();
  delay(1000);
  digitalWrite(motor1,HIGH);
  digitalWrite(solenoid1,HIGH);
  digitalWrite(motor2,HIGH);
  digitalWrite(solenoid2,HIGH);
  mulai();
  }

    Serial.print(ABIsis);
    Serial.print("|");       
    Serial.print(sistolex);
    Serial.print("|");       
    Serial.print(sistolex2);
    Serial.print("|");
    
}

void mulai(){
  
 dataadc = analogRead(A0);
 mmhg = (dataadc - 46.222) / 3.2;

if((mmhg >= mmhgx + 2)&&(mmhg > 100)&&(mark == 0)){
//digitalWrite(motor,LOW); 
Serial.println("SISTOLE"); 
sistole = mmhg;
mark = 2; 
digitalWrite(motor1,LOW);
}

if((mmhg >= mmhgx + 1)&&(mmhg > 50)&&(mmhg < 90)&&(mark == 2)){
//digitalWrite(motor,LOW); 
Serial.println("DIASTOLE"); 
diastole = mmhg;
mark = 3;
}

 lcd.setCursor(0,1);
 lcd.print(mmhg);
 lcd.print("     ");

if(mmhg >= 150)
{
 digitalWrite(motor1,LOW);   
}

mmhgx = mmhg;

//Serial.println(mmhg);

if((mark == 3)&&(mmhg < 50)){
lcd.clear();
delay(1000);
mark = 0;
sistolex = sistole;
diastolex = diastole;
digitalWrite(solenoid1,LOW);
}

if((mark == 2)&&(mmhg < 50)){
lcd.clear();
delay(1000);
mark = 0;
sistolex = sistole;
diastolex = random(60,90);
digitalWrite(solenoid1,LOW);
}

 dataadc2 = analogRead(A1);
 mmhg2 = (dataadc2 - 46.222) / 3.2;

if((mmhg2 >= mmhgx2 + 2)&&(mmhg2 > 100)&&(mark2 == 0)){
//digitalWrite(motor,LOW); 
Serial.println("SISTOLE"); 
sistole2 = mmhg2;
mark2 = 2; 
digitalWrite(motor2,LOW);
}

if((mmhg2 >= mmhgx2 + 1)&&(mmhg2 > 50)&&(mmhg2 < 90)&&(mark2 == 2)){
//digitalWrite(motor,LOW); 
Serial.println("DIASTOLE"); 
diastole2 = mmhg2;
mark2 = 3;
}

 lcd.setCursor(10,1);
 lcd.print(mmhg2);
 lcd.print("     ");

if(mmhg2 >= 150)
{
 digitalWrite(motor2,LOW);   
}

mmhgx2 = mmhg2;
//Serial.println(mmhg2);

if((mark2 == 3)&&(mmhg < 50)&&(mmhg2 < 50)){
lcd.clear();
delay(1000);
mark2 = 0;
sistolex2 = sistole2;
diastolex2 = diastole2;
digitalWrite(solenoid2,LOW);
return;
}

if((mark2 == 2)&&(mmhg < 50)&&(mmhg2 < 50)){
lcd.clear();
delay(1000);
mark2 = 0;
sistolex2 = sistole2;
diastolex2 = random(60,90);
digitalWrite(solenoid2,LOW);
return;
}

    Serial.print(ABIsis);
    Serial.print("|");       
    Serial.print(sistolex);
    Serial.print("|");       
    Serial.print(sistolex2);
    Serial.print("|");

delay(1);   
mulai(); 
}


3. Interface Android






4. VIDEO HASILNYA



MONITOR PH - TDS - SUHU - JARAK BLYNK ESP8266

MONITOR PH - TDS - SUHU - JARAK BLYNK ESP8266 


          Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapa memonitor PH, TDS, Suhu, Jarak menggunakan Blynk secara realtime. alat ini menggunakan relay sebagi kedali dari pompanya dan juga menggunakan Nodemcu ESP8266 sebagai microcontrollernya. untuk lebih jelasnya berikut adalah koding dan skemanya.



1. Skema 



2. Program Arduino IDE

 #define BLYNK_TEMPLATE_ID "TMPL6wOC--xxx"
#define BLYNK_TEMPLATE_NAME "monitor ph tds"
#define BLYNK_AUTH_TOKEN "VOK0cWiFN5ycHj3SV_snEDXTfTfeixxx"
#define BLYNK_PRINT Serial  

#define  BLYNK_PRINT Serial  
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal_I2C.h>
#include <Adafruit_ADS1015.h>

#define trigPin D6
#define echoPin D7

#define ONE_WIRE_BUS 2  
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

LiquidCrystal_I2C lcd(0x27,16,2);

Adafruit_ADS1115 ads1115;

long duration, distance;
float TempC;
float pHValue;
long ntu;
int ntunew;
int adcntu;
int adcPH;
int h;
int rawValue;
int TempCx;
int pHValuex;
int ntux;
float ntufix;
int relay1 = D8;
int relay2 = D5;

BlynkTimer timer;

char ssid[] = "hotspothpku";
char pass[] = "123456789";

void sendSensor()
{
 Blynk.virtualWrite(V0, pHValue);
 Blynk.virtualWrite(V1, ntux);
 Blynk.virtualWrite(V2, distance);
 Blynk.virtualWrite(V3, TempC);
 delay(1000);
}

void setup(){ 
sensors.begin();
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
digitalWrite(relay1, HIGH);
digitalWrite(relay2, HIGH);
      
ads1115.begin();
ads1115.setGain(GAIN_ONE); 
    
Wire.begin();  

Serial.begin(9600);
lcd.begin();

Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
timer.setInterval(1000L, sendSensor);
}

void loop(){

  digitalWrite(trigPin, LOW);  // Added this line
  delayMicroseconds(2); // Added this line
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10); // Added this line
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
 
adcPH = ads1115.readADC_SingleEnded(0);
pHValue = (adcPH - 2196.84) / 440.283;

adcntu = ads1115.readADC_SingleEnded(1);                   
ntu = (adcntu - 22000.0) / 1;

sensors.requestTemperatures();
TempC = sensors.getTempCByIndex(0); // Celcius

if(ntu < 0){
 ntu = 0; 
}

ntux = map(adcntu, 3000, 0, 0, 100);

if(ntux < 0){
 ntux = 0; 
}

  lcd.setCursor(0,0);
  lcd.print("Ph: ");
  lcd.print(pHValue);
  lcd.print(" ");
  lcd.print(distance);
  lcd.print("    ");
   
  lcd.setCursor(0,1);
  lcd.print("NTU: ");
  lcd.print(ntux);
  lcd.print(" ");
  lcd.print(TempC);
  lcd.print("   ");
  
if(distance <= 10){
 digitalWrite(relay1, HIGH);
}
if(distance > 10){
 digitalWrite(relay1, LOW);
}

if(ntux <= 10){
 digitalWrite(relay2, HIGH);
}
if(ntux > 10){
 digitalWrite(relay2, LOW);
}

  Blynk.run();
  timer.run();
  delay(200);
}


3. VIDEO HASILNYA



Monitoring PH dan Turbidity via Wireless HC-12 LCD TFT ILI9341 Arduino

Monitoring PH dan Turbidity via Wireless HC-12 LCD TFT ILI9341 Arduino


        Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang bisa memonitoring ph dan turbidity secara realtime dengan sistem wireless. alat ini menggunakan indikator berupa lampu ac 220 volt yang berwarna. interface yang dipakai juga menggunakan lcd tft ili9341. untuk lebih jelasnya berikut adalah koding dan komponennya.


1. Komponen 




2. Program Transmitter

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#include <SoftwareSerial.h>

SoftwareSerial mySerial (2, 3);

float pHValue;
int tds;
int adctds;
int adcPH;

void setup() {
 mySerial.begin(9600); 
 Serial.begin(9600); 
 pinMode(2, INPUT);
 pinMode(3, OUTPUT);
}

void loop() {

 adcPH = analogRead(A0); //menggunakan pin A0 untuk membaca output sensor pH
 pHValue = (adcPH - 1093.4) / -30.897;

 adctds = analogRead(A1);             
 tds = map(adctds, 900, 1, 0, 100);

mySerial.print("*");
mySerial.print(pHValue * 100);
mySerial.print(",");
mySerial.print(tds);
mySerial.println("#");

//Serial.print(pHValue);
//Serial.print(" ");
//Serial.println(tds);

delay(100);
}


3. Program Receiver

#include <Arduino.h>
#include <math.h>
#include <Wire.h>
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include <SoftwareSerial.h>

#define TFT_CS         10
#define TFT_DC         8
//#define TFT_LED      5v
#define TFT_RST        9
#define TFT_MOSI       11
#define TFT_CLK        13
#define TFT_MISO       12

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);

SoftwareSerial mySerial (2, 3);

int value1;
int value2;
float ph = 0;
int tds = 0;
int datain1;
int datain2;

int ssrmerahph = 4;
int ssrhijauph = A1;
int ssrkuningph = A2;
int ssrtdsmerah = 7;
int ssrtdshijau = A0;

String dataIn;
String dt[10];
int i;
boolean parsing=false;

void setup(){

pinMode(ssrmerahph,OUTPUT);
pinMode(ssrhijauph,OUTPUT);
pinMode(ssrkuningph,OUTPUT);
pinMode(ssrtdsmerah,OUTPUT);
pinMode(ssrtdshijau,OUTPUT);

  digitalWrite(ssrmerahph,HIGH);
  digitalWrite(ssrhijauph,HIGH);
  digitalWrite(ssrkuningph,HIGH);
  digitalWrite(ssrtdsmerah,HIGH);
  digitalWrite(ssrtdshijau,HIGH);
  
  tft.begin();
  tft.fillScreen(ILI9341_BLACK);
  tft.setTextSize(5);
  tft.setRotation(3); 
  
 dataIn=""; 
// Serial.begin(9600);
 mySerial.begin(9600); 
 pinMode(2, INPUT);
 pinMode(3, OUTPUT);
}

void loop(){

delay(200);

  tft.setCursor(10, 10);
  tft.setTextColor(ILI9341_YELLOW,ILI9341_BLACK);  
  tft.print("PH: ");  
  tft.print(ph);    
  tft.print("  "); 

  tft.setCursor(10, 70);
  tft.setTextColor(ILI9341_GREEN,ILI9341_BLACK);  
  tft.print("TDS: ");  
  tft.print(tds);  
  tft.print("  "); 

if(ph > 8){
  digitalWrite(ssrmerahph,LOW);
  digitalWrite(ssrhijauph,HIGH);
  digitalWrite(ssrkuningph,HIGH);
}

if(ph < 6){
  digitalWrite(ssrmerahph,HIGH);
  digitalWrite(ssrhijauph,HIGH);
  digitalWrite(ssrkuningph,LOW);
}
  
if((ph >= 6)&&(ph <= 8)){
  digitalWrite(ssrmerahph,HIGH);
  digitalWrite(ssrhijauph,LOW);
  digitalWrite(ssrkuningph,HIGH);
}

if(tds < 5){
  digitalWrite(ssrtdsmerah,HIGH);
  digitalWrite(ssrtdshijau,LOW);
}

if(tds >= 5){
  digitalWrite(ssrtdsmerah,LOW);
  digitalWrite(ssrtdshijau,HIGH);
}


//secara wireless
if(mySerial.available()>0) {
    char inChar = (char)mySerial.read();
    dataIn += inChar;
    if (inChar == '\n') {
    parsing = true;
  }
}

if(parsing){
    parsingData();
   
    ph = datain1/100.0;
    tds = datain2;
     
    parsing=false;
    dataIn="";
  } 

}

void parsingData(){
int j=0;

//kirim data yang telah diterima sebelumnya
//Serial.print("data masuk : ");
//Serial.print(dataIn);
//Serial.print("\n");

//inisialisasi variabel, (reset isi variabel)
dt[j]="";
//proses parsing data
for(i=1;i<dataIn.length();i++){
//pengecekan tiap karakter dengan karakter (#) dan (,)
if ((dataIn[i] == '#') || (dataIn[i] == ','))
{
//increment variabel j, digunakan untuk merubah index array penampung
j++;
dt[j]="";       //inisialisasi variabel array dt[j]
}
else
{
//proses tampung data saat pengecekan karakter selesai.
dt[j] = dt[j] + dataIn[i];
}
}

 datain1 = dt[0].toInt();
 datain2 = dt[1].toInt();

}


4. VIDEO HASILNYA



Monitoring Kecepatan Kendaraan Sensor Piezoelectic via Bluetooth Android MIT Inventor

Monitoring Kecepatan Kendaraan Sensor Piezoelectic via Bluetooth Android MIT Inventor 


           Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat mengukur kecepatan kendaraan menggunakan piezoelectric yang dipasang pada pembatas jalan. alat ini dimonitoring dengan menggunakan handphone via bluetooth dengan software MIT Inventor. untuk lebih jelasnya berikut adalah koding dan skemanya.


a. Skema




b. Koding Android





c. Program Arduino IDE

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#include <SoftwareSerial.h>

SoftwareSerial mySerial (2, 3);

float kecepatan; 
float t;
int tanda,counter;

void setup() {
 mySerial.begin(9600); 
 Serial.begin(9600); 
 lcd.begin();
 lcd.clear();
 lcd.noCursor();
 pinMode(2, INPUT);
 pinMode(3, OUTPUT);
}

void loop() {

  int v1 = analogRead(A0);
  int v2 = analogRead(A1);

  lcd.setCursor(0, 0);
  lcd.print("1/2= ");
  lcd.print(v1);
  lcd.print("/");
  lcd.print(v2);
  lcd.print("  ");
     
  lcd.setCursor(0, 1);
  lcd.print("V= ");
  lcd.print(kecepatan);
  lcd.print(" m/s ");

if((v1 > 10)&&(tanda == 0)){
  tanda = 1;
  lcd.setCursor(15, 0);
  lcd.print("c");
  }

if((v2 > 15)&&(tanda == 1)){
  tanda = 0;
  t = counter / 1000.0;
  counter = 0;
  kecepatan = 5.0/t;
  lcd.setCursor(15, 0);
  lcd.print(" ");
  }

if(tanda == 1){
counter++;  

mySerial.print(kecepatan);
delay(100);
}



d. VIDEO HASILNYA



Timer Tamiya 3 Lap dan 3 Jalur / Line + Fitur Lastlap

Timer Tamiya 3 Lap dan 3 Jalur / Line + Fitur Lastlap


          Pada kesempatan kali ini saya akan menjelaska mengenai bagaimana cara membuat sebuah alat timer lomba tamiya untuk 3 jalur / Line, alat ini juga dibekali fitur lastlap jika terjadi mobil tamiya yang keluar jalur maka tombol lastlap diaktifkan. untuk lebih jelasnya berikut adalah koding dan skemanya.

  
1. Skema




2. 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 WAKTU_TAMPIL_JAM      10    //detik
#define WAKTU_TAMPIL_KALENDAR 5     //detik

#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];
char lineBuff2[20];

int lineA;
int lineB;
int lineC;
int mulai;
int seconds;
int cs;
long start_time = 0;
int lapa,lapb,lapc;
int btlastlap = 5;
int btlastlapx;
int led1 = A0;
int led2 = A1;
int led3 = A2;

void ScanDMD()
{
  dmd.scanDisplayBySPI();
}

void setup(void)
{
pinMode(2,INPUT);
pinMode(3,INPUT);
pinMode(4,INPUT);
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
pinMode(led3,OUTPUT);
pinMode(btlastlap,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);
lineB = digitalRead(3);
lineC = digitalRead(4);
btlastlapx = digitalRead(btlastlap);


if(btlastlapx == 1){
if((lineA == 0)&&(lineB == 1)&&(lineC == 1)&&(mulai == 1)){
lapa++;
delay(100);
}

if((lineA == 1)&&(lineB == 0)&&(lineC == 1)&&(mulai == 1)){
lapb++;
delay(100);
}

if((lineA == 1)&&(lineB == 1)&&(lineC == 0)&&(mulai == 1)){
lapc++;
delay(100);
}

if((lineA == 0)&&(lineB == 0)&&(lineC == 1)&&(mulai == 1)){
lapa++;
lapb++;
delay(100);
}

if((lineA == 0)&&(lineB == 1)&&(lineC == 0)&&(mulai == 1)){
lapa++;
lapc++;
delay(100);
}

if((lineA == 1)&&(lineB == 0)&&(lineC == 0)&&(mulai == 1)){
lapb++;
lapc++;
delay(100);
}

if((lineA == 0)&&(lineB == 0)&&(lineC == 0)&&(mulai == 1)){
lapa++;
lapb++;
lapc++;
delay(100);
}

//=============================================
if(lapa > 2){
dmd.clearScreen( true );   
sprintf(lineBuff2, "WIN", lapa, lapb, lapc);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 3,  3, lineBuff2, strlen(lineBuff2), GRAPHICS_NORMAL);  
delay(2000);
dmd.clearScreen( true );  
hasila();  
}

if(lapb > 2){
dmd.clearScreen( true );   
sprintf(lineBuff2, "WIN", lapa, lapb, lapc);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 3,  3, lineBuff2, strlen(lineBuff2), GRAPHICS_NORMAL);  
delay(2000);
dmd.clearScreen( true );  
hasilb();  
}

if(lapc > 2){
dmd.clearScreen( true );   
sprintf(lineBuff2, "WIN", lapa, lapb, lapc);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 3,  3, lineBuff2, strlen(lineBuff2), GRAPHICS_NORMAL);  
delay(2000);
dmd.clearScreen( true );  
hasilc();  
}
}

//===========================================================
if(btlastlapx == 0){
if((lineA == 0)&&(lineB == 1)&&(lineC == 1)&&(mulai == 1)){
dmd.clearScreen( true );   
sprintf(lineBuff2, "WIN", lapa, lapb, lapc);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 3,  3, lineBuff2, strlen(lineBuff2), GRAPHICS_NORMAL);  
delay(2000);
dmd.clearScreen( true );  
digitalWrite(led1,HIGH);
digitalWrite(led2,LOW);
digitalWrite(led3,LOW);
hasila();  
delay(100);
}

if((lineA == 1)&&(lineB == 0)&&(lineC == 1)&&(mulai == 1)){
dmd.clearScreen( true );   
sprintf(lineBuff2, "WIN", lapa, lapb, lapc);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 3,  3, lineBuff2, strlen(lineBuff2), GRAPHICS_NORMAL);  
delay(2000);
dmd.clearScreen( true );  
digitalWrite(led1,LOW);
digitalWrite(led2,HIGH);
digitalWrite(led3,LOW);
hasilb();  
delay(100);
}

if((lineA == 1)&&(lineB == 1)&&(lineC == 0)&&(mulai == 1)){
dmd.clearScreen( true );   
sprintf(lineBuff2, "WIN", lapa, lapb, lapc);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 3,  3, lineBuff2, strlen(lineBuff2), GRAPHICS_NORMAL);  
delay(2000);
dmd.clearScreen( true );  
digitalWrite(led1,LOW);
digitalWrite(led2,LOW);
digitalWrite(led3,HIGH);
hasilc();  
delay(100);
}
}

//=============================================
lineA = digitalRead(2);
lineB = digitalRead(3);
lineC = digitalRead(4);

if((lineA == 0)&&(mulai == 0)){
  delay(200);
  mulai = 1;
  start_time = millis();  
}  

if((lineB == 0)&&(mulai == 0)){
  delay(200);
  mulai = 1;
  start_time = millis();  

if((lineC == 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( 37,  3, lineBuff, strlen(lineBuff), GRAPHICS_NORMAL);  

sprintf(lineBuff2, "%d/%d/%d ", lapa, lapb, lapc);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 3,  3, lineBuff2, strlen(lineBuff2), GRAPHICS_NORMAL);  
//===========================================================================

}

void hasila(){
sprintf(lineBuff, "%d:%d ", seconds, cs);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 35,  3, lineBuff, strlen(lineBuff), GRAPHICS_NORMAL);  

sprintf(lineBuff2, " A", lapa, lapb, lapc);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 3,  3, lineBuff2, strlen(lineBuff2), GRAPHICS_NORMAL);  

hasila();  
}


void hasilb(){
sprintf(lineBuff, "%d:%d ", seconds, cs);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 35,  3, lineBuff, strlen(lineBuff), GRAPHICS_NORMAL);  

sprintf(lineBuff2, " B", lapa, lapb, lapc);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 3,  3, lineBuff2, strlen(lineBuff2), GRAPHICS_NORMAL);  

hasilb();  
}


void hasilc(){
sprintf(lineBuff, "%d:%d ", seconds, cs);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 35,  3, lineBuff, strlen(lineBuff), GRAPHICS_NORMAL);  

sprintf(lineBuff2, " C", lapa, lapb, lapc);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 3,  3, lineBuff2, strlen(lineBuff2), GRAPHICS_NORMAL);  

hasilc();  
}



3. VIDEO HASILNYA