In python, I need:
1. win32gui module: to get the mouse position
2. pySerial module: to send the data to arduino
Here is my python code
import win32gui
import time
import serial
ser = serial.Serial(4)
while (True):
x,y = win32gui.GetCursorPos()
time.sleep(0.2)
pos=int(179*x/1599)
ser.write(chr(pos))
print x,y
And my code in arduino
#include
Servo myservo;
int val;
void setup(){
myservo.attach(9);
Serial.begin(9600);
}
void loop(){
if(Serial.available()){
val=Serial.read();
myservo.write(val);
delay(15);
}
}
0 意見:
張貼留言