def run(self, output_fn, **kwargs): fd = open(output_fn, 'w') if not LCD.init_lcd(): fd.write("Failed init lcd1602, stoping now.") return wlan0 = "None" eth0 = "None" t = 0 while wlan0 != "None" or eth0 != "None": wlan0 = host.get_ip_address("wlan0") eth0 = host.get_ip_address("eth0") LCD.print_lcd(0, 0, "No network connect") LCD.print_lcd(0, 1, "%s times tried" % t) t += 0.5 time.sleep(0.5) wlan0 = host.get_ip_address("wlan0") LCD.print_lcd(0, 0, "W" + wlan0) time.sleep(3) rund = 0 LCD.clear_lcd() #d = 0 #h = 0 #m = 0 #s = 0 while True: #s += 1 #if s%60 == 0: # s = 0 # m += 1 # if m%60 == 0: # m=0 # h += 1 # if h%24 == 0: # h=0 # d += 1 LCD.print_lcd(0, 0, wlan0) LCD.print_lcd(0, 1, host.get_up_time( )) # "%s %s%s:%s%s:%s%s"%(d, h/10, h%10, m/10, m%10, s/10, s%10)) time.sleep(1) fd.close()
def get_mem_info(): total = commands.getoutput('free -m|grep Mem:|awk \'{print $2}\'') free = commands.getoutput('free -m|grep cache:|awk \'{print $4}\'') return 'M:F' + free + '/T' + total + ' MiB' def run_cmd(cmd): p = Popen(cmd, shell=True, stdout=PIPE) output = p.communicate()[0] return output if __name__ == '__main__': LCD.init_lcd() LCD.turn_light(0) # LCD.print_lcd(0,0,datetime.now().strftime('%b %d %H:%M:%S\n')) # LCD.print_lcd(1,1,'local time') # print('wait 5 seconds') # time.sleep(5) while True: # nowtime = datetime.now().strftime('%b %d %H:%M:%S') # mintime = time.strftime('%M',time.localtime(time.time())) # print('current time:'+nowtime) # LCD.print_lcd(0,0,nowtime) # if mintime == 59:
#!/user/bin/env python import smbus import time import sys import LCD1602 as LCD if __name__ == '__main__': LCD.init_lcd() LCD.print_lcd(0, 0, 'RaspberryPi IIC') LCD.print_lcd(1, 1, 'wait a moment') print('wait 3 seconds') LCD.turn_light(1) time.sleep(3) try: while True: nowtime = time.strftime('%m-%d %H:%M:%S', time.localtime(time.time())) mintime = time.strftime('%M', time.localtime(time.time())) print('current time:' + nowtime) LCD.print_lcd(1, 1, nowtime) if mintime == 59: LCD.turn_light(1) print('mintime:' + mintime) time.sleep(1) except KeyboardInterrupt: LCD.print_lcd(0, 1, 'Can\'t see anyth') print('exit')
def LCD_Init(): LCD.init_lcd() LCD.print_lcd(0,0,'RaspberryPi IIC') #LCD.print_lcd(1,1,'wait a moment') LCD.turn_light(1) time.sleep(1.5)
def Ds1302ReadTime(): for i in range(0, 6): TIME[i] = Ds1302Read(READ_RTC_ADDR[i]) print(int(TIME[2] / 16), (TIME[2] & 0x0f), ':', int(TIME[1] / 16), (TIME[1] & 0x0f), ':', int(TIME[0] / 16), (TIME[0] & 0x0f)) data[0] = int(TIME[2] / 16) data[1] = TIME[2] & 0x0f data[2] = 10 data[3] = int(TIME[1] / 16) data[4] = TIME[1] & 0x0f data[5] = 10 data[6] = int(TIME[0] / 16) data[7] = TIME[0] & 0x0f def Ds1302Init(): Ds1302Write(0x8E, 0X00) for i in range(0, 7): Ds1302Write(WRITE_RTC_ADDR[i], TIME[i]) Ds1302Write(0x8E, 0x80) Ds1302Init() LCD1602.init_lcd() while True: Ds1302ReadTime() for i in range(8): LCD1602.print_lcd_char(i, 0, data[i] + 48) #LCD1602.print_lcd(2, 0,"tt") time.sleep(1)