Toggling a LED is the ultimate experience! 😄
This can be done viaGPIO pins.
It is recommended to use the GPIO as a sink: plug the long lead (positive side)on the 3.3V rail, the short lead on a 220Ω resistor, which is itself connectedto the GPIO.
The reason is that most boards have an easier time to sink current than sourcecurrent.
periph
doesn’t expose anytoggle-like functionality on purpose, it is asstateless as possible.
packagemainimport("log""time""periph.io/x/conn/v3/gpio""periph.io/x/host/v3""periph.io/x/host/v3/rpi")funcmain(){// Load all the drivers:if_,err:=host.Init();err!=nil{log.Fatal(err)}t:=time.NewTicker(500*time.Millisecond)forl:=gpio.Low;;l=!l{// Lookup a pin by its location on the board:iferr:=rpi.P1_33.Out(l);err!=nil{log.Fatal(err)}<-t.C}}
This example uses basically no CPU: theOut() call above doesn’t call intothe kernel, unlike other Go hardware libraries. Instead itdirectly writes tothe GPIO memory mapped register.
LEDs are generally best bought in bulk (e.g. 200 LEDs in a bag).