progress on the LED blinking handler

This commit is contained in:
Patrick Tschuchnig 2019-09-11 16:34:32 +02:00
parent dc9497ab6b
commit e3af1a7f50

View File

@ -9,7 +9,7 @@
# Pinout for assembly: # Pinout for assembly:
# #
# 3V3 (1) (2) 5V # 3V3 (1) (2) 5V
# pin_shutdown (3) (4) 5V # - (3) (4) 5V
# - (5) (6) GND # - (5) (6) GND
# - (7) (8) - # - (7) (8) -
# GND (9) (10) - # GND (9) (10) -
@ -25,7 +25,7 @@
# - (29) (30) GND # - (29) (30) GND
# - (31) (32) pin_start # - (31) (32) pin_start
# pin_error (33) (34) GND # pin_error (33) (34) GND
# - (35) (36) - # - (35) (36) pin_shutdown
# - (37) (38) - # - (37) (38) -
# GND (39) (40) - # GND (39) (40) -
@ -33,7 +33,7 @@
# #
# 32: pull up # 32: pull up
# 33: pull up # 33: pull up
# 3: pull down # 36: pull up
# #
# make sure leds are on pull-up default pins # make sure leds are on pull-up default pins
# so when their state is undefined, the led # so when their state is undefined, the led
@ -141,9 +141,6 @@ led_red_brightness = 0
led_green_brightness = 0 led_green_brightness = 0
led_blue_brightness = 0 led_blue_brightness = 0
# predefine led blink timer to 0
timer_led_blink = 0
############################################ ############################################
######## END OF PRE-INITIALISATION ######### ######## END OF PRE-INITIALISATION #########
############################################ ############################################
@ -198,7 +195,7 @@ def change_red(amount):
global led_red, led_red_brightness global led_red, led_red_brightness
led_red_brightness = amount led_red_brightness = amount
factor = 100/255 factor = 100/255
led_red.ChangeDutyCycle(amount*factor) led_red.ChangeDutyCycle(led_red_brightness*factor)
def change_green(amount): def change_green(amount):
# takes an input from 0 to 255 and converts it to Duty Cycle # takes an input from 0 to 255 and converts it to Duty Cycle
@ -206,7 +203,7 @@ def change_green(amount):
global led_green, led_green_brightness global led_green, led_green_brightness
led_green_brightness = amount led_green_brightness = amount
factor = 100/255 factor = 100/255
led_green.ChangeDutyCycle(amount*factor) led_green.ChangeDutyCycle(led_green_brightness*factor)
def change_blue(amount): def change_blue(amount):
# takes an input from 0 to 255 and converts it to Duty Cycle # takes an input from 0 to 255 and converts it to Duty Cycle
@ -214,19 +211,7 @@ def change_blue(amount):
global led_blue, led_blue_brightness global led_blue, led_blue_brightness
led_blue_brightness = amount led_blue_brightness = amount
factor = 100/255 factor = 100/255
led_blue.ChangeDutyCycle(amount*factor) led_blue.ChangeDutyCycle(led_blue_brightness_temp*factor)
def get_red():
global led_red_brightness
return led_red_brightness
def get_green():
global led_green_brightness
return led_green_brightness
def get_blue():
global led_blue_brightness
return led_blue_brightness
def change_led_colour(red_amount,green_amount,blue_amount): def change_led_colour(red_amount,green_amount,blue_amount):
# sets an RGB value for the led strip. # sets an RGB value for the led strip.
@ -251,21 +236,24 @@ def change_led_speed(colour, speed):
return false return false
def led_handler(): def led_handler():
if led_blink == True: # global timer_led_blink_toggle, timer_led_one_shot
if timer_led_blink == 0: # if led_blink == True:
timer_led_blink_starttime = pygame.time.get_ticks() # if int((pygame.time.get_ticks()/1000))%2 == 0:
timer_led_blink = (timer_led_blink_starttime-pygame.time.get_ticks()) # if timer_led_one_shot == 0:
if (timer_led_blink/1000)%2 = 0: # timer_led_one_shot = 1
if timer_led_blink_toggle == 1: # if timer_led_blink_toggle == 1:
led_red_brightness_temp = get_red() # print('BLINK: switching leds off')
led_green_brightness_temp = get_green() # print('red br.:' + str(led_red_brightness))
led_blue_brightness_temp = get_blue()
change_led_colour(0,0,0) # change_led_colour(0,0,0)
timer_led_blink_toggle = 0 # timer_led_blink_toggle = 0
else: # else:
change_led_colour(led_red_brightness_temp,led_green_brightness_temp,led_blue_brightness_temp) # print('BLINK: reverting colours')
timer_led_blink_toggle = 1 # change_led_colour(led_red_brightness,led_green_brightness,led_blue_brightness)
# timer_led_blink_toggle = 1
# else:
# timer_led_one_shot = 0
pass
def led_alert(): def led_alert():
# stops the running program for 10 seconds # stops the running program for 10 seconds
@ -354,7 +342,7 @@ def enter_name():
textbox_surface = pygame_font_2.render(str(name), True, pygame_font_main_color) textbox_surface = pygame_font_2.render(str(name), True, pygame_font_main_color)
textbox_rectangle = textbox_surface.get_rect() textbox_rectangle = textbox_surface.get_rect()
textbox_rectangle.topleft = (700, 370) textbox_rectangle.topleft = (930, 400)
screen.blit(textbox_text_surface, textbox_text_rectangle) screen.blit(textbox_text_surface, textbox_text_rectangle)
screen.blit(textbox_surface, textbox_rectangle) screen.blit(textbox_surface, textbox_rectangle)
@ -487,7 +475,13 @@ highscore_checked = False
pin_start_inhibit = False pin_start_inhibit = False
timer_game_ending_started = False timer_game_ending_started = False
# test: enable led blinking permanently
led_blink = True led_blink = True
timer_led_blink_toggle = 1
led_red_brightness_temp = 0
led_green_brightness_temp = 0
led_blue_brightness_temp = 0
timer_led_one_shot = 0
############################################ ############################################
########## END OF INITIALISATION ########### ########## END OF INITIALISATION ###########
@ -504,6 +498,7 @@ while True:
show_debug() show_debug()
led_handler() led_handler()
print(int((pygame.time.get_ticks()/1000))%2)
if game_running == False and game_ending == False: if game_running == False and game_ending == False:
# one shot for changing the led colour # one shot for changing the led colour
if game_just_started == True: if game_just_started == True: