如何将arduino代码翻译成python pyfirmata?
我想用pyfirmata将这个Arduino代码翻译成python代码。我该怎么做如何将arduino代码翻译成python pyfirmata?,python,python-3.x,arduino,arduino-uno,firmata,Python,Python 3.x,Arduino,Arduino Uno,Firmata,我想用pyfirmata将这个Arduino代码翻译成python代码。我该怎么做 int sw = 0; void setup() { // put your setup code here, to run once: pinMode(2, INPUT); pinMode(6, OUTPUT); } void loop() { // put your main code here, to run repeatedly: sw = digitalRead(2);
int sw = 0;
void setup() {
// put your setup code here, to run once:
pinMode(2, INPUT);
pinMode(6, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
sw = digitalRead(2);
if (sw == LOW){
digitalWrite(6, LOW);
}
else {
digitalWrite(6, HIGH);
}
}
我试过了
from pyfirmata import Arduino, util
board = Arduino('COM3')
it = util.Iterator(board)
it.start()
button = board.get_pin('d:2:i')
led = board.get_pin('d:6:o')
while True:
sw = button.read()
print(sw)
if sw:
led.write(1)
else:
led.write(0)
但这不起作用,当我打印sw
时,它返回None
然后我试着这样做,但总是返回None
from pyfirmata import Arduino, util, INPUT
board = Arduino('COM3')
it = util.Iterator(board)
it.start()
while True:
board.digital[2].mode = INPUT
board.digital[2].enable_reporting()
print(board.digital[2].read())