Arduino UNO digunakan untuk membaca nilai data axis X dan Y yang merupakan output data dari joystick yang hasilnya ditampilkan pada LCD.
Kebutuhan Hardware
- Modul Joystick Dual Axis
- Modul LCD 2x16
- Modul Arduino UNO
- Power supply +5 Volt
Modul Joystick Dual Axis | Source
Diagram Blok
Schematic
Koneksi Arduino UNO dengan LCD
Koneksi Modul Joystick
Source Code/Sketch
#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
int joyX = A0;
int joyY = A1;
int value1 = 0;
int value2 = 0;
int SW = 8;
int led = 0;
void setup() {
pinMode(13, OUTPUT);
pinMode(SW, INPUT);
digitalWrite(SW, HIGH);
lcd.begin(16, 2);
lcd.print("Baca Joystick");
}
void loop() {
value1 = analogRead(joyX);
value2 = analogRead(joyY);
lcd.setCursor(0 ,1);
//X=46 --> 1018
lcd.print("X:");
lcd.print(value1);
//Y=46 --> 1018
lcd.print(" Y:");
lcd.print(value2);
lcd.print(" ");
if(digitalRead(SW)==0){
delay(100);
led=!led;
digitalWrite(13, led);
}
delay(100);
}
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
int joyX = A0;
int joyY = A1;
int value1 = 0;
int value2 = 0;
int SW = 8;
int led = 0;
void setup() {
pinMode(13, OUTPUT);
pinMode(SW, INPUT);
digitalWrite(SW, HIGH);
lcd.begin(16, 2);
lcd.print("Baca Joystick");
}
void loop() {
value1 = analogRead(joyX);
value2 = analogRead(joyY);
lcd.setCursor(0 ,1);
//X=46 --> 1018
lcd.print("X:");
lcd.print(value1);
//Y=46 --> 1018
lcd.print(" Y:");
lcd.print(value2);
lcd.print(" ");
if(digitalRead(SW)==0){
delay(100);
led=!led;
digitalWrite(13, led);
}
delay(100);
}
Jalannya Alat
LCD menampilkan nilai X dan Y, sedangkan tombol/SW akan menghidupkan dan mematikan LED 13 Arduino.
Video untuk Project V - 30. Interfacing Arduino dengan Analog Joystick
KONTAK KAMI 085743320570 (adi sanjaya)
No comments:
Post a Comment