-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathface2.py
executable file
·157 lines (123 loc) · 3.62 KB
/
face2.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env python
#this is the main brobot face script
#it displays a default face (face 0) until some action occurs
#actions could be push notifications (twitter, irc, btc threshold, boot process, ec)
#trying to keep cpu in mind here because the pi zero is only single core 1ghz.
#animation refreshes need to be scaled back, and "eyes" are only drawn once unless animated.
import math
import unicornhat as unicorn
import time
import sys
import os
import requests
from microdotphat import clear, write_string, scroll, show, set_brightness, WIDTH, HEIGHT
face = 0
#text = "Brobot v1.0 "
btc = 1
twitter = "none"
ipFace = 0
boot=0
unicorn.set_layout(unicorn.AUTO)
unicorn.rotation(0)
unicorn.brightness(0.5)
def set_face( face_status ):
if ( face_status == 0 ):
speed = 5
string = 0
shown = True
strings = ["Brobot", "#Bro", "+plus+", "#Bot"]
#boot eyes
unicorn.set_pixel(1,2,255,0,0)
unicorn.set_pixel(1,3,255,0,0)
unicorn.set_pixel(2,2,255,0,0)
unicorn.set_pixel(2,3,255,0,0)
unicorn.set_pixel(5,2,255,0,0)
unicorn.set_pixel(5,3,255,0,0)
unicorn.set_pixel(6,2,255,0,0)
unicorn.set_pixel(6,3,255,0,0)
unicorn.show()
#boot mouth (brobot fading text)
show()
# Start time. Phase offset by math.pi/2
start = time.time()
while True:
# Fade the brightness in/out using a sine wave
b = (math.sin((time.time() - start) * speed) + 1) / 2
set_brightness(b)
# At minimum brightness, swap out the string for the next one
if b < 0.002 and shown:
clear()
write_string(strings[string], kerning=False)
string += 1
string %= len(strings)
show()
shown = False
# At maximum brightness, confirm the string has been shown
if b > 0.998:
shown = True
# Sleep a bit to save resources, this wont affect the fading speed
time.sleep(0.01)
elif ( face_status == 1 ):
#ipface eyes
unicorn.set_pixel(1,2,255,0,0)
unicorn.set_pixel(1,3,255,0,0)
unicorn.set_pixel(2,2,255,0,0)
unicorn.set_pixel(2,3,255,0,0)
unicorn.set_pixel(5,2,255,0,0)
unicorn.set_pixel(5,3,255,0,0)
unicorn.set_pixel(6,2,255,0,0)
unicorn.set_pixel(6,3,255,0,0)
#ipface eyebrows
unicorn.set_pixel(1,0,255,0,0)
unicorn.set_pixel(2,0,255,0,0)
unicorn.set_pixel(5,0,255,0,0)
unicorn.set_pixel(6,0,255,0,0)
unicorn.set_pixel(0,1,255,0,0)
unicorn.set_pixel(7,1,255,0,0)
#draw eyes (square beady)
unicorn.show()
#draw mouth (scrolling text)
ipv4 = os.popen('ip addr show wlan0').read().split("inet ")[1].split("/")[0]
text = ipv4+ " "
write_string(text, offset_x=0)
while True:
scroll()
show()
time.sleep(0.08)
elif ( face_status == 2 ):
#btc eyes
#left eye
unicorn.set_pixel(0,0,255,0,0)
unicorn.set_pixel(0,3,255,0,0)
unicorn.set_pixel(1,1,255,0,0)
unicorn.set_pixel(1,2,255,0,0)
unicorn.set_pixel(2,1,255,0,0)
unicorn.set_pixel(2,2,255,0,0)
#right eye
unicorn.set_pixel(5,1,255,0,0)
unicorn.set_pixel(5,2,255,0,0)
unicorn.set_pixel(6,1,255,0,0)
unicorn.set_pixel(6,2,255,0,0)
unicorn.set_pixel(7,0,255,0,0)
unicorn.set_pixel(7,3,255,0,0)
#draw eyes
unicorn.show()
#btc mouth
r = requests.get('http://api.bitcoincharts.com/v1/weighted_prices.json')
data = r.json()
averageBTC = data['USD']['24h']
text = averageBTC + " "
write_string(text, offset_x=0)
while True:
scroll()
show()
time.sleep(0.08)
while True:
if (boot == 1):
face = 0
elif (ipFace == 1):
face = 1
elif (btc == 1 ):
face = 2
# Face variable set, send to function for processing
set_face( face )