Untitled
unknown
plain_text
3 years ago
1.1 kB
10
Indexable
int LED = 11;
int BUTTON = 12;
void setup() {
// put your setup code here, to run once:
pinMode(BUTTON,INPUT_PULLUP);
pinMode(LED,OUTPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
if(!digitalRead(BUTTON)){
Serial.print(1);
delay(100);
}
if (Serial.available()){
String num = Serial.readString();
Serial.print(num);
if(num=="2"){
digitalWrite(LED,HIGH);
}
else if(num=="3"){
digitalWrite(LED,LOW);
}
}
}
from pynput.keyboard import Key, Controller
import serial
import time
arduino = serial.Serial(port='/dev/ttyUSB0', baudrate=9600)
keyboard = Controller()
try:
while True:
readArduino = arduino.read().decode()
print(readArduino)
arduino.write("2".encode())
time.sleep(2)
arduino.write("3".encode())
if(readArduino=="1"):
print("done")
keyboard.press(Key.right)
time.sleep(0.1)
keyboard.release(Key.right)
except KeyboardInterrupt:
arduino.close()
Editor is loading...