|
4 | 4 | import board
|
5 | 5 | import neopixel
|
6 | 6 | from rpi_ws281x import Color
|
| 7 | +import board |
| 8 | +import neopixel |
| 9 | +import time |
| 10 | +import os |
| 11 | +from digitalio import DigitalInOut, Direction, Pull |
| 12 | +from multiprocessing import Process |
| 13 | +import sys |
| 14 | +import serial |
| 15 | +import time |
| 16 | +from gpiozero import LED |
| 17 | +from time import sleep |
| 18 | +from PyP100 import PyP100 |
| 19 | +p100 = PyP100.P100("192.168.43.55", "CENSORED", "CENSORED") |
| 20 | +p100.handshake() |
| 21 | +p100.login() |
| 22 | + |
| 23 | +led = LED(17) |
7 | 24 |
|
8 | 25 | pixel_pin = board.D18
|
9 | 26 |
|
|
14 | 31 | pixel_pin, num_pixels, brightness=0.2, auto_write=False, pixel_order=ORDER
|
15 | 32 | )
|
16 | 33 |
|
17 |
| -def wheel(pos): |
18 |
| - # Input a value 0 to 255 to get a color value. |
19 |
| - # The colours are a transition r - g - b - back to r. |
20 |
| - if pos < 0 or pos > 255: |
21 |
| - r = g = b = 0 |
22 |
| - elif pos < 85: |
23 |
| - r = int(pos * 3) |
24 |
| - g = int(255 - pos * 3) |
25 |
| - b = 0 |
26 |
| - elif pos < 170: |
27 |
| - pos -= 85 |
28 |
| - r = int(255 - pos * 3) |
29 |
| - g = 0 |
30 |
| - b = int(pos * 3) |
31 |
| - else: |
32 |
| - pos -= 170 |
33 |
| - r = 0 |
34 |
| - g = int(pos * 3) |
35 |
| - b = int(255 - pos * 3) |
36 |
| - return (r, g, b) if ORDER in (neopixel.RGB, neopixel.GRB) else (r, g, b, 0) |
37 |
| - |
| 34 | +async def turnOffHeater(): |
38 | 35 |
|
39 |
| -async def turnOffFan(): |
40 |
| - p = SmartPlug("192.168.1.144") |
| 36 | + p = SmartPlug("CENSORED") |
41 | 37 |
|
42 | 38 | await p.update()
|
43 | 39 |
|
44 | 40 | await p.turn_off()
|
45 | 41 |
|
46 |
| -async def turnOnFan(): |
47 |
| - p = SmartPlug("192.168.1.144") |
| 42 | +async def turnOnHeater(): |
| 43 | + p = SmartPlug("CENSORED") |
48 | 44 |
|
49 | 45 | await p.update()
|
50 | 46 |
|
51 | 47 | await p.turn_on()
|
| 48 | + |
| 49 | +async def turnOffFan(): |
| 50 | + |
| 51 | + p100.turnOff() |
| 52 | + |
| 53 | +async def turnOnFan(): |
| 54 | + |
| 55 | + p100.turnOn() |
| 56 | + |
| 57 | +print('START') |
| 58 | + |
| 59 | + |
| 60 | +rocket = 0 |
| 61 | + |
| 62 | +def func1(): |
| 63 | + global rocket |
| 64 | + print ('start func1') |
| 65 | + import serial |
| 66 | + try: |
| 67 | + print('i tried1') |
| 68 | + ser = serial.Serial('/dev/ttyACM1', 9600, timeout=1) |
| 69 | + time.sleep(2) |
| 70 | + ser.write(b'start') |
| 71 | + except: |
| 72 | + print('errrrrrooorrrrr1') |
| 73 | + try: |
| 74 | + print('i tried2') |
| 75 | + ser1 = serial.Serial('/dev/ttyACM0', 9600, timeout=1) |
| 76 | + time.sleep(2) |
| 77 | + ser1.write(b'start') |
| 78 | + except: |
| 79 | + print('errrrrrooorrrrr2') |
| 80 | + try: |
| 81 | + print('i tried2') |
| 82 | + ser1 = serial.Serial('/dev/ttyACM2', 9600, timeout=1) |
| 83 | + time.sleep(2) |
| 84 | + ser1.write(b'start') |
| 85 | + except: |
| 86 | + print('errrrrrooorrrrr2') |
| 87 | + |
| 88 | + |
| 89 | + |
| 90 | +def func2(): |
| 91 | + global rocket |
| 92 | + start = time.time() |
| 93 | + os.system("sudo -u pi bash -c 'cvlc movie.mov'") |
| 94 | + |
| 95 | +def func3(): |
| 96 | + global rocket |
| 97 | + |
| 98 | + |
52 | 99 |
|
53 |
| -def colorWipe(strip, color, color2, color3, wait_ms=50): |
54 |
| - for i in range(num_pixels): |
55 |
| - strip.fill(color) |
56 |
| - while True: |
57 |
| - for i in range(num_pixels): |
58 |
| - strip[i] = color2 |
59 |
| - strip.show() |
60 |
| - time.sleep(wait_ms/10000.0) |
61 |
| - for i in range(num_pixels): |
62 |
| - strip[i] = color3 |
63 |
| - strip.show() |
64 |
| - time.sleep(wait_ms/10000.0) |
65 |
| - for i in range(num_pixels): |
66 |
| - strip[i] = color |
67 |
| - strip.show() |
68 |
| - time.sleep(wait_ms/10000.0) |
69 |
| - strip.clear() |
70 |
| - |
71 |
| -colorWipe(pixels, Color(40, 0, 0), Color(40, 5, 0), Color(40, 10, 0)) |
| 100 | +while True: |
| 101 | + import urllib.request |
| 102 | + import json |
| 103 | + with urllib.request.urlopen('https://climatator-web.vercel.app/api/status') as response: |
| 104 | + res = json.loads(response.read().decode("utf-8")) |
| 105 | + print(res) |
| 106 | + if res['video'] == 1: |
| 107 | + print('hi!') |
| 108 | + import serial |
| 109 | + try: |
| 110 | + print('i tried1') |
| 111 | + ser = serial.Serial('/dev/ttyACM1', 9600, timeout=1) |
| 112 | + time.sleep(2) |
| 113 | + ser.write(b'start') |
| 114 | + except: |
| 115 | + print('errrrrrooorrrrr1') |
| 116 | + try: |
| 117 | + print('i tried2') |
| 118 | + ser1 = serial.Serial('/dev/ttyACM0', 9600, timeout=1) |
| 119 | + time.sleep(2) |
| 120 | + ser1.write(b'start') |
| 121 | + except: |
| 122 | + print('errrrrrooorrrrr2') |
| 123 | + time.sleep(13) |
| 124 | + try: |
| 125 | + asyncio.run(turnOnHeater()) |
| 126 | + except: |
| 127 | + print('Heated Did Not Activate') |
| 128 | + time.sleep(10) |
| 129 | + led.on() |
| 130 | + sleep(0.5) |
| 131 | + led.off() |
| 132 | + sleep(0.5) |
| 133 | + led.on() |
| 134 | + sleep(0.5) |
| 135 | + led.off() |
| 136 | + sleep(0.5) |
| 137 | + led.on() |
| 138 | + sleep(0.5) |
| 139 | + led.off() |
| 140 | + sleep(0.5) |
| 141 | + sleep(6) |
| 142 | + led.on() |
| 143 | + sleep(0.5) |
| 144 | + led.off() |
| 145 | + sleep(0.5) |
| 146 | + led.on() |
| 147 | + sleep(0.5) |
| 148 | + led.off() |
| 149 | + sleep(0.5) |
| 150 | + led.on() |
| 151 | + sleep(0.5) |
| 152 | + led.off() |
| 153 | + sleep(0.5) |
| 154 | + led.on() |
| 155 | + sleep(0.5) |
| 156 | + led.off() |
| 157 | + sleep(0.5) |
| 158 | + led.on() |
| 159 | + sleep(0.5) |
| 160 | + led.off() |
| 161 | + sleep(0.5) |
| 162 | + led.on() |
| 163 | + sleep(0.5) |
| 164 | + led.off() |
| 165 | + sleep(0.5) |
| 166 | + led.on() |
| 167 | + sleep(0.5) |
| 168 | + led.off() |
| 169 | + sleep(0.5) |
| 170 | + led.on() |
| 171 | + sleep(0.5) |
| 172 | + led.off() |
| 173 | + sleep(0.5) |
| 174 | + led.on() |
| 175 | + sleep(0.5) |
| 176 | + led.off() |
| 177 | + sleep(0.5) |
| 178 | + led.on() |
| 179 | + sleep(0.5) |
| 180 | + led.off() |
| 181 | + sleep(0.5) |
| 182 | + sleep(23) |
| 183 | + try: |
| 184 | + asyncio.run(turnOffHeater()) |
| 185 | + except: |
| 186 | + print('Could not turn off heater') |
| 187 | + try: |
| 188 | + asyncio.run(turnOnFan()) |
| 189 | + except: |
| 190 | + print('Could not turn on fan') |
| 191 | + led.on() |
| 192 | + sleep(0.5) |
| 193 | + led.off() |
| 194 | + sleep(0.5) |
| 195 | + led.on() |
| 196 | + sleep(0.5) |
| 197 | + led.off() |
| 198 | + sleep(0.5) |
| 199 | + led.on() |
| 200 | + sleep(0.5) |
| 201 | + led.off() |
| 202 | + sleep(0.5) |
| 203 | + led.on() |
| 204 | + sleep(0.5) |
| 205 | + led.off() |
| 206 | + sleep(0.5) |
| 207 | + led.on() |
| 208 | + sleep(0.5) |
| 209 | + led.off() |
| 210 | + sleep(0.5) |
| 211 | + led.on() |
| 212 | + sleep(0.5) |
| 213 | + led.off() |
| 214 | + sleep(0.5) |
| 215 | + led.on() |
| 216 | + sleep(0.5) |
| 217 | + led.off() |
| 218 | + sleep(0.5) |
| 219 | + led.on() |
| 220 | + sleep(0.5) |
| 221 | + led.off() |
| 222 | + sleep(0.5) |
| 223 | + led.on() |
| 224 | + sleep(0.5) |
| 225 | + led.off() |
| 226 | + sleep(0.5) |
| 227 | + led.on() |
| 228 | + sleep(0.5) |
| 229 | + led.off() |
| 230 | + sleep(0.5) |
| 231 | + sleep(28) |
| 232 | + try: |
| 233 | + asyncio.run(turnOffFan()) |
| 234 | + except: |
| 235 | + print('Could not turn off fan') |
| 236 | + |
| 237 | + urllib.request.urlopen('https://climatator-web.vercel.app/api/finished') |
0 commit comments