tinygo.org/x/drivers@v0.27.1-0.20240509133757-7dbca2a54349/examples/irremote/main.go (about) 1 package main 2 3 import ( 4 "machine" 5 "time" 6 7 "tinygo.org/x/drivers/irremote" 8 ) 9 10 var irCmdButtons = map[uint16]string{ 11 0x45: "POWER", 12 0x47: "FUNC/STOP", 13 0x46: "VOL+", 14 0x44: "FAST BACK", 15 0x40: "PAUSE", 16 0x43: "FAST FORWARD", 17 0x07: "DOWN", 18 0x15: "VOL-", 19 0x09: "UP", 20 0x19: "EQ", 21 0x0D: "ST/REPT", 22 0x16: "0", 23 0x0C: "1", 24 0x18: "2", 25 0x5E: "3", 26 0x08: "4", 27 0x1C: "5", 28 0x5A: "6", 29 0x42: "7", 30 0x52: "8", 31 0x4A: "9", 32 } 33 34 var ( 35 pinIRIn = machine.GP26 36 ir irremote.ReceiverDevice 37 ) 38 39 func setupPins() { 40 ir = irremote.NewReceiver(pinIRIn) 41 ir.Configure() 42 } 43 44 func irCallback(data irremote.Data) { 45 msg := "Command: " + irCmdButtons[data.Command] 46 if data.Flags&irremote.DataFlagIsRepeat != 0 { 47 msg = msg + " (REPEAT)" 48 } 49 println(msg) 50 } 51 52 func main() { 53 setupPins() 54 ir.SetCommandHandler(irCallback) 55 for { 56 time.Sleep(time.Millisecond * 10) 57 } 58 }