def run(args): with open(args.cart, "rb") as fp: data = fp.read() cart = Cart(data) cpu = CPU(cart, debug=args.debug_cpu) lcd = None if not args.headless: lcd = LCD(cpu, debug=args.debug_gpu) running = True clock = 0 while running: try: if not cpu.halt and not cpu.stop: clock += cpu.tick() else: clock += 4 #if cpu.halt: # print("CPU halted, waiting for interrupt") # break #if cpu.stop: # print("CPU stopped, waiting for button") # break except OpNotImplemented as e: running = False # print(cpu) print(e, file=sys.stderr) except (Exception, KeyboardInterrupt) as e: running = False dump(cpu, str(e)) # 4MHz / 60FPS ~= 70000 instructions per frame if clock > 70224 or clock > 1000: # print(last_frame - time.time()) clock = 0 if lcd and not lcd.update(): running = False if lcd: lcd.close()
L2.eev.add(0.17) L2.update_total() L2.set_date_time() lcd.update(L2) raw_input() for _ in range(10): L2.i.set_image(L2.ch1 - 6, L2.ch1 - 6, 'purple_r.jpg') time.sleep(.5) lcd.draw(L2) L2.i.set_image(L2.ch1 - 6, L2.ch1 - 6, 'gray_r.jpg') time.sleep(.5) lcd.draw(L2) L2.clear_all() lcd.draw(L2) for i in range(10): L2.ewv.add(0.01) L2.egv.add(1) L2.eev.add(0.17) L2.update_total() L2.set_date_time() lcd.update(L2) raw_input() lcd.close()
screen = Screen(["Dog", "Cat", "Moose", "Potatoes"], lcd) screen.display() is_press = False while run: if gpio.input(5) == False: if is_press == False: screen.moveDown() screen.display() is_press = True else: print("STOP") elif gpio.input(5) == True: is_press = False elif gpio.input(12) == False: if is_press == False: screen.moveUp() screen.display() is_press = True else: print("STOP") elif gpio.input(6) == True: is_press = False while run: sleep(1) lcd.close() print("Done")
class Ticker: def __init__(self, symbol: str) -> None: self.symbol = symbol print("init BTC ticker...") self.lcd = LCD() self.client = Client(api_key=API_KEY, api_secret=API_SECRET) # init screen self.lcd.clear() self.lcd.writeLine1("BTC / EUR") self.running: bool = False self.currentPrice: float = 0 def getMethod(self): """ Poll price by sending an active request to the binance server """ while True: try: #client.ping() #price: dict = client.get_avg_price(symbol="BTCEUR") price: dict = self.client.get_symbol_ticker(symbol=self.symbol) except KeyboardInterrupt: print("exiting....") sys.exit() self.lcd.writeLine2(price.get("price")) time.sleep(1) #print(price.get("price")) def wsMethod(self): """ Get current price by using a websocket connection """ bm = BinanceSocketManager(self.client) signal.signal(signal.SIGINT, self._closeConnection) signal.signal(signal.SIGTERM, self._closeConnection) bm.start_trade_socket(self.symbol, self._wsCallback) bm.start() self.running = True self.writeThread = Thread(target=self.writeLCD) self.writeThread.start() def _wsCallback(self, msg: dict): self.currentPrice = float(msg.get("p")) print(f'Preis: {self.currentPrice}') def writeLCD(self): while self.running: print(f"LCD {self.currentPrice}") self.lcd.writeLine2(str(self.currentPrice)) time.sleep(1) def _closeConnection(self, signum, frame): print("exiting...") self.running = False reactor.stop() self.writeThread.join() self.lcd.close()