def __init__(self): # the lcd screen self.screen = i2c_lcd.lcd() # the 3 buttons self.middle_clicks = 0 # used for exiting application left_button = 19 # BCM pin of the left button middle_button = 13 # BCM pin of the middle button right_button = 6 # BCM pin of the right button GPIO.setmode(GPIO.BCM) GPIO.setup(left_button, GPIO.IN, pull_up_down=GPIO.PUD_UP) # left GPIO.setup(middle_button, GPIO.IN, pull_up_down=GPIO.PUD_UP) # middle GPIO.setup(right_button, GPIO.IN, pull_up_down=GPIO.PUD_UP) # right # when a button is pressed, the callback method is called in a seperate thread GPIO.add_event_detect(left_button, GPIO.FALLING, callback=self.left_button_press, bouncetime=300) GPIO.add_event_detect(right_button, GPIO.FALLING, callback=self.right_button_press, bouncetime=300) GPIO.add_event_detect(middle_button, GPIO.FALLING, callback=self.middle_button_press, bouncetime=300) # what page is displayed at the moment self.index = 0 # content to display on each page self.pages = []
def main(): global lcd global process global threads now = datetime.now().strftime('%Y_%m_%d_%H%M%S') logging.basicConfig(filename='/home/pi/logs/radio_log_' + now + '.log', level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') lcd = i2c_lcd.lcd() process = start_stream(get_current_station_url()) t1 = threading.Thread(target=extract_stream_title, name='extract_thread') t1.daemon = True threads.append(t1) t1.start() t2 = threading.Thread(target=display_station, args=[get_current_station_name()], name='display_thread') threads.append(t2) t2.start() t3 = threading.Thread(target=handle_rotary_encoder, name='rotary_thread') threads.append(t3) t3.start() t4 = threading.Thread(target=handle_volume_rotary_encoder, name='rotary_volume_thread') threads.append(t4) t4.start() t5 = threading.Thread(target=handle_ir_remote, name='ir_remote_thread') threads.append(t5) t5.start()
def _load_hardware(self): address = self._address self._device['device'] = i2c_lcd.lcd(address[0]) # Hack to have better control on the I2C bus. Close old smbus. And use new one (smbus2) self._device['device'].lcd_device.bus.close() self._device['device'].lcd_device.bus = smbus2.SMBus( 1 if len(address) == 1 else int(address[1])) self.width = self.WIDTH self.height = self.HEIGHT
def main(): '''This function manages the mainline logic of the program ''' # HOST = '' # Available for all interaces HOST = '192.168.0.24' PORT = 8888 #PRESET # 0. Instantiation of the lcd class lcd = i2c_lcd.lcd() lcd.backlight_on(True) # 1. Instantiation of the socket class SocketServer = socket.socket(socket.AF_INET, socket.SOCK_STREAM) print('Socket is created') # 2. Being prepared to receive data from the client try: SocketServer.bind((HOST, PORT)) except: print("Binding failed") SocketServer.close() sys.exit() print('Socket binding completed') # 3. Start listening from the client SocketServer.listen(1) print("Server is waiting for connection") while True: # 4. Socket starts to communicate conn, addr = SocketServer.accept() print("Connected with " + addr[0] + ': ' + str(addr[1])) msg = conn.recv(1024) lcd.lcd_clear() # 5. Return the state of the socket conn.sendall("Successfully sent".encode()) # 6. Display encoded_data = msg.decode() if len(encoded_data) <= 16: lcd.lcd_display_string(encoded_data, 1) elif len(encoded_data) > 16: lcd.lcd_display_string(encoded_data[:16], 1) lcd.lcd_display_string(encoded_data[16:], 2) del (msg, encoded_data) #memory managementexit try: if keyboard.is_pressed('q'): # if key 'q' is pressed print('END THE SOCKET SERVER!') break # finishing the loop else: pass except: pass # 7. Close the socket conn.close() SocketServer.close() lcd.lcd_clear() lcd.backlight_on(False)
def __init__(self): self.lcd = i2c_lcd.lcd()
import i2c_lcd from time import * mylcd = i2c_lcd.lcd() mylcd.lcd_display_string("Hello World!", 1)
def init_lcd(self): self.lcd = i2c_lcd.lcd(addr=self.config['lcd_address']) self.print_start_message()
def __init__(self, header=''): super().__init__() self.lcd = lcd() self.header = header
now = datetime.datetime.now() start = ceil_dt(now, delta) # inicia em horarios 'redondos' # verifica se opcao lcd esta habilitada if (config['LCDConfig']['enable'] == 'true'): import i2c_lcd refresh_lcd = datetime.timedelta( seconds=int(config['LCDConfig']['refresh'])) INTERVAL_LCD = refresh_lcd.total_seconds() INTERVAL_START = (start - now).total_seconds() REP_run = int(INTERVAL // INTERVAL_LCD) # qtde rep ate salvar leitura REP_start = int( INTERVAL_START // INTERVAL_LCD ) # valor inicial de REP para salvar em horarios 'redondos' #lcd = lcd_config() lcd = i2c_lcd.lcd(pi, width=16) counter = 0 first_run = True else: # aguarda o proximo horario inteiro do intervalo para comecar time.sleep( (start - now).total_seconds()) # Overall INTERVAL second polling. next_reading = time.time() while True: data_atual = data_hora() if (config['SensorConfig']['sensor'] == 'DHT22'): s.trigger() time.sleep(0.2) temperature = s.temperature()
global pages global index if pages[index] == 'Quit': _thread.interrupt_main() def refresh_screen(): global pages global index screen.lcd_clear() screen.lcd_display_string("Pagina:", 1) screen.lcd_display_string(pages[index], 2) try: screen = i2c_lcd.lcd() GPIO.setmode(GPIO.BCM) GPIO.setup(left_button, GPIO.IN, pull_up_down=GPIO.PUD_UP) # left GPIO.setup(middle_button, GPIO.IN, pull_up_down=GPIO.PUD_UP) # middle GPIO.setup(right_button, GPIO.IN, pull_up_down=GPIO.PUD_UP) # right GPIO.add_event_detect(left_button, GPIO.FALLING, callback=left_button_press, bouncetime=200) # bouncetime = x ms GPIO.add_event_detect(right_button, GPIO.FALLING, callback=right_button_press, bouncetime=200) GPIO.add_event_detect(middle_button,
def init_lcd(self): self.lcd = i2c_lcd.lcd(addr=self.FMC.config['lcd_address']) self.lcd.lcd_display_string_pos("FMC Desktop", 1, 0) self.lcd.lcd_display_string_pos("v0.0.2!", 2, 0)
""" self._inst(0x01) self.pi.i2c_close(self._h) if __name__ == "__main__": import i2c_lcd import pigpio import time pi = pigpio.pi() if not pi.connected: exit(0) lcd = i2c_lcd.lcd(pi, width=20) count = 1 try: while True: #lcd.backlight(True) lcd.put_line(0, "pigpio") lcd.put_line(1, " library") lcd.put_line(2, time.asctime()) lcd.move_to(3, 8) lcd.put_str(str(count)) count += 1