Вот ардуино код :
void setup()
{
Serial.begin(9600);
pinMode(9,INPUT);
digitalWrite(9,HIGH);
}
int prev_state=0;
void loop() {
int z=0,xpos=0,ypos=0;
int x=analogRead(A0);
int y=analogRead(A1);
int sensitivity=10;
if(x>=550)
xpos=map(x,550,1023,0,sensitivity);
if(x<=450)
xpos=map(x,450,0,0,-sensitivity);
if(y>=550)
ypos=map(y,550,1023,0,sensitivity);
if(y<=450)
ypos=map(y,450,0,0,-sensitivity);
int curr_state=digitalRead(9);
if(curr_state==1 && prev_state==0)
z=1;
else
z=0;
if(xpos!=0 or ypos!=0 or z==1)
{
Serial.print(xpos);
Serial.print(":");
Serial.print(ypos);
Serial.print(":");
Serial.println(z);
}
prev_state=curr_state;
delay(10);
}
А вот Python код
import mouse, sys
import time
import serial
mouse.FAILSAFE=False
ArduinoSerial=serial.Serial('com3',9600)
time.sleep(1)
while 1:
data=str(ArduinoSerial.readline())
(x,y,z)=data.split(":")
(X,Y)=mouse.get_position()
(x,y)=(int(x),int(y))
mouse.move(X+x,Y-y)
if '1' in z:
mouse.click(button="left")
Вот ошибка (она python`е):
Traceback (most recent call last):
File "c:\Users\Admin\AppData\Local\Programs\Python\Python311\Jmouse.py", line 13, in <module>
(x,y)=(int(x),int(y))
^^^^^^
ValueError: invalid literal for int() with base 10: "b'8"