ap.show_letter('1') - Raspberry Pi Forums
this problem has been solved:
************************************************************************************************
why won't countdown work?
if first time - pickle set - [*] scroll n , enter it.
[*] scroll one
should able scroll 1 if have done before , not deleted data files
execute terminal sudo
here's code:
************************************************************************************************
why won't countdown work?
if first time - pickle set - [*] scroll n , enter it.
[*] scroll one
should able scroll 1 if have done before , not deleted data files
execute terminal sudo
here's code:
code: select all
#! /usr/bin/python # import modules , functions import os , time , curses , pickle , random astro_pi import astropi time import sleep import pickle ap = astropi() ap.clear() # clear screen... # set data: variables , lists , dictionaries , functions etc... # stored data: (in pickle) if not os.path.isfile( 'numberofpeople.dat' ): # if there not correct file exising... numberofpeople = 0 # set variable file = open( 'numberofpeople.dat' , 'wb' ) # set setup variable pickle.dump( numberofpeople , file ) # dump data in file file.close() # close file else: # if file exist... file = open( 'numberofpeople.dat' , 'rb' ) # set setup variable numberofpeople = pickle.load( file ) # load data file.close() # close file if not os.path.isfile( 'besttemp.dat' ): # if there not correct file exising... besttemp = 0 # set variable file = open( 'besttemp.dat' , 'wb' ) # set setup variable pickle.dump( besttemp , file ) # dump data in file file.close() # close file else: # if file exist... file = open( 'besttemp.dat' , 'rb' ) # set setup variable besttemp = pickle.load( file ) # load data file.close() # close file if not os.path.isfile( 'users.dat' ): # if there not correct file exising... users = [] # set dictionary file = open( 'users.dat' , 'wb' ) # set setup variable pickle.dump( users , file ) # dump data in file file.close() # close file else: # if file exist... file = open( 'users.dat' , 'rb' ) # set setup variable users = pickle.load( file ) # load data file.close() # close file # temporary data: person = 0 # current person playing/reading data. default 0 if main menu launched or if administrator running. temporary = [] # curses setup... screen = curses.initscr() # initialising... screen.keypad(true) # set arrow keys... curses.cbreak() # don't wait enter pressed # functions: def menunum(): # number side of menu layer 1 running = true # set running true file = open( 'numberofpeople.dat' , 'rb' ) # setup variable numberofpeople = pickle.load( file ) # refresh variables if numberofpeople >= 1: # if numberofpeople or more one.. screenchar = 1 # set screen 1 ap.show_message(str(screenchar)) # change screen try: while running: ap.clear() # clear screen char = screen.getch() # setup variable if char == curses.key_right: # if right key pressed file = open( 'numberofpeople.dat' , 'rb' ) # open file numberofpeople = pickle.load( file ) # refresh data if (screenchar + 1) > numberofpeople: ####### menucharn() # right arrow pressed running = false ####### else: screenchar += 1 ####### ap.show_message(str(screenchar)) # right arrow pressed elif char == curses.key_left: ####### if screenchar == 1: ####### menucharn() # left arrow pressed running = false ####### else: screenchar -= 1 ####### ap.show_message(str(screenchar)) # left arrow pressed elif char == 10: ####### person = screenchar ####### write() # enter pressed running = false ####### finally: print('') # stop errors occuring... else: menucharn() # go new menu running = false # stop def menucharn(): # new menu item running = true # set running true ap.clear() # clear screen ap.show_message('n') # show n on screen try: while running: char = screen.getch() # setup variable if char == curses.key_right: # if right arrow pressed menuchara() # admin menu item running = false # stop elif char == curses.key_left: # if left arrow pressed menunum() # number menu item running = false # stop elif char == 10: # if enter pressed file = open( 'numberofpeople.dat' , 'rb' ) # open data file numberofpeople = pickle.load( file ) # refresh data currentpeople = numberofpeople # setup variable currentpeople += 1 # add 1 current people numberofpeople = currentpeople # setup variable file = open( 'numberofpeople.dat' , 'wb' ) # set setup variable pickle.dump( numberofpeople , file ) # dump data in file file = open( 'numberofpeople.dat' , 'rb' ) # open file reading numberofpeople = pickle.load( file ) # refresh variable ap.show_message('new person ' + str(numberofpeople) + ' created!') # display completion message menunum() # go number menu running = false # stop finally: print('') # somethong stop errors occuring try... def menuchara(): # admin menu item running = true # set running true ap.clear() # clear screen ap.show_message('a') # show on screen try: while running: char = screen.getch() # setup variable if char == curses.key_right: # if right arrow pressed menunum() # number menu item/s elif char == curses.key_left: # if left key pressed menucharn() # new menu item elif char == 10: # if enter key pressed admin() # admin enter finally: print('') # stop errors occuring... def admin(): # inside admin menu ap.show_message('the best overall temperature place work @ is... 21 degrees celcius!') # display average message def write(): # inside person menu item ap.clear() ########### ap.show_letter('9') # sleep(1) # ap.show_letter('8') # sleep(1) # ap.show_letter('7') # sleep(1) # ap.show_letter('6') # sleep(1) # ap.show_letter('5') # countdown... sleep(1) # begin! ap.show_letter('4') # sleep(1) # ap.show_letter('3') # sleep(1) # ap.show_letter('2') # sleep(1) # # ap.show_letter('1') # sleep(1) # ap.show_letter('0') # sleep(1) ########### # begin actual game! r = [ 255 , 0 , 0 ] # r = red o = [ 0 , 0 , 0 ] # o = black dotred = [ o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, r, r, o, o, o, o, o, o, r, r, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o ] # code red dot ap.set_pixels(dotred) # set pixels red dot sleep(random.random() * 10 + 3) # wait random time between 3 , 13 seconds ap.clear() ap.clear() # clear screen menunum() # start whole program!
does program work you?
code: select all
#!/usr/bin/python import time astro_pi import astropi ap = astropi() in reversed(range(0,10)): ap.show_letter(str(i)) time.sleep(1)
raspberrypi
Comments
Post a Comment