闪烁通过Arduino-Python链接的LED

时间:2017-06-04 08:51:04

标签: arduino pyserial

我写了一个示例代码,用于闪烁链接到Python的LED。代码没有给我任何错误,但LED没有闪烁。有什么建议吗?

Python代码:

//element(*, ItemType)

Arduino代码:

import serial #import the pyserial library
connected = False #this will represent whether or not ardunio is connected to the system
ser = serial.Serial("COM3",9600) #open the serial port on which Ardunio is connected to, this will coommunicate to the serial port where ardunio is connected, the number which is there is called baud rate, this will provide the speed at which the communication happens
while not connected:#you have to loop until the ardunio gets ready, now when the ardunio gets ready, blink the led in the ardunio
    serin = ser.read()
    connected = True
ser.write('1') #this will blink the led in the ardunio
while ser.read() == '1': #now once the led blinks, the ardunio gets message back from the serial port and it get freed from the loop!
    ser.read()
print('Program is done')
ser.close()

1 个答案:

答案 0 :(得分:2)

在arduino代码中,您可以调用

digitalWrite(50,LOW);

digitalWrite(255,HIGH);

但是digitalWrite的第一个参数是引脚编号,您将其定义为引脚10.只需将50和255更改为10,因为您希望输出低信号和高信号。