def __init__(self): iv = interrupt_vector.InterruptVector() btns = buttons.Buttons(iv, conf.config().get('buttons', {})) weather_devices = weather_stations.WeatherStations(conf.config().get( 'weather_stations', [])) self.target_loop_time = conf.config().get("main_loop", {}).get("interval", 32) self.minimum_loop_time = conf.config().get("main_loop", {}).get("minimum", 1) self.thinkers = [ iv, # buttons, switches, et al. btns, weather_devices ] routes = [('GET', '/weather_stations', 0, weather_devices.list), ('GET', '/weather_stations/(.+)', 1, weather_devices.show)] self.poller = select.poll() if not hasattr(self.poller, 'ipoll'): import uselect self.poller = uselect.poll() self.server = htserver.HttpServer(self.poller, routes, conf.config().get('http_server', {}))
def __init__(self): Gtk.Window.__init__(self, title='AryaLinux Installer') self.context = dict() self.context['main_window'] = self self.context['installation_cmd'] = [ '/usr/bin/sudo', '/bin/bash', '/opt/installer-new/backend.sh' ] self.context['install_started'] = False self.header = header.Header() self.vbox = Gtk.VBox(spacing=5) self.stack = stack.Stack(self.context, buttons.prevButton, buttons.nextButton, buttons.installButton) self.buttons = buttons.Buttons(self.context) self.vbox.pack_start(self.header, False, True, 0) self.vbox.pack_start(self.stack, True, True, 0) self.vbox.pack_start(Gtk.HSeparator(), False, True, 0) self.vbox.pack_start(self.buttons, False, True, 0) self.add(self.vbox) # Set half the size of screen and center screen = Gdk.Screen.get_default() self.set_size_request(screen.get_width()/2, screen.get_height()/2) self.set_position(Gtk.WindowPosition.CENTER_ALWAYS) self.set_border_width(5) buttons.cancelButton.connect('clicked', self.confirm_cancellation) self.set_border_width(5) self.context['install_started'] = False self.context['input_started'] = True
def main(): trellis = adafruit_trellism4.TrellisM4Express() trellis.pixels.fill((0, 0, 0)) trellis.pixels.auto_write = False btns = buttons.Buttons(trellis) config = {} try: with open('quickstart_config.csv', 'r') as f: lines = f.readlines() for line in lines: if len(line) <= 4: continue x, y, mod = line[0], line[2], line[4:] if not x.isdigit() or not y.isdigit(): continue x = max(0, min(7, int(x))) y = max(0, min(3, int(y))) mod = ''.join(list(filter(str.isalpha, mod))) if (len(mod) == 0): continue config[(x, y)] = mod except OSError: with open('quickstart_config.csv', 'w') as f: pass if (len(config) == 0): config[(0, 0)] = 'module_list' for p, mod in config.items(): random.seed(hash(mod)) c = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) print(p, c) trellis.pixels[p] = c trellis.pixels.show() available = set(config.keys()) s = frozenset() while len(s) == 0: btns.update() s = btns.pressed() & available time.sleep(0.01) trellis.pixels.auto_write = True deinit_trellis.deinit(trellis) p = s.pop() mod = config[p] print('import ' + mod) mod = __import__(mod) if 'main' in dir(mod): print(mod.__name__ + '.main') mod.main()
def __init__(self, gps_rate=None): # initialize objects self._gui = gui.GUI() self._buttons = buttons.Buttons(on_green=self.green_callback, on_blue=self.blue_callback, on_red=self.red_callback) self.rs = RobotState() print("The first state in the state machine is: %s" % rs.state) self._gps = gps.GPS()
def __init__(self, gps_rate=None): # initialize objects self.stop_blink = threading.Event() self._gui = gui.GUI() self._buttons = buttons.Buttons(on_green=self.green_callback, on_blue=self.blue_callback, on_red=self.red_callback) self.rs = RobotState() print("The first state in the state machine is: %s" % self.rs.state) print("Mac Address: " + gma()) self._gps = gpsCode.GPS()
def run(self): """Run the game""" print("Run the game") pygame.display.init() pygame.init() # button_event = pygame.event.Event(BUTTONEVENT, message="Button Pressed", button_values=[]) try: background_sound = pygame.mixer.Sound("./tetris.ogg") background_sound.play(loops = -1) self.row_sound = pygame.mixer.Sound("./jump.wav") except: pass controls = buttons.Buttons() show_board(self.board) self.running = True pygame.time.set_timer(USEREVENT, 100) # every 100 miliseconds pygame.time.set_timer(USEREVENT+1, 10) # every 10 milliseconds while self.running and not self.ended: event = pygame.event.wait() if event.type == QUIT: self.running = False if event.type == USEREVENT: if self.time_till_next_drop() < 0: if not self.move_snake(): self.lives -= 1 log.debug('Player died! Lives remaining: %s', self.lives) # death_sound.play() if self.lives <= 0: log.debug('Game over') self.ended = True else: # TODO: "Ready?" Message self.new_level() if event.type == USEREVENT+1: for button in self.buttons_pressed(controls.get_buttons()): log.debug("Button pressed %s", button) self.button_event(button) if event.type == KEYDOWN: if event.key == pygame.K_LEFT: self.set_direction(MOVE_L) if event.key == pygame.K_RIGHT: self.set_direction(MOVE_R) if event.key == pygame.K_UP: self.set_direction(MOVE_U) if event.key == pygame.K_DOWN: self.set_direction(MOVE_D) if event.key == pygame.K_q: self.running = False if self.ended: print("Thanks for playing") print("Level: ", self.level) print("Score: ", self.score)
def _server(_): config = { "foo": { "pin": 42, "active": "low", "pull": "high", "udp_target": ["127.0.0.1", 12347], "http_target": ["127.0.0.1", 8080], } } iv = interrupt_vector.InterruptVector() btns = buttons.Buttons(iv, config) btns.buttons[0].pin.poke() iv.think(1) btns.think(1)
from utime import sleep_ms, ticks_ms, ticks_diff import ujson import leds, buttons, msg f = open('settings.json', 'r') configs = ujson.loads(f.read()) print(configs) f.close() Leds = leds.Leds(configs['leds']) Btns = buttons.Buttons(configs['buttons']) Msg = msg.msg(configs['msg'], Leds, Btns) ms_per_frame = int(1000 / configs['fps']) while True: now = ticks_ms() try: Msg.check() Leds.animate() except KeyboardInterrupt: print('Break') break except Exception as e: print(e) pass rest = ticks_diff(ticks_ms(),now) Msg.loadavg = (Msg.loadavg * 0.99) + ((rest/ms_per_frame) * 0.01) if rest < ms_per_frame: sleep_ms(ms_per_frame-rest)
def __init__(self, views): self.buttons = btns.Buttons([10,15,17,27,24,9]) self.views = views
import search, buttons, time, registerUser, registerAuthorizer, lockOutput, irsensor import baseMethods, sys, lcddriver import RPi.GPIO as GPIO display = lcddriver.lcd() search = search.Search() but = buttons.Buttons() lockOutput = lockOutput.LockOutput() irsens=irsensor.Irsens() baseMethod = baseMethods.BaseMethods() count = 0 def sButPressed(title): if title == "Register User": regUser = registerUser.RegisterUser() regUser.main() elif title == "Register Authorizer": regAutho = registerAuthorizer.RegisterAuthorizer() regAutho.main() def mButPressed(): global count count += 1 if count == 1: display.lcd_clear() display.lcd_display_string("Register User",1)
import tkinter as tk import buttons as Bt import logic as Lg root = tk.Tk() root.geometry("514x490") logic = Lg.Logic() board = Bt.Buttons(root, logic) root.mainloop()
# Licensed under GPLv3 (https://www.gnu.org/licenses/gpl.html) from pyo import * from collections import deque import os import time import copy import mcpaccess import patcher import buttons # Setup MCP ADC, Patching System, and Button checking mcp = mcpaccess.MCPAccess() patches = patcher.Patcher() btns = buttons.Buttons() # Setup pyo server s = Server(audio='jack', sr=44100, nchnls=1, duplex=0, jackname='pyo') # Print MIDI input devices midiInputs = pm_get_input_devices() print(midiInputs) # Server config s.setIchnls(0) # Disable audio in, unneeded s.setMidiInputDevice(3) #Set midi device s.boot() #Boot server # Copy output to otherwise unused channel, as only using mono, # but both speakers should output.
def main(): trellis = adafruit_trellism4.TrellisM4Express() trellis.pixels.fill((0,0,0)) trellis.pixels.auto_write = False on_col = (0, 25, 0) alphabet = { 'A': 1959, # 4015, 'B': 4051, # 3922, 'C': 3993, 'D': 3990, 'E': 4057, # 4061, 'F': 4008, # 4010, 'G': 3995, 'H': 3951, 'I': 2553, 'J': 542, # 670, 'K': 3945, 'L': 3857, 'M': 3919, 'N': 3983, # 3975, 'O': 1686, 'P': 4004, 'Q': 1687, 'R': 4005, 'S': 1466, 'T': 2296, 'U': 3871, # 3615, 'V': 3614, 'W': 3887, 'X': 2891, 'Y': 3132, 'Z': 3033, # 2493, '0': 3999, '1': 1521, '2': 2485, '3': 2527, '4': 3631, '5': 3546, '6': 4027, # 1989, '7': 2191, # 2235, '8': 4031, '9': 3551, ' ': 0, '.': 16, ',': 288, '!': 208, '?': 180, ':': 144, ';': 2464, # 416, '\'': 192, '"': 200, # 196, '/': 300, '\\':3105, '<': 592, # 597, '>': 1312, # 1352, '+': 626, '-': 546, '*': 3264, # 1252, '^': 1156, '_': 273, '=': 1365, '(': 1680, ')': 2400, '[': 3984, ']': 2544, '{': 1273, '}': 2548, '#': 1782, # 1791, '%': 2349, '&': 1021, '|': 240, '$': 1266, '@': 1791, # 3831, '~': 612, '`': 2112, } def get_letter(c): c = c.upper() if c not in alphabet: return None b = alphabet[c] return set((2 - i // 4, 3 - i % 4) for i in range(12) if b & (1 << i)) def get_message(m): s = set() for i, c in enumerate(m): s ^= set((p[0] + 4 * i, p[1]) for p in get_letter(c)) return s btns = buttons.Buttons(trellis) pixels_on = get_message('hi') for p in pixels_on: trellis.pixels[p] = on_col fnames = [fname[:-3] for fname in os.listdir('.') if not fname.startswith('.') and fname.endswith('.py') and fname != 'code.py'] index = 0 length = len(fnames[index]) * 4 - 4 dots = get_message(fnames[index]) scroll = 0 while True: btns.update() p = (0, 0) for p in btns.pressed(): if (p[0] == 0 or p[0] == 7): if (p[0] == 0 and scroll - 2 >= 0): scroll -= 2 elif (p[0] == 7 and scroll + 2 <= length): scroll += 2 elif (p[1] == 0 or p[1] == 3): if (p[1] == 0 and index > 0): index -= 1 elif (p[1] == 3 and index < len(fnames)): index += 1 length = len(fnames[index]) * 4 - 4 dots = get_message(fnames[index]) scroll = 0 else: break if (0 < p[0] < 7 and 0 < p[1] < 3): break trellis.pixels.fill((0,0,0)) for dot in dots: if (0 <= dot[0] - scroll < 8 and 0 <= dot[1] < 4): trellis.pixels[dot[0] - scroll, dot[1]] = on_col trellis.pixels.show() time.sleep(0.05) deinit_trellis.deinit(trellis) mod = __import__(fnames[index]) print('import ' + mod.__name__) if 'main' in dir(mod): print(mod.__name__ + '.main') mod.main()