Translate

Simulasi Timer Count Down ARDUINO Proteus

Simulasi Timer Count Down ARDUINO Proteus


      Pada kesempatan kali ini saya akan menjelaskan mengenai sebuah alat simulasi dengan menggunakan software proteus 7. Alat ini berfungsi untuk timer mundur dengan beberapa pilihan waktu. ada beberapa buah tombol yang mana tiap tombol mewakili waktu tertentu. untuk lebih jelasnya berikut adalah programnya.



a. Program Arduino IDE

#include "Wire.h"
//#include <LiquidCrystal_I2C.h>
#include <LiquidCrystal.h>
//LiquidCrystal_I2C lcd(0x27, 16, 2);
LiquidCrystal lcd(16,17,18,19,20,21);

int led1 = 2;
int led2 = 3;
int led3 = 4;
int led4 = 5;
int led5 = 6;
int led6 = 7;
int btreset = 8;

int btonoff = 14;

int onoff = 0;

int detik;
int menit;
int mulaix;

int x = 0;

int dipsw1 = 9;
int dipsw2 = 10;
int dipsw3 = 11;
int dipsw4 = 12;

int sw1 = 0;
int sw2 = 0;
int sw3 = 0;
int sw4 = 0;

int counter = 0;
int jalan;
int jalanx;
int waktu;

int mark = 0; 

void setup(void){

  lcd.begin(16,2);
  lcd.clear();
  lcd.noCursor();

Serial.begin(9600);

//indikator
pinMode(led1,OUTPUT);
digitalWrite(led1,HIGH);

pinMode(led2,OUTPUT);
pinMode(led3,OUTPUT);
pinMode(led4,OUTPUT);
pinMode(led5,OUTPUT);
pinMode(led6,OUTPUT);

pinMode(btreset,INPUT);

pinMode(dipsw1,INPUT);
pinMode(dipsw2,INPUT);
pinMode(dipsw3,INPUT);
pinMode(dipsw4,INPUT);

pinMode(btonoff,INPUT);

digitalWrite(btreset,HIGH);
digitalWrite(dipsw1,HIGH);
digitalWrite(dipsw2,HIGH);
digitalWrite(dipsw3,HIGH);
digitalWrite(dipsw4,HIGH);
digitalWrite(btonoff,HIGH);
  
}

void loop(void){
//Serial.println("utama");


onoff = digitalRead(btonoff);

if(onoff == 1){
//Serial.println("aktif");

digitalWrite(led6,LOW);

sw1 = digitalRead(dipsw1);
sw2 = digitalRead(dipsw2);
sw3 = digitalRead(dipsw3);
sw4 = digitalRead(dipsw4);

if((sw1 == 1)&&(sw2 == 1)&&(sw3 == 1)&&(sw4 == 1)){
delay(200);
waktu = 0;
lcd.setCursor(0,1);
lcd.print("TS=0M");
}

if((sw1 == 0)&&(sw2 == 1)&&(sw3 == 1)&&(sw4 == 1)){
delay(200);
waktu = 60;
menit = 1;
lcd.setCursor(0,1);
lcd.print("TS=1M");
}

if((sw1 == 1)&&(sw2 == 0)&&(sw3 == 1)&&(sw4 == 1)){
delay(200);
waktu = 120;
menit = 2;
lcd.setCursor(0,1);
lcd.print("TS=2M");
}

if((sw1 == 1)&&(sw2 == 1)&&(sw3 == 0)&&(sw4 == 1)){
delay(200);
waktu = 180;
menit = 3;
lcd.setCursor(0,1);
lcd.print("TS=3M");
}

if((sw1 == 1)&&(sw2 == 1)&&(sw3 == 1)&&(sw4 == 0)){
delay(200);
waktu = 240;
menit = 4;
lcd.setCursor(0,1);
lcd.print("TS=4M");
}

counter = 0;
jalan = waktu / 1; 
jalanx = jalan + 10;

digitalWrite(led3,LOW);
digitalWrite(led4,LOW);

//Serial.println(waktu);

if(waktu > 0){
delay(200);  
mulai();

}

}


if(onoff == 0){
//Serial.println("non-aktif");
digitalWrite(led6,HIGH);
digitalWrite(led3,LOW);  
digitalWrite(led4,LOW);
}


  
}



void mulai(){
//Serial.println("mulai");

lcd.setCursor(0,0);
lcd.print("FATIGUE  WARNING");
lcd.setCursor(8,1);
lcd.print("TR=");
lcd.print(menit);
lcd.print(":");
lcd.print(detik);
lcd.print(" ");


if((detik <= 0)&&(menit > 0)){
detik = 59;
menit--;
}

if((detik < 0)&&(menit == 0)){
detik = 0;  
lcd.clear();
return; 
}


onoff = digitalRead(btonoff);

if(onoff == 0){
lcd.clear();  
detik = 0;
return;
}  

detik--;
   
x = digitalRead(btreset);  

if((x == 0)&&(mark == 0)){
  mark = 1;
  delay(200);
  //if(x == 1){
  //Serial.println("kena reset");
  digitalWrite(led5,HIGH);
  delay(1000);
  digitalWrite(led5,LOW);
  lcd.clear();
  detik = 0;
  return;
  //}
}


if((x == 1)&&(mark == 1)){
  delay(200);
  mark = 0;  
}

counter++;
//Serial.println(counter);

if (counter >= jalan){
digitalWrite(led3,HIGH);   
digitalWrite(led2,LOW);
delay(500);
digitalWrite(led3,LOW);
digitalWrite(led2,LOW);
delay(500);
}
if (counter < jalan){
digitalWrite(led3,LOW);
digitalWrite(led2,HIGH);
delay(500);
digitalWrite(led2,LOW);
delay(500);
}

if(counter >= jalanx){
digitalWrite(led4,HIGH);
}
if(counter < jalanx){
digitalWrite(led4,LOW);
}

mulai();
}





b. VIDEO HASILNYA






    

No comments:

Post a Comment