1#include <Wire.h>
2#include <LiquidCrystal_I2C.h>
3
4LiquidCrystal_I2C lcd(0x27,16,2);
5
6#define joyX A0
7#define joyY A1
8
9int button=2;
10int buttonState = 0;
11int buttonState1 = 0;
12
13void setup() {
14 pinMode(7,OUTPUT);
15 pinMode(button,INPUT);
16 digitalWrite(button, HIGH);
17 lcd.init();
18 lcd.backlight();
19 pinMode(8,OUTPUT);
20 pinMode(9,OUTPUT);
21 pinMode(10,OUTPUT);
22 pinMode(11,OUTPUT);
23}
24
25void loop() {
26
27 int xValue = analogRead(joyX);
28 int yValue = analogRead(joyY);
29
30 buttonState = digitalRead(button);
31 if (xValue>=0 && yValue<=10)
32 {
33 digitalWrite(10, HIGH);
34 lcd.setCursor(0,0);
35 lcd.print("left ");
36 }
37 else{digitalWrite(10, LOW);}
38
39 if (xValue<=10 && yValue>=500)
40 {
41 digitalWrite(11, HIGH);
42 lcd.setCursor(0,0);
43 lcd.print("down ");
44 }
45 else{digitalWrite(11, LOW);}
46
47 if (xValue>=1020 && yValue>=500)
48 {
49 digitalWrite(9, HIGH);
50 lcd.setCursor(0,0);
51 lcd.print("up ");
52 }
53 else{digitalWrite(9, LOW);}
54
55 if (xValue>=500 && yValue>=1020)
56 {
57 digitalWrite(8, HIGH);
58 lcd.setCursor(0,0);
59 lcd.print("right");
60 }
61 else{digitalWrite(8, LOW);}
62
63 if (xValue>=1020 && yValue>=1020)
64 {
65 digitalWrite(9, LOW);
66 digitalWrite(8, LOW);
67 }
68}