Код: Выделить всё
###python code###
import serial
import time
def iniciar():
try:
arduino = serial.Serial("COM7", 9600)
time.sleep(2)
while True:
a = int(input(": "))
arduino.write(b'a')
if a == "x":
break
finally:
arduino.close()
#while True:
iniciar()
Код: Выделить всё
#include
Servo ON;
Servo OFF;
char pr;
void setup() {
Serial.begin(9600);
OFF.attach(8);
ON.attach(9);
}
void loop() {
if(Serial.available()>0){
pr = Serial.read();
if(pr == 'b'){
ON.write(0); // tell servo to go to a particular angle
delay(1000);
ON.write(90);
delay(500);
}
if(pr == 'a'){
OFF.write(0); // tell servo to go to a particular angle
delay(1000);
OFF.write(90);
delay(500);
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/791 ... ith-python
Мобильная версия