From fdc698a5d26ae70d6c0d6b0c73684d012d98e9eb Mon Sep 17 00:00:00 2001 From: sago35 Date: Fri, 3 May 2024 10:31:39 +0900 Subject: [PATCH 1/2] Simplify examples/ws2812 --- examples/ws2812/arduino.go | 3 +-- examples/ws2812/digispark.go | 1 - examples/ws2812/main.go | 8 ++++---- examples/ws2812/others.go | 5 ++--- examples/ws2812/others_wo_led.go | 10 ---------- examples/ws2812/thingplus-rp2040.go | 12 ------------ 6 files changed, 7 insertions(+), 32 deletions(-) delete mode 100644 examples/ws2812/others_wo_led.go delete mode 100644 examples/ws2812/thingplus-rp2040.go diff --git a/examples/ws2812/arduino.go b/examples/ws2812/arduino.go index 3f8c58ea6..a47b104d7 100644 --- a/examples/ws2812/arduino.go +++ b/examples/ws2812/arduino.go @@ -4,7 +4,6 @@ package main import "machine" -// Replace neo and led in the code below to match the pin +// Replace neo in the code below to match the pin // that you are using if different. var neo = machine.D2 -var led = machine.LED diff --git a/examples/ws2812/digispark.go b/examples/ws2812/digispark.go index fa8c57412..ad7f37197 100644 --- a/examples/ws2812/digispark.go +++ b/examples/ws2812/digispark.go @@ -8,4 +8,3 @@ import "machine" // Replace neo and led in the code below to match the pin // that you are using if different. var neo machine.Pin = 0 -var led = machine.LED diff --git a/examples/ws2812/main.go b/examples/ws2812/main.go index 02699d6b4..60e19625f 100644 --- a/examples/ws2812/main.go +++ b/examples/ws2812/main.go @@ -12,11 +12,12 @@ import ( "tinygo.org/x/drivers/ws2812" ) -var leds [10]color.RGBA +var ( + noe machine.Pin + leds [10]color.RGBA +) func main() { - led.Configure(machine.PinConfig{Mode: machine.PinOutput}) - neo.Configure(machine.PinConfig{Mode: machine.PinOutput}) ws := ws2812.NewWS2812(neo) @@ -35,7 +36,6 @@ func main() { } ws.WriteColors(leds[:]) - led.Set(rg) time.Sleep(100 * time.Millisecond) } } diff --git a/examples/ws2812/others.go b/examples/ws2812/others.go index 3c90f05e7..11becd858 100644 --- a/examples/ws2812/others.go +++ b/examples/ws2812/others.go @@ -1,10 +1,9 @@ -//go:build !digispark && !arduino && !qtpy && !m5stamp_c3 && !thingplus_rp2040 +//go:build !digispark && !arduino package main import "machine" -// Replace neo and led in the code below to match the pin +// Replace neo in the code below to match the pin // that you are using if different. var neo machine.Pin = machine.WS2812 -var led = machine.LED diff --git a/examples/ws2812/others_wo_led.go b/examples/ws2812/others_wo_led.go deleted file mode 100644 index 988d79a83..000000000 --- a/examples/ws2812/others_wo_led.go +++ /dev/null @@ -1,10 +0,0 @@ -//go:build qtpy || m5stamp_c3 - -package main - -import "machine" - -// Replace neo and led in the code below to match the pin -// that you are using if different. -var neo machine.Pin = machine.WS2812 -var led = machine.NoPin diff --git a/examples/ws2812/thingplus-rp2040.go b/examples/ws2812/thingplus-rp2040.go deleted file mode 100644 index a194bdab5..000000000 --- a/examples/ws2812/thingplus-rp2040.go +++ /dev/null @@ -1,12 +0,0 @@ -//go:build thingplus_rp2040 - -package main - -import "machine" - -// This is the pin assignment for the internal neopixel of the -// Sparkfun thingplus rp2040. -// Replace neo and led in the code below to match the pin -// that you are using if different. -var neo machine.Pin = machine.GPIO8 -var led = machine.LED From 9dbfaa87df4c5fd1396ffc01fdb0dca9f3d85ccb Mon Sep 17 00:00:00 2001 From: sago35 Date: Sat, 4 May 2024 23:32:27 +0900 Subject: [PATCH 2/2] Fix typo and move initialization of neo to init() --- examples/ws2812/arduino.go | 8 +++++--- examples/ws2812/digispark.go | 10 ++++++---- examples/ws2812/main.go | 2 +- examples/ws2812/others.go | 8 +++++--- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/examples/ws2812/arduino.go b/examples/ws2812/arduino.go index a47b104d7..6196aec05 100644 --- a/examples/ws2812/arduino.go +++ b/examples/ws2812/arduino.go @@ -4,6 +4,8 @@ package main import "machine" -// Replace neo in the code below to match the pin -// that you are using if different. -var neo = machine.D2 +func init() { + // Replace neo in the code below to match the pin + // that you are using if different. + neo = machine.D2 +} diff --git a/examples/ws2812/digispark.go b/examples/ws2812/digispark.go index ad7f37197..e7d7526b2 100644 --- a/examples/ws2812/digispark.go +++ b/examples/ws2812/digispark.go @@ -4,7 +4,9 @@ package main import "machine" -// This is the pin assignment for the Digispark only. -// Replace neo and led in the code below to match the pin -// that you are using if different. -var neo machine.Pin = 0 +func init() { + // This is the pin assignment for the Digispark only. + // Replace neo and led in the code below to match the pin + // that you are using if different. + neo = machine.Pin(0) +} diff --git a/examples/ws2812/main.go b/examples/ws2812/main.go index 60e19625f..8ade21fd3 100644 --- a/examples/ws2812/main.go +++ b/examples/ws2812/main.go @@ -13,7 +13,7 @@ import ( ) var ( - noe machine.Pin + neo machine.Pin leds [10]color.RGBA ) diff --git a/examples/ws2812/others.go b/examples/ws2812/others.go index 11becd858..27e116e6a 100644 --- a/examples/ws2812/others.go +++ b/examples/ws2812/others.go @@ -4,6 +4,8 @@ package main import "machine" -// Replace neo in the code below to match the pin -// that you are using if different. -var neo machine.Pin = machine.WS2812 +func init() { + // Replace neo in the code below to match the pin + // that you are using if different. + neo = machine.WS2812 +}