Closed e-r-n-i-e closed 1 year ago
The following code runs fine, but after the first touch to turn on the LEDs the CPU usage of python raises to about 15-16%.
#!/usr/bin/env python import explorerhat import time print("Touch me to toggle the LEDs!") def touch(channel, event): print("Thank you! :-))) [{}: {}]".format(channel, event)) explorerhat.light.toggle() explorerhat.touch.released(touch) while True: time.sleep(10) print('Please touch me...') explorerhat.pause()
Why? How to avoid this behaviour?
Tested with top on Raspi 2 with latest Raspi OS.
top
Probably because it's using RPi.GPIO's soft PWM to brightness control the LEDs. That - I believe - just uses a loop under the hood.
RPi.GPIO
The following code runs fine, but after the first touch to turn on the LEDs the CPU usage of python raises to about 15-16%.
Why? How to avoid this behaviour?
Tested with
top
on Raspi 2 with latest Raspi OS.