From 31173163323e0b6bda163b1fc1c1933cbb3d4353 Mon Sep 17 00:00:00 2001 From: Daniel Esteban Date: Wed, 15 Apr 2026 23:11:30 +0200 Subject: [PATCH] added nicebadge --- defs_nicebadge.go | 146 ++++++++++++++++++++++++++++++++++++++++++++++ main.go | 3 - 2 files changed, 146 insertions(+), 3 deletions(-) create mode 100644 defs_nicebadge.go diff --git a/defs_nicebadge.go b/defs_nicebadge.go new file mode 100644 index 0000000..8a94697 --- /dev/null +++ b/defs_nicebadge.go @@ -0,0 +1,146 @@ +//go:build nicenano +// +build nicenano + +package main + +import ( + "image/color" + "machine" + + "tinygo.org/x/drivers/encoders" + "tinygo.org/x/drivers/st7789" + "tinygo.org/x/drivers/ws2812" +) + +const ( + hardware_name = "NICEBADGE" + displayWidth = 240 + displayHeight = 135 +) + +// UI layout constants for nicebadge (240x135) +const ( + // myNameIs layout + cornerRadius = 10 + topBandHeight = 20 + bottomBandHeight = 10 + helloY = 20 + myNameIsY = 20 + gophersY = 110 + gophersX = 48 + + // menu layout + menuItemSpace = 20 + menuCircleR = 6 + + numLEDs = 2 + + buttonBack = buttonB +) + +var menuOptions = []int8{ + modeBadge, + modeSchedule, + modeAdventure, + modeLEDs, + modeMusic, + modeGameSnake, + modeGameLife, + modeGameColors, + modeInfo, +} + +// Font size thresholds for gopherbadge +const ( + FontWidthThreshold = 300 +) + +var ( + display st7789.Device + btnA machine.Pin + btnB machine.Pin + btnStart machine.Pin + + ax machine.ADC + ay machine.ADC + enc *encoders.QuadratureDevice +) + +func initHardware() { + machine.SPI0.Configure(machine.SPIConfig{ + SCK: machine.P1_01, + SDO: machine.P1_02, + Frequency: 2.0 * machine.MHz, + Mode: 0, + }) + + machine.I2C1.Configure(machine.I2CConfig{ + SDA: machine.P0_17, + SCL: machine.P0_20, + Frequency: 2.0 * machine.MHz, + }) + display = st7789.New(machine.SPI0, + machine.P1_15, // TFT_RESET + machine.P1_13, // TFT_DC + machine.P0_10, // TFT_CS + machine.P0_09) // TFT_LITE + + display.Configure(st7789.Config{ + Rotation: st7789.ROTATION_90, + Width: 135, + Height: 240, + RowOffset: 40, + ColumnOffset: 53, + //FrameRate: st7789.FRAMERATE_111, + //VSyncLines: st7789.MAX_VSYNC_SCANLINES, + }) + + neo := machine.P1_11 + neo.Configure(machine.PinConfig{Mode: machine.PinOutput}) + leds = ws2812.New(neo) + + bzrPin = machine.P0_31 + bzrPin.Configure(machine.PinConfig{Mode: machine.PinOutput}) + + //pwm := machine.PWM0 + //speaker, _ := tone.New(pwm, bzrPin) + + machine.InitADC() + ax = machine.ADC{Pin: machine.P0_02} + ay = machine.ADC{Pin: machine.P0_29} + ax.Configure(machine.ADCConfig{}) + ay.Configure(machine.ADCConfig{}) + + enc = encoders.NewQuadratureViaInterrupt(machine.P1_00, machine.P0_24) + enc.Configure(encoders.QuadratureConfig{ + Precision: 4, + }) + + btnStart = machine.P0_22 + btnA = machine.P1_06 + btnB = machine.P1_04 + btnStart.Configure(machine.PinConfig{Mode: machine.PinInputPullup}) + btnA.Configure(machine.PinConfig{Mode: machine.PinInputPullup}) + btnB.Configure(machine.PinConfig{Mode: machine.PinInputPullup}) + + black := color.RGBA{0, 0, 0, 255} + display.FillScreen(black) + +} + +func getInput() { + for b := 0; b < 9; b++ { + buttonsOldState[b] = buttonsState[b] + } + + buttonsState[buttonA] = !btnA.Get() + buttonsState[buttonB] = !btnB.Get() + buttonsState[buttonStart] = !btnStart.Get() + + buttonsState[buttonLeft] = (ax.Get() < 12000) + buttonsState[buttonRight] = (ax.Get() > 52000) + buttonsState[buttonDown] = (ay.Get() < 12000) + buttonsState[buttonUp] = (ay.Get() > 52000) +} + +func Accel3D() {} diff --git a/main.go b/main.go index 79298f3..b9e532e 100644 --- a/main.go +++ b/main.go @@ -87,9 +87,6 @@ func main() { display.FillScreen(colorBlack) setCustomData() - for { - scroll("ABC", "XYZ", "123") - } Info() for {