Arduino & pyhton

so I wanted to make a simple click with arduino uno when the LDR sense light, but since I can't use mouse.click() with uno I though I could use python to do it. here is the codes
arduino code :

const int ldrpin = A2;

void setup(){
pinMode(ldrpin, INPUT);
 Serial.begin(9600);
}

void loop() {

  int ldrstat = analogRead(ldrpin);
  Serial.println(ldrstat);

  if (ldrstat >= 4){
    delay(500);
  }
}

python code :

from socket import timeout
from pynput.mouse import Button, Controller
import serial
import time
mouse = Controller()
serialport = serial.Serial('COM3', baudrate=9600, timeout=1)


aruinodata = serialport.readline(3).decode('ascii')

    print(aruinodata)
if aruinodata >= str(4) : 
     mouse.click(Button.left, 1)

the problem with the python code is that it dosen't click unless the last value in the run is >=4 ,so if in the middle of the run it detected 4 it won't click even after the run
.? ends. how can I make it click instantly when it detects 4

Just send one byte when you need to click, don’t overflow the serial port with useless info

1 Like

I still need to make python click when detects 4 ... if I did send 1 byte if this byte wasn't by the end of the run it won't click

Does this click for you?

The rest is more just getting input byte by byte as they come and trigger the mouse click each time you get an ‘x’ or whatever you decide to send only when it’s needed

send only 4+

if (ldrstat >= 4)
Serial.print(ldrstat);

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.