circuitpython_temp_humidity.png
From https://learn.adafruit.com/adafruit-io-basics-temperature-and-humidity

We started with wanting to debounce a mechanical switch, and now we have the ability to debounce any zero-argument predicate function/lambda. From this we can get stable boolean values, as well as being informed when that stable value charges and in which direction (i.e. rising or falling)

We can use a debouncer for these three things even if the signal may not be all that noisy. Think about a temperature monitor that has an acceptable range. We can use a debouncer to monitor whether the temperature is in (or out of) that range. 

Let's say we need to know if/when the temperature exceeds 30C and when it returns to an acceptable value. Maybe we turn a fan on when it's too hot and off when it's ok. On a Circuit Playground Express we could do something like:

import adafruit_debouncer
import adafruit_thermistor
import board
 
thermistor = adafruit_thermistor.Thermistor(board.TEMPERATURE, 10000, 10000, 25, 3950)

in_range = adafruit_debouncer.Debouncer(lambda: thermistor.temperature <= 30)

while True:
    in_range.update()
    if in_range.fell:
        print('High temperature alert')
    elif in_range.rose:
        print('Temperature ok again')

You can use a debouncer and an appropriate lamdba to monitor any sort of threshold like this.

This guide was first published on Jan 08, 2019. It was last updated on Mar 08, 2024.

This page (Beyond Debouncing) was last updated on Mar 08, 2024.

Text editor powered by tinymce.