Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal_SR_LCD3.h>
- const int PIN_LCD_STROBE = 2;
- const int PIN_LCD_DATA = 3;
- const int PIN_LCD_CLOCK = 4;
- LiquidCrystal_SR_LCD3 lcd(PIN_LCD_DATA, PIN_LCD_CLOCK, PIN_LCD_STROBE);
- int ProxSensor = A0;
- int Buzzer = A1;
- int inputVal = 0;
- int button=7, led=9, led2=10,led3=11;
- int ok=0;
- int no=0;
- void setup() {
- pinMode(Buzzer, OUTPUT);
- pinMode(ProxSensor, INPUT);
- pinMode(button, INPUT);
- pinMode(led, OUTPUT);
- pinMode(led2, OUTPUT);
- pinMode(led3, OUTPUT);
- Serial.begin(9600);
- lcd.begin(16,2);
- lcd.home();
- }
- void loop() {
- ok=digitalRead(button);
- if(ok==LOW){
- goto menu1;
- }
- menu0:
- no=0;
- lcd.print("HELLO");
- digitalWrite(led, LOW);
- while(1){
- ok=digitalRead(button);
- if(ok==LOW){
- delay(300);
- goto menu1;
- }
- }
- menu1:
- while(1){
- lcd.clear();
- if(no==2){
- int prox = analogRead(ProxSensor);
- analogWrite(led, 255-prox/4);
- lcd.setCursor(10,0);
- lcd.print(prox);
- }
- if (digitalRead(ProxSensor) == LOW) {
- Serial.println("Terdeteksi Halangan!");
- lcd.setCursor(0,0);
- lcd.print("Terdeteksi");
- lcd.setCursor(0,1);
- lcd.print("Halangan");
- if(no==1 || no==3){
- digitalWrite(Buzzer, HIGH);
- if(no==3){
- digitalWrite(led,HIGH);
- digitalWrite(led2,HIGH);
- digitalWrite(led3,HIGH);
- delay(1000);
- digitalWrite(Buzzer, LOW);
- digitalWrite(led,LOW);
- digitalWrite(led2,LOW);
- digitalWrite(led3,LOW);
- delay(900);
- }
- }
- inputVal = analogRead(ProxSensor);
- Serial.println(inputVal);
- delay(100);
- }
- if (digitalRead(ProxSensor) == HIGH) {
- Serial.println("Clear!");
- lcd.setCursor(0,0);
- lcd.print("Clear!");
- digitalWrite(Buzzer, LOW);
- inputVal = analogRead(ProxSensor);
- Serial.println(inputVal);
- digitalWrite(led, LOW);
- digitalWrite(led2, LOW);
- digitalWrite(led3, LOW);
- delay(100);
- }
- ok=digitalRead(button);
- if(ok==LOW){
- delay(300);
- no++;
- if(no==4){
- lcd.clear();
- goto menu0;
- }else{
- goto menu1;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement