def main(): time.sleep(1) pitft = PiTFT_GPIO(v2=True) screen = display_on_rpi.init_display() mypath = '/home/pi/Google-Hackathon-Replay/review/' resetReviewLog = True reviewFileIter = iter([f for f in listdir(mypath) if isfile(join(mypath, f))]) while True: string_to_display = '' if pitft.Button1: print "Button 1 pressed - screen off" string_to_display = replay("/home/pi/Google-Hackathon-Replay/text/log.txt", 3) save_review_to_file(string_to_display) display_on_rpi.init_display() display_on_rpi.display_text(string_to_display, screen) display_on_rpi.draw_file_browsing_interface(screen) resetReviewLog = True time.sleep(0.2) elif pitft.Button2: print "Button 2 pressed - screen on" string_to_display = replay("/home/pi/Google-Hackathon-Replay/text/log.txt", 6) save_review_to_file(string_to_display) display_on_rpi.init_display() display_on_rpi.display_text(string_to_display, screen) display_on_rpi.draw_file_browsing_interface(screen) resetReviewLog = True time.sleep(0.2) elif pitft.Button3: print "Button 3 pressed" if resetReviewLog: resetReviewLog = False reviewFileIter = iter([f for f in listdir(mypath) if isfile(join(mypath, f))]) try: file = next(reviewFileIter) if file: string_to_display = open(mypath+file).read() print string_to_display display_on_rpi.init_display() display_on_rpi.display_text(string_to_display, screen) display_on_rpi.draw_file_browsing_interface(screen) # cloud_conn.textToSpeech(string_to_display) # os.system('aplay output.mp3') if len(string_to_display)>1: command = "espeak \""+string_to_display+"\" --stdout | aplay -D 'default'" print command os.system(command) time.sleep(1) except Exception as e: reviewFileIter = iter([f for f in listdir(mypath) if isfile(join(mypath, f))]) print "reached end no more printing" elif pitft.Button4: print "Button 4 pressed" time.sleep(0.2) else: string_to_display = replay("/home/pi/Google-Hackathon-Replay/text/log.txt", 3) display_on_rpi.init_display() display_on_rpi.display_text(string_to_display, screen) display_on_rpi.draw_file_browsing_interface(screen) resetReviewLog = True time.sleep(0.2)
from pitftgpio import PiTFT_GPIO pitft = PiTFT_GPIO() while True: if pitft.Button1: print "Button 1 pressed - screen off" #pitftf.Backlight(False) if pitft.Button2: print "Button 2 pressed - screen on" #pitft.Backlight(True) if pitft.Button3: print "Button 3 pressed" if pitft.Button4: print "Button 4 pressed"
GPIO.setmode(GPIO.BOARD) #uses the pins on the board ############################# VARIABLES ########################## #paw buttons p1palm = 27 p1left = 29 p1center = 31 p1right = 33 p2palm = 35 p2left = 37 p2center = 36 p2right = 38 pitft = PiTFT_GPIO() #for buttons on display ############################# SET UP ########################## #for paw controllers GPIO.setup(p1palm, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(p1left, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(p1center, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(p1left, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(p2palm, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(p2left, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(p2center, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(p2right, GPIO.IN, pull_up_down=GPIO.PUD_UP) ############################# LOOP ########################## while True:
from pitftgpio import PiTFT_GPIO pitft = PiTFT_GPIO() def my_callback(pin): print "Button:" + str(pin) + " callback" pitft.Button4Interrupt(callback=my_callback) while True: if pitft.Button1: print "Button 1 pressed - screen off" pitft.Backlight(False) if pitft.Button2: print "Button 2 pressed - screen on" pitft.Backlight(True) if pitft.Button3: print "Button 3 pressed" #if pitft.Button4: # print "Button 4 pressed"
# This is where we start # Initialise pygame RASPBERRYPI = False # pprint(pygame.di`play.list_modes(), 3) # Tell the RPi to use the TFT screen and that it's a touchscreen device if os.name == 'posix': RASPBERRYPI = True print "You're running raspberry pi" # Hide mouse from pitftgpio import PiTFT_GPIO os.putenv('SDL_VIDEODRIVER', 'fbcon') os.putenv('SDL_FBDEV', '/dev/fb1') os.putenv('SDL_MOUSEDRV', 'TSLIB') os.putenv('SDL_MOUSEDEV', '/dev/input/touchscreen') tftscreen = PiTFT_GPIO() ############################################################################## # Create a clock and set max FPS (This reduces a lot CPU ussage) pygame.init() # Screen size (currently fixed) size = width, height = 320, 240 screen = pygame.display.set_mode(size) # Set up the callback functions for the buttons if RASPBERRYPI: tftscreen.Button1Interrupt(TFTBtn1Click) tftscreen.Button2Interrupt(TFTBtn2Click) tftscreen.Button3Interrupt(TFTBtn3Click) tftscreen.Button4Interrupt(TFTBtn4Click) pygame.mouse.set_visible(False if RASPBERRYPI else True)
import nfc import time import platform import os import sys import requests import datetime import json from nfc.clf import RemoteTarget from dotenv import load_dotenv from datetime import datetime # Attempt to load the PiTFT_GPIO package. try: from pitftgpio import PiTFT_GPIO pitft = PiTFT_GPIO() except ImportError: # Do nothing as we can't import the PiTFT_GPIO package when we're # running on Windows. pitft = None # Load environment variables in .env. load_dotenv() def default(obj): if isinstance(obj, (datetime.date, datetime.datetime)): return obj.isoformat() def clear(): if platform.system().lower() == 'windows': os.system('cls')