progress on the LED blinking handler
This commit is contained in:
parent
dc9497ab6b
commit
e3af1a7f50
@ -9,7 +9,7 @@
|
||||
# Pinout for assembly:
|
||||
#
|
||||
# 3V3 (1) (2) 5V
|
||||
# pin_shutdown (3) (4) 5V
|
||||
# - (3) (4) 5V
|
||||
# - (5) (6) GND
|
||||
# - (7) (8) -
|
||||
# GND (9) (10) -
|
||||
@ -25,7 +25,7 @@
|
||||
# - (29) (30) GND
|
||||
# - (31) (32) pin_start
|
||||
# pin_error (33) (34) GND
|
||||
# - (35) (36) -
|
||||
# - (35) (36) pin_shutdown
|
||||
# - (37) (38) -
|
||||
# GND (39) (40) -
|
||||
|
||||
@ -33,7 +33,7 @@
|
||||
#
|
||||
# 32: pull up
|
||||
# 33: pull up
|
||||
# 3: pull down
|
||||
# 36: pull up
|
||||
#
|
||||
# make sure leds are on pull-up default pins
|
||||
# so when their state is undefined, the led
|
||||
@ -141,9 +141,6 @@ led_red_brightness = 0
|
||||
led_green_brightness = 0
|
||||
led_blue_brightness = 0
|
||||
|
||||
# predefine led blink timer to 0
|
||||
timer_led_blink = 0
|
||||
|
||||
############################################
|
||||
######## END OF PRE-INITIALISATION #########
|
||||
############################################
|
||||
@ -198,7 +195,7 @@ def change_red(amount):
|
||||
global led_red, led_red_brightness
|
||||
led_red_brightness = amount
|
||||
factor = 100/255
|
||||
led_red.ChangeDutyCycle(amount*factor)
|
||||
led_red.ChangeDutyCycle(led_red_brightness*factor)
|
||||
|
||||
def change_green(amount):
|
||||
# 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
|
||||
led_green_brightness = amount
|
||||
factor = 100/255
|
||||
led_green.ChangeDutyCycle(amount*factor)
|
||||
led_green.ChangeDutyCycle(led_green_brightness*factor)
|
||||
|
||||
def change_blue(amount):
|
||||
# takes an input from 0 to 255 and converts it to Duty Cycle
|
||||
@ -214,20 +211,8 @@ def change_blue(amount):
|
||||
global led_blue, led_blue_brightness
|
||||
led_blue_brightness = amount
|
||||
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):
|
||||
# sets an RGB value for the led strip.
|
||||
if red_amount < 0 or red_amount > 255 or green_amount < 0 or green_amount > 255 or blue_amount < 0 or blue_amount > 255:
|
||||
@ -250,22 +235,25 @@ def change_led_speed(colour, speed):
|
||||
else:
|
||||
return false
|
||||
|
||||
def led_handler():
|
||||
if led_blink == True:
|
||||
if timer_led_blink == 0:
|
||||
timer_led_blink_starttime = pygame.time.get_ticks()
|
||||
timer_led_blink = (timer_led_blink_starttime-pygame.time.get_ticks())
|
||||
if (timer_led_blink/1000)%2 = 0:
|
||||
if timer_led_blink_toggle == 1:
|
||||
led_red_brightness_temp = get_red()
|
||||
led_green_brightness_temp = get_green()
|
||||
led_blue_brightness_temp = get_blue()
|
||||
def led_handler():
|
||||
# global timer_led_blink_toggle, timer_led_one_shot
|
||||
# if led_blink == True:
|
||||
# if int((pygame.time.get_ticks()/1000))%2 == 0:
|
||||
# if timer_led_one_shot == 0:
|
||||
# timer_led_one_shot = 1
|
||||
# if timer_led_blink_toggle == 1:
|
||||
# print('BLINK: switching leds off')
|
||||
# print('red br.:' + str(led_red_brightness))
|
||||
|
||||
change_led_colour(0,0,0)
|
||||
timer_led_blink_toggle = 0
|
||||
else:
|
||||
change_led_colour(led_red_brightness_temp,led_green_brightness_temp,led_blue_brightness_temp)
|
||||
timer_led_blink_toggle = 1
|
||||
# change_led_colour(0,0,0)
|
||||
# timer_led_blink_toggle = 0
|
||||
# else:
|
||||
# print('BLINK: reverting colours')
|
||||
# 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():
|
||||
# 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_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_surface, textbox_rectangle)
|
||||
@ -487,7 +475,13 @@ highscore_checked = False
|
||||
pin_start_inhibit = False
|
||||
timer_game_ending_started = False
|
||||
|
||||
# test: enable led blinking permanently
|
||||
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 ###########
|
||||
@ -504,6 +498,7 @@ while True:
|
||||
show_debug()
|
||||
led_handler()
|
||||
|
||||
print(int((pygame.time.get_ticks()/1000))%2)
|
||||
if game_running == False and game_ending == False:
|
||||
# one shot for changing the led colour
|
||||
if game_just_started == True:
|
||||
|
Loading…
Reference in New Issue
Block a user