Skip to content

Instantly share code, notes, and snippets.

@lol97
Created August 4, 2018 16:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lol97/ecaee3183e9b327273fad25ac94cad11 to your computer and use it in GitHub Desktop.
Save lol97/ecaee3183e9b327273fad25ac94cad11 to your computer and use it in GitHub Desktop.
Send Data to Arduino at serial Communication
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