def updatelcd(self): self.getlcddata() if self.lcddata != self.old_lcddata: lcd = Lcd((self.unit['lcd'][0]['addr'][0:6]), (self.unit['lcd'][0]['addr'][6:8])) for index, item in enumerate(self.lcddata): if index < 4: lcd.setCursor(0, index) lcd.printString(item) else: print 'To many rows to print, max 4' if ( (not self.unit['pir']) and (not self.unit['lcd'][0]['backlightState']) ): self.pwmLcdBacklight(250) self.old_lcddata = self.lcddata elif ( (not self.unit['pir']) and (self.unit['lcd'][0]['backlightState']) ): self.pwmLcdBacklight(0)
from datetime import datetime from subprocess import * from time import sleep, strftime from Queue import Queue from threading import Thread import os from nanpy import Arduino, Lcd Arduino.pinMode(14, input) lcd = Lcd([8, 9, 4, 5, 6, 7], [16, 2]) # Setup the LCD pins for the Sainsmart Shield lcd.printString("Jess's Web Radio", 0, 0) lcd.printString("Loading" + "." * 3, 0, 1) sleep(5) max_trax = 74 x = 1 loop_menu = 1 loop_radio = 1 def display_ipaddr(): show_wlan0 = "ip addr show wlan0 | cut -d/ -f1 | awk '/inet/ {printf \"w%15.15s\", $2}'" show_eth0 = "ip addr show eth0 | cut -d/ -f1 | awk '/inet/ {printf \"e%15.15s\", $2}'" ipaddr = run_cmd(show_eth0) if ipaddr == "": ipaddr = run_cmd(show_wlan0) lcd.printString('IP Address:', 0, 0) lcd.printString(ipaddr, 0, 1) sleep(2)
else: pass self.__data = raw def getCelsius(self): if self.__fetchAddress(): self.__fetchData() return self.__data / 16.0 def getFahrenheit(self): if self.__fetchAddress(): self.__fetchData() return self.getCelsius() * 1.8 + 32.0 from nanpy import Lcd if __name__ == "__main__": lcd = Lcd([7, 8, 9, 10, 11, 12], [16, 2]) lcd.printString("Loc. London") temp_int = FakeDallasTemperature(6) temp_ext = FakeDallasTemperature(5) while(1): lcd.setCursor(0, 1) lcd.printString("Ex.%0.0f\xDFC In.%0.0f\xDFC" % (temp_int.getCelsius(), temp_ext.getCelsius()))
#!/usr/bin/env python # Author: Andrea Stagi <*****@*****.**> # Description: get the current time from a ntp server and show it on a lcd # Dependencies: ntplib (http://pypi.python.org/pypi/ntplib/) import ntplib from nanpy import (Arduino, Lcd) from datetime import datetime ntp_client = ntplib.NTPClient() response = ntp_client.request('europe.pool.ntp.org', version=3) time = int(response.tx_time) lcd = Lcd([7, 8, 9, 10, 11, 12], [16, 2]) while (1): lcd.setCursor(0, 0) lcd.printString((datetime.fromtimestamp(time)).strftime('%Y-%m-%d')) if time % 2: time_format = '%H:%M' else: time_format = '%H %M' lcd.setCursor(0, 1) lcd.printString((datetime.fromtimestamp(time)).strftime(time_format)) Arduino.delay(1000) time += 1
from nanpy import Arduino from nanpy import Lcd import time lcd = Lcd([12, 11, 5, 4, 3, 2], [16, 2]) lcd.printString('Hello World!') def taha(N): Arduino.pinMode(13, Arduino.OUTPUT) while True: Arduino.digitalWrite(13, Arduino.HIGH) time.sleep(float(N)) Arduino.digitalWrite(13, Arduino.LOW) time.sleep(float(N)) lcd.setCursor(0, 1) lcd.printString(N) print N
# Description: get the current time from a ntp server and show it on a lcd # Dependencies: ntplib (http://pypi.python.org/pypi/ntplib/) import ntplib from nanpy import (SerialManager, Lcd) from datetime import datetime from time import sleep connection = SerialManager() ntp_client = ntplib.NTPClient() response = ntp_client.request('europe.pool.ntp.org', version=3) time = int(response.tx_time) pins = [7, 8, 9, 10, 11, 12] cols, rows = 16, 2 lcd = Lcd(pins, [cols, rows], connection=connection) while (1): lcd.setCursor(0, 0) lcd.printString((datetime.fromtimestamp(time)).strftime('%Y-%m-%d')) if time % 2: time_format = '%H:%M' else: time_format = '%H %M' lcd.setCursor(0, 1) lcd.printString((datetime.fromtimestamp(time)).strftime(time_format)) sleep(1) time += 1
from nanpy import (ArduinoApi, SerialManager, Lcd) from time import sleep import datetime lcd = Lcd([8, 9, 4, 5, 6, 7], [16, 2]) status = 't' while status == 't': lcd.clear() lcd.printString(datetime.datetime.now()) status = input("What status do you want: ") lcd.clear() lcd.printString('Dead!!!') ledPin = 13 ledState = True try: connection = SerialManager() a = ArduinoApi(connection=connection) except: print("Failed to connect to Arduino") a.pinMode(ledPin, a.OUTPUT) try: while True: if ledState: a.digitalWrite(ledPin, a.LOW) ledState = False lcd.clear()