Skip to content

Instantly share code, notes, and snippets.

@kanokkorn
Last active July 12, 2017 07:07
Show Gist options
  • Save kanokkorn/19826ff265c411abe73900fbf1556293 to your computer and use it in GitHub Desktop.
Save kanokkorn/19826ff265c411abe73900fbf1556293 to your computer and use it in GitHub Desktop.
nanpy sample code for windows
from nanpy import *
from colorama import Fore, init, AnsiToWin32
import time, sys
connection = SerialManager(device='COM5:')
a = ArduinoApi(connection=connection)
a.pinMode(13, a.OUTPUT)
print("Type ON, OFF, BLINK to open LED or EXIT to exit the program")
init(autoreset=True)
stream = AnsiToWin32(sys.stderr).stream
while 1:
p_in = input("Status: ")
if(p_in == "ON"):
a.digitalWrite(13, a.HIGH)
print(Fore.GREEN + "LED: ON",file=stream)
elif(p_in == "OFF"):
a.digitalWrite(13, a.LOW)
print(Fore.RED + "LED: OFF",file=stream)
elif (p_in == "BLINK"):
blink = int(input("How many times ? : "))
L_delay = float(input("Delay between blink : "))
for i in range(blink):
a.digitalWrite(13, a.HIGH)
time.sleep(L_delay)
a.digitalWrite(13, a.LOW)
time.sleep(L_delay)
elif(p_in == "EXIT"):
yn = input("Are you sure ? : ")
if(yn == "YES"):
exit()
if(yn == "NO"):
pass
else:
print("Type the correct function")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment