-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnailpolishpicker.py
60 lines (53 loc) · 2.29 KB
/
nailpolishpicker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import serial
import time
file_name = "serial.html" # Once created, open this file in a browser.
# Adapt serial port nr. & baud rate to your system.
serial_port = '/dev/cu.usbserial-023E583A'
baudrate = 115200
page_title = "Nail Polish Picker"
button_pressed = False
button_count = 0
def write_page(data_list):
fo = open(file_name,"w+")
# Start of HTML page.
fo.write("<html><head><title>"+page_title+"</title>") # Page & Head begin.
fo.write("<meta http-equiv='refresh' content='1'>")
fo.write("<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>")
fo.write("<link rel='shortcut icon' href='favicon.ico' />")
fo.write("<link rel='icon' type='image/x-icon' href='favicon.ico' />")
fo.write("<link rel='icon' type='image/png' href='favicon.png' />")
fo.write("</head><body><center><p>"+page_title+"</p>") # Head end, body begin.
img_url = "/Users/Anvi/Downloads/redlicorice.jpeg"
if (int(button_count)/2 % 7 == 0):
img_url = "/Users/Anvi/Downloads/redlicorice.jpeg"
if (int(button_count)/2 % 7 == 1):
img_url = "/Users/Anvi/Downloads/orangedrink.jpeg"
if (int(button_count)/2 % 7 == 2):
img_url = "/Users/Anvi/Downloads/lemonsucker.jpeg"
if (int(button_count)/2 % 7 == 3):
img_url = "/Users/Anvi/Downloads/greentaffy.jpeg"
if (int(button_count)/2 % 7 == 4):
img_url = "/Users/Anvi/Downloads/bluefreezie.jpeg"
if (int(button_count)/2 % 7 == 5):
img_url = "/Users/Anvi/Downloads/purpleslushie.jpeg"
if (int(button_count)/2 % 7 == 6):
img_url = "/Users/Anvi/Downloads/magentajelly.jpeg"
fo.write("<td>"+ "<img src=" + img_url + ">"+"</td>")
fo.write("</html>") # Page end.
# Done, close file.
fo.close()
s = serial.Serial(serial_port,baudrate) # Open serial port.
s.dtr = 0 # Reset Arduino.
s.dtr = 1
print("Waiting for data...")
time.sleep(2) # Wait for Arduino to finish booting.
s.reset_input_buffer() # Delete any stale data.
while 1:
write_page(0)
data_str = s.readline().decode() # Read data & convert bytes to string type.
data_str = data_str.replace(' ','') # Remove whitespace.
data_str = data_str.replace('\r','') # Remove return.
data_str = data_str.replace('\n','') # Remove new line.
button_count = data_str
print(data_str)
write_page(data_str)