Created
August 4, 2018 16:21
-
-
Save lol97/ecaee3183e9b327273fad25ac94cad11 to your computer and use it in GitHub Desktop.
Send Data to Arduino at serial Communication
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 | |
arduino = serial.Serial('com4',9600) | |
def ledController(): | |
cmd = input('type on/off/dc : ') | |
cmd = str.lower(cmd) | |
if(cmd == "on"): | |
arduino.write('H'.encode()) | |
print("Lampu Nyala") | |
elif(cmd == "off"): | |
arduino.write('L'.encode()) | |
print("Lampu Mati") | |
elif(cmd == "dc"): | |
arduino.close() | |
print("Lampu Mati") | |
else: | |
print("Ngetik yang bener pilih on / off / dc") | |
try: | |
while (True): | |
ledController() | |
except KeyboardInterrupt: | |
arduino.close() | |
print('has disconnected') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment