#include <Wire.h>
#include <LiquidCrystal_I2C.h> // LCD_I2C模組程式庫
LiquidCrystal_I2C lcd(0x27, 20, 4);
uint8_t up[8] = {
0b00000000,
0b00000100,
0b00001110,
0b00011111,
0b00000100,
0b00000100,
0b00000000,
0b00000000,
};
uint8_t down[8] = {
0b00000000,
0b00000100,
0b00000100,
0b00011111,
0b00001110,
0b00000100,
0b00000000,
0b00000000,
};
uint8_t left[8] = {
0b00000000,
0b00000100,
0b00001100,
0b00011111,
0b00001100,
0b00000100,
0b00000000,
0b00000000,
};
uint8_t right[8] = {
0b00000000,
0b00000100,
0b00000110,
0b00011111,
0b00000110,
0b00000100,
0b00000000,
0b00000000,
};
int x,y;
int dir=1;
int r=0,c=0;
int count=0;
void setup() {
lcd.init();
lcd.backlight();
lcd.createChar(1, up);
lcd.createChar(2, down);
lcd.createChar(3, left);
lcd.createChar(4, right);
}
void loop() {
y=analogRead(A0);
x=analogRead(A1);
delay(10);
if(y>700)
dir=1;
if(y<300)
dir=2;
if(x>700)
dir=3;
if(x<300)
dir=4;
lcd.setCursor(c,r);
switch(dir)
{
case 1:
lcd.print("\x01");
break;
case 2:
lcd.print("\x02");
break;
case 3:
lcd.print("\x03");
break;
case 4:
lcd.print("\x04");
break;
}
count++;
if(count>=30)
{
count=0;
lcd.setCursor(c,r);
lcd.print(' ');
switch(dir)
{
case 1:
r=r-1;
if(r<0)
r=3;
break;
case 2:
r=r+1;
if(r>3)
r=0;
break;
case 3:
c=c-1;
if(c<0)
c=19;
break;
case 4:
c=c+1;
if(c>19)
c=0;
break;
}
}
}