aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYurii Soldak <[email protected]>2023-06-12 15:27:20 +0200
committerRon Evans <[email protected]>2023-06-18 10:59:23 +0200
commitcec237917f2b0f8dc4fb09d83c350ed94ca5a603 (patch)
treed71a80b41afa22bbbef840eaa03160d0fdacd608
parent4d2a6d2bbeef8db2a2e9714f3d91372f89bc9b80 (diff)
downloadtinygo-cec237917f2b0f8dc4fb09d83c350ed94ca5a603.tar.gz
tinygo-cec237917f2b0f8dc4fb09d83c350ed94ca5a603.zip
example: simplify pininterrupt
-rw-r--r--builder/sizes_test.go2
-rw-r--r--src/examples/pininterrupt/pininterrupt.go11
2 files changed, 2 insertions, 11 deletions
diff --git a/builder/sizes_test.go b/builder/sizes_test.go
index d640fa21f..a97fc01c3 100644
--- a/builder/sizes_test.go
+++ b/builder/sizes_test.go
@@ -43,7 +43,7 @@ func TestBinarySize(t *testing.T) {
// microcontrollers
{"hifive1b", "examples/echo", 4612, 280, 0, 2252},
{"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
// wasm binaries are run through wasm-opt and therefore the
diff --git a/src/examples/pininterrupt/pininterrupt.go b/src/examples/pininterrupt/pininterrupt.go
index 0cb29bc85..f693f1172 100644
--- a/src/examples/pininterrupt/pininterrupt.go
+++ b/src/examples/pininterrupt/pininterrupt.go
@@ -8,7 +8,6 @@ package main
import (
"machine"
- "runtime/volatile"
"time"
)
@@ -18,8 +17,6 @@ const (
)
func main() {
- var lightLed volatile.Register8
- lightLed.Set(0)
// Configure the LED, defaulting to on (usually setting the pin to low will
// turn the LED on).
@@ -33,13 +30,7 @@ func main() {
// Set an interrupt on this pin.
err := button.SetInterrupt(buttonPinChange, func(machine.Pin) {
- if lightLed.Get() != 0 {
- lightLed.Set(0)
- led.Low()
- } else {
- lightLed.Set(1)
- led.High()
- }
+ led.Set(!led.Get())
})
if err != nil {
println("could not configure pin interrupt:", err.Error())