2017-06-04 11 views
0

PythonにリンクされたLEDを点滅させるためのサンプルコードを書きました。コードは私に何かエラーを投げかけていませんが、LEDが点滅していません。助言がありますか?Arduino-PythonでリンクされたLEDの点滅

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のコード: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

、あなたが

digitalWrite(50,LOW); 

digitalWrite(255,HIGH); 
を呼び出します

ですが、digitalWriteの最初のパラメータはピン番号です。これをピン10と定義します.50と255を10に変更するだけで、ローとハイの信号を出力します。

+0

ありがとうございました。 –

関連する問題