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