A small temperature alarm in Toit 2.0
Описание и применение
Пример реализации температурного сигнала с гистерезисом в Toit 2.0, демонстрирующий, как избежать частых переключений состояния при колебаниях температуры.
Задача
Implement a hysteresis-based temperature alarm that avoids rapid state changes when readings hover around threshold values.
Результат
The program printed the expected sequence of alarm states, demonstrating correct hysteresis logic without external hardware.
Рабочий процесс
- 1. Download the v2.0.0 Toit release for your platform and add its bin directory to PATH.
- 2. Verify the runtime with
toit --version. - 3. Create a file
sensor.toitcontaining the alarm logic using local variables and conditional blocks. - 4. Run
toit analyze sensor.toitto check syntax. - 5. Execute the program with
toit run sensor.toitand observe the output. - 6. Verify hysteresis behavior by comparing output to expected state transitions.
Доказательства
A temperature alarm needs a little memory. Switch it on at 30°C, keep it on while the reading drifts down, and switch it off at 27°C.
Get the archive that matches your platform from the official v2.0.0 release, extract it, and put its bin directory on your PATH.
toit analyze sensor.toit toit run sensor.toit
28 C: false 30 C: true 29 C: true 30 C: true 29 C: true 27 C: false 29 C: false 31 C: true
- Дата записи: 2026-11-03T14:14:19.801Z