import serial
from turtle import Turtle, Screen
def HVmove(T, S, forwardAmount):
for i in range (forwardAmount):
T.forward(i)
S .update()
def JoyMove (T, S, ser):
xy= ser.readline()
xy=xy.decode('utf-8')
#xy=xy.rstlip()
xy=xy.split(",")
horizontal=int(xy[0])
vertical =int(xy[1])
if (horizontal >0):
T.setheading(0)
HVmove(T, S, horizontal)
elif (horizontal <0):
T.setheading(180)
HVmove(T, S, horizontal * -1)
elif (vertical < 0):
T.setheading (90)
HVmove(T, S, vertical * -1)
elif (vertical >0):
T.setheading (270)
HVmove (T, S,vertical)
T = Turtle()
S = Screen()
ser = serial.Serial('COM3')
T.shape("turtle")
T. speed(0)
S. tracer(0,0)
while True:
JoyMove(T, S, ser)
int verti=A0;
int hori=A1;
void setup() {
Serial.begin(9600);
}
void loop() {
String vertical = String(map((analogRead(verti) + 18), 0, 1023, -3, +3));
String horizontal = String(map((analogRead(hori) -18), 0, 1023, -3, +3));
if (vertical != "0" || horizontal != "0") {
String dataToSend ="";
dataToSend += vertical;
dataToSend += ",";
dataToSend += horizontal;
Serial.println(dataToSend);
delay(40);
}}
'Arduino<>Python' 카테고리의 다른 글
PA005. 아두이노> 파이션 Mouse (0) | 2021.03.02 |
---|---|
PA004. 파이션 이두이노 버튼 turtle head 제어 (0) | 2021.03.01 |
PA002. 파이션아두이노 버튼그래픽(1) (0) | 2021.03.01 |
PA001.tultle(x,y) 좌표 (0) | 2021.03.01 |
PA001. LED On Off (0) | 2021.02.21 |