I tried to make a Python script that sends a message to my arduino uno r4 when I click my mouse the arduino should power pin 11 when the mouse is clicked and unpower pin 11 when the mouse gets released. I just can’t get it to work. If there’s a better solution or you know how to help feel free to help.
i used a script from a tutorial i found:
phyton:
.
.
.
import serial
import time
serialcomm = serial.Serial(‘COM7’, 9600)
serialcomm.timeout = 1
while True:
i = input("Enter Input: ").strip()
if i == "Done":
print('finished')
break
serialcomm.write(i.encode())
time.sleep(0.5)
print(serialcomm.readline().decode('ascii'))
serialcomm.close()
.
.
.
Arduino:
“String incomingByte ;
void setup() {
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
if (Serial.available() > 0) {
incomingByte = Serial.readStringUntil(‘\n’);
if (incomingByte == "on") {
digitalWrite(11, HIGH);
Serial.write("Led on");
}
else if (incomingByte == "off") {
digitalWrite(11, LOW);
Serial.write("Led off");
}
else{
Serial.write("invald input");
}
}
}
]