2017-06-04 48 views
0

我寫了一個閃爍鏈接到Python的指示燈的示例代碼。該代碼不會引發任何錯誤,但LED不閃爍。有什麼建議麼?閃爍通過Arduino-Python鏈接的指示燈

Python代碼:

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() 

的Arduino代碼:

void setup() { 
Serial.begin(9600); 
pinMode(10,OUTPUT); 
Serial.write('1'); 
} 
void loop() { 
if(Serial.available()>0){ 
    digitalWrite(255,HIGH); 
    delay(50); 
    digitalWrite(50,LOW); 
    delay(50); 
    digitalWrite(255,HIGH); 
    delay(50); 
    digitalWrite(50,LOW); 
    delay(50); 
    digitalWrite(255,HIGH); 
    delay(50); 
    digitalWrite(50,LOW); 
    Serial.read(); 
} 
else{ 
    Serial.available()==0; 
} 
} 

回答

2

在Arduino的代碼,你叫

digitalWrite(50,LOW); 

digitalWrite(255,HIGH); 

但digitalWrite的第一個參數是引腳編號,您將其定義爲引腳10.只需將50和255更改爲10,因爲這是您希望將低電平信號和高電平信號輸出到的位置。

+0

非常感謝。 –