example: simplify pininterrupt

Этот коммит содержится в:
Yurii Soldak 2023-06-12 15:27:20 +02:00 коммит произвёл Ron Evans
родитель 4d2a6d2bbe
коммит cec237917f
2 изменённых файлов: 2 добавлений и 11 удалений

Просмотреть файл

@ -43,7 +43,7 @@ func TestBinarySize(t *testing.T) {
// microcontrollers // microcontrollers
{"hifive1b", "examples/echo", 4612, 280, 0, 2252}, {"hifive1b", "examples/echo", 4612, 280, 0, 2252},
{"microbit", "examples/serial", 2724, 388, 8, 2256}, {"microbit", "examples/serial", 2724, 388, 8, 2256},
{"wioterminal", "examples/pininterrupt", 6159, 1485, 116, 6816}, {"wioterminal", "examples/pininterrupt", 6039, 1485, 116, 6816},
// TODO: also check wasm. Right now this is difficult, because // TODO: also check wasm. Right now this is difficult, because
// wasm binaries are run through wasm-opt and therefore the // wasm binaries are run through wasm-opt and therefore the

Просмотреть файл

@ -8,7 +8,6 @@ package main
import ( import (
"machine" "machine"
"runtime/volatile"
"time" "time"
) )
@ -18,8 +17,6 @@ const (
) )
func main() { func main() {
var lightLed volatile.Register8
lightLed.Set(0)
// Configure the LED, defaulting to on (usually setting the pin to low will // Configure the LED, defaulting to on (usually setting the pin to low will
// turn the LED on). // turn the LED on).
@ -33,13 +30,7 @@ func main() {
// Set an interrupt on this pin. // Set an interrupt on this pin.
err := button.SetInterrupt(buttonPinChange, func(machine.Pin) { err := button.SetInterrupt(buttonPinChange, func(machine.Pin) {
if lightLed.Get() != 0 { led.Set(!led.Get())
lightLed.Set(0)
led.Low()
} else {
lightLed.Set(1)
led.High()
}
}) })
if err != nil { if err != nil {
println("could not configure pin interrupt:", err.Error()) println("could not configure pin interrupt:", err.Error())