Sunday, January 19, 2025

DKS - Sabaku belajar Arduino #7... guna LCD

 




ahad, 19 Jan 2025... sesi kelas Arduino dengan Sabaku.. malam ni belajar guna LCD display... pastu d-kita sambung dengan servo motor guna suis keypada pada LCD shield tu utk kawal pergerakkan motor tuh. antara link yang digunakan :-



/*
Arduino 2x16 LCD - Detect Buttons
modified on 18 Feb 2019
by Saeed Hosseini @ Electropeak
https://electropeak.com/learn/
*/
#include <LiquidCrystal.h>
#include <Servo.h>
int servoPin = 22; 
Servo Servo1; 
//LCD pin to Arduino
const int pin_RS = 8; 
const int pin_EN = 9; 
const int pin_d4 = 4; 
const int pin_d5 = 5; 
const int pin_d6 = 6; 
const int pin_d7 = 7; 
const int pin_BL = 10; 
LiquidCrystal lcd( pin_RS,  pin_EN,  pin_d4,  pin_d5,  pin_d6,  pin_d7);
void setup() {
 Servo1.attach(servoPin);
 lcd.begin(16, 2);
 lcd.setCursor(0,0);
 lcd.print("Electropeak.com");
 lcd.setCursor(0,1);
 lcd.print("Press Key:");
}
void loop() {
 int x;
 x = analogRead (0);
 lcd.setCursor(10,1);
 if (x < 60) {
   lcd.print ("Right ");
      Servo1.write(0); 
   delay(1000); 
   // Make servo go to 90 degrees 
   Servo1.write(90); 
   delay(1000); 
   // Make servo go to 180 degrees 
   Servo1.write(180); 
   delay(1000);
 }
 else if (x < 200) {
   lcd.print ("Up    ");
 }
 else if (x < 400){
   lcd.print ("Down  ");
 }
 else if (x < 600){
   lcd.print ("Left  ");
 }
 else if (x < 800){
   lcd.print ("Select");
 }
}

No comments:

Post a Comment