Created
January 11, 2013 01:28
-
-
Save jreisstudio/4507236 to your computer and use it in GitHub Desktop.
Python + Arduino on/off the LED.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define LED 13 | |
// Using http://slides.justen.eng.br/python-e-arduino as refference | |
void setup() { | |
pinMode(LED, OUTPUT); | |
Serial.begin(9600); | |
} | |
void loop() { | |
if (Serial.available()) { | |
char serialListener = Serial.read(); | |
if (serialListener == 'H') { | |
digitalWrite(LED, HIGH); | |
} | |
else if (serialListener == 'L') { | |
digitalWrite(LED, LOW); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import serial # you need to install the pySerial :pyserial.sourceforge.net | |
import time | |
# your Serial port should be different! | |
arduino = serial.Serial('/dev/tty.usbmodem1411', 9600) | |
def onOffFunction(): | |
command = raw_input("Type something..: (on/ off / bye )"); | |
if command =="on": | |
print "The LED is on..." | |
time.sleep(1) | |
arduino.write('H') | |
onOffFunction() | |
elif command =="off": | |
print "The LED is off..." | |
time.sleep(1) | |
arduino.write('L') | |
onOffFunction() | |
elif command =="bye": | |
print "See You!..." | |
time.sleep(1) | |
arduino.close() | |
else: | |
print "Sorry..type another thing..!" | |
onOffFunction() | |
time.sleep(2) #waiting the initialization... | |
onOffFunction() |
Hey ,
Thank you for the code
if you use python 3 at least you will get also a problem with
arduino.write('L')
change it to
arduino.write(b'YourStringText ')
THANK YOU !
как запустить его?!??!?!?!
откуда его запускать
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It was a problem with the identation in the code, sorry.