Advertisement
ZulRocky

Modul 9

Mar 3rd, 2020
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. #include <LiquidCrystal_SR_LCD3.h>
  2. const int PIN_LCD_STROBE = 2;
  3. const int PIN_LCD_DATA = 3;
  4. const int PIN_LCD_CLOCK = 4;
  5. LiquidCrystal_SR_LCD3 lcd(PIN_LCD_DATA, PIN_LCD_CLOCK, PIN_LCD_STROBE);
  6.  
  7.  
  8. int ProxSensor = A0;
  9. int Buzzer = A1;
  10. int inputVal = 0;
  11. int button=7, led=9, led2=10,led3=11;
  12. int ok=0;
  13. int no=0;
  14. void setup() {
  15. pinMode(Buzzer, OUTPUT);
  16. pinMode(ProxSensor, INPUT);
  17. pinMode(button, INPUT);
  18. pinMode(led, OUTPUT);
  19. pinMode(led2, OUTPUT);
  20. pinMode(led3, OUTPUT);
  21. Serial.begin(9600);
  22. lcd.begin(16,2);
  23. lcd.home();
  24. }
  25. void loop() {
  26. ok=digitalRead(button);
  27.  
  28. if(ok==LOW){
  29. goto menu1;
  30. }
  31.  
  32. menu0:
  33. no=0;
  34. lcd.print("HELLO");
  35. digitalWrite(led, LOW);
  36. while(1){
  37. ok=digitalRead(button);
  38. if(ok==LOW){
  39. delay(300);
  40. goto menu1;
  41. }
  42. }
  43.  
  44. menu1:
  45. while(1){
  46. lcd.clear();
  47. if(no==2){
  48. int prox = analogRead(ProxSensor);
  49. analogWrite(led, 255-prox/4);
  50. lcd.setCursor(10,0);
  51. lcd.print(prox);
  52. }
  53. if (digitalRead(ProxSensor) == LOW) {
  54. Serial.println("Terdeteksi Halangan!");
  55. lcd.setCursor(0,0);
  56. lcd.print("Terdeteksi");
  57. lcd.setCursor(0,1);
  58. lcd.print("Halangan");
  59. if(no==1 || no==3){
  60. digitalWrite(Buzzer, HIGH);
  61. if(no==3){
  62. digitalWrite(led,HIGH);
  63. digitalWrite(led2,HIGH);
  64. digitalWrite(led3,HIGH);
  65. delay(1000);
  66. digitalWrite(Buzzer, LOW);
  67. digitalWrite(led,LOW);
  68. digitalWrite(led2,LOW);
  69. digitalWrite(led3,LOW);
  70. delay(900);
  71. }
  72. }
  73. inputVal = analogRead(ProxSensor);
  74. Serial.println(inputVal);
  75. delay(100);
  76. }
  77. if (digitalRead(ProxSensor) == HIGH) {
  78. Serial.println("Clear!");
  79. lcd.setCursor(0,0);
  80. lcd.print("Clear!");
  81. digitalWrite(Buzzer, LOW);
  82. inputVal = analogRead(ProxSensor);
  83. Serial.println(inputVal);
  84. digitalWrite(led, LOW);
  85. digitalWrite(led2, LOW);
  86. digitalWrite(led3, LOW);
  87. delay(100);
  88. }
  89. ok=digitalRead(button);
  90. if(ok==LOW){
  91. delay(300);
  92. no++;
  93. if(no==4){
  94. lcd.clear();
  95. goto menu0;
  96. }else{
  97. goto menu1;
  98. }
  99. }
  100. }
  101.  
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement