trying to reduce flicker due to pwm switching

This commit is contained in:
Patrick Tschuchnig 2019-09-12 08:20:20 +02:00
parent dc1bc6fe7b
commit 4cada0a593

View File

@ -144,6 +144,10 @@ led_blue_brightness = 0
# leds are turned on and can be switched off by default
leds_off_toggle = False
# toggle for the led update to happen every *other* evaluation
# of the timer equation
timer_led_updated = 0
############################################
######## END OF PRE-INITIALISATION #########
############################################
@ -291,9 +295,15 @@ def led_handler():
# the values will be correctly put in once the toggle is back
if leds_off_toggle == False:
led_red.ChangeDutyCycle(led_red_brightness)
led_green.ChangeDutyCycle(led_green_brightness)
led_blue.ChangeDutyCycle(led_blue_brightness)
if int((pygame.time.get_ticks()/100))%2 == 0:
if timer_led_updated == 0:
timer_led_updated = 1
led_red.ChangeDutyCycle(led_red_brightness)
led_green.ChangeDutyCycle(led_green_brightness)
led_blue.ChangeDutyCycle(led_blue_brightness)
else:
timer_led_updated = 0
def leds_toggle():
@ -533,8 +543,9 @@ while True:
handle_events()
show_debug()
led_handler()
print(str(pygame.time.get_ticks()))
print(str(int((pygame.time.get_ticks()/100))%2))
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: