pimoroni / explorer-hat

Python library for Explorer HAT
https://shop.pimoroni.com/products/explorer-hat
MIT License
163 stars 60 forks source link

Higher CPU usage after turning on the lights - Why? #53

Closed e-r-n-i-e closed 1 year ago

e-r-n-i-e commented 2 years 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.

Gadgetoid commented 2 years ago

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.