https://github.com/drahoslove/go-nec
Implementation of NEC - Infrared transmission protocol - in golang
https://github.com/drahoslove/go-nec
nec protocol
Last synced: 3 months ago
JSON representation
Implementation of NEC - Infrared transmission protocol - in golang
- Host: GitHub
- URL: https://github.com/drahoslove/go-nec
- Owner: drahoslove
- Created: 2017-11-14T14:23:06.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-10-14T22:39:41.000Z (over 6 years ago)
- Last Synced: 2025-01-29T17:14:22.529Z (5 months ago)
- Topics: nec, protocol
- Language: Go
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# go-nec
Implementation of IR transmition NEC protocol in golang## usage
```go
package mainimport (
"os"
"flag"
"github.com/stianeikeland/go-rpio"
"github.com/drahoslav7/go-nec"
)var (
addr uint = 61184 // 24 key ir remote control
cmd uint = 3 // ON
)func init() {
flag.UintVar(&cmd, "c", cmd, "command to send (0-23)")
flag.Parse()
}func main() {
// init gpio
err := rpio.Open()
if err != nil {
os.Exit(1)
}
defer rpio.Close()pin := rpio.Pin(2)
pin.Mode(rpio.Output)
pin.Write(rpio.Low)// transmition funcion
toLED := func(v bool) {
if v {
pin.Write(rpio.High)
} else {
pin.Write(rpio.Low)
}
}
nec.EncodeExt(uint16(addr), uint8(cmd)).TransmitTimes(toLED, 3)
}```
## examples of NEC protocol
#### classic:
`addr = 0`
`cmd = 1``data = addr + ^addr + cmd + ^cmd`
=> `00 FF 80 7F`
```
9 ms | 4.5 ms | addr | ^addr | cmd | ^cmd | end
1111111111111111 00000000 10 10 10 10 10 10 10 10 1000 1000 1000 1000 1000 1000 1000 1000 1000 10 10 10 10 10 10 10 10 1000 1000 1000 1000 1000 1000 1000 10000000...
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1
```
`nec.Encode(0, 1)` or `nec.NewSignal(0x00FF807F)`#### extended:
`addr = 61184`
`cmd = 3``data = low_addr + high_addr + cmd + ^cmd`
=> `00 F7 C0 3F`
```
9 ms | 4.5 ms | low addr | high addr | cmd | ^cmd | end
1111111111111111 00000000 10 10 10 10 10 10 10 10 1000 1000 1000 1000 10 1000 1000 1000 1000 1000 10 10 10 10 10 10 10 10 1000 1000 1000 1000 1000 1000 10000000...
0 0 0 0 0 0 0 0 1 1 1 1 0 1 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1
```
`nec.EncodeExt(61184, 3)` or `nec.NewSignal(0x00F7C03F)`#### repeat code:
```
9 ms |2.25|
1111111111111111 0000 1000...
```
`nec.NewRepeatSignal()`