trying to reduce flicker due to pwm switching
This commit is contained in:
		| @@ -144,6 +144,10 @@ led_blue_brightness = 0 | |||||||
| # leds are turned on and can be switched off by default | # leds are turned on and can be switched off by default | ||||||
| leds_off_toggle = False | 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 ######### | ######## END OF PRE-INITIALISATION ######### | ||||||
| ############################################ | ############################################ | ||||||
| @@ -291,9 +295,15 @@ def led_handler(): | |||||||
|         # the values will be correctly put in once the toggle is back |         # the values will be correctly put in once the toggle is back | ||||||
|  |  | ||||||
|         if leds_off_toggle == False: |         if leds_off_toggle == False: | ||||||
|             led_red.ChangeDutyCycle(led_red_brightness) |             if int((pygame.time.get_ticks()/100))%2 == 0: | ||||||
|             led_green.ChangeDutyCycle(led_green_brightness) |                 if timer_led_updated == 0: | ||||||
|             led_blue.ChangeDutyCycle(led_blue_brightness) |                     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(): | def leds_toggle(): | ||||||
|  |  | ||||||
| @@ -533,8 +543,9 @@ while True: | |||||||
|         handle_events() |         handle_events() | ||||||
|         show_debug() |         show_debug() | ||||||
|         led_handler() |         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:  |         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: | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user