1
0
mirror of https://github.com/kidoman/embd synced 2024-10-31 23:38:44 +01:00
embd/doc.go

89 lines
1.9 KiB
Go
Raw Normal View History

2013-12-08 22:19:39 +01:00
/*
2014-04-16 10:35:13 +02:00
Package embd provides a hardware abstraction layer for doing embedded programming
2014-03-23 11:17:58 +01:00
on supported platforms like the Raspberry Pi and BeagleBone Black. Most of the examples below
will work without change (i.e. the same binary) on all supported platforms. How cool is that?
2013-12-08 22:19:39 +01:00
Although samples are all present in the samples folder, we will show a few choice examples here.
2014-03-23 11:17:58 +01:00
Use the LED driver to toggle LEDs on the BBB:
2013-12-08 22:19:39 +01:00
2014-03-23 11:17:58 +01:00
import "github.com/kidoman/embd"
...
embd.InitLED()
defer embd.CloseLED()
...
led, err := embd.NewLED("USR3")
...
led.Toggle()
2013-12-08 22:19:39 +01:00
2014-03-23 11:17:58 +01:00
Even shorter while prototyping:
2013-12-08 22:19:39 +01:00
2014-03-23 11:17:58 +01:00
import "github.com/kidoman/embd"
...
embd.InitLED()
defer embd.CloseLED()
...
embd.ToggleLED(3)
2013-12-08 22:19:39 +01:00
2014-03-29 05:16:45 +01:00
BBB + PWM:
2014-03-28 04:09:36 +01:00
import "github.com/kidoman/embd"
...
embd.InitGPIO()
defer embd.CloseGPIO()
...
pwm, _ := embd.NewPWMPin("P9_14")
defer pwm.Close()
...
pwm.SetDuty(1000)
2014-03-23 11:17:58 +01:00
Control GPIO pins on the RaspberryPi / BeagleBone Black:
2013-12-08 22:19:39 +01:00
2014-03-23 11:17:58 +01:00
import "github.com/kidoman/embd"
...
embd.InitGPIO()
defer embd.CloseGPIO()
...
embd.SetDirection(10, embd.Out)
embd.DigitalWrite(10, embd.High)
Could also do:
import "github.com/kidoman/embd"
...
embd.InitGPIO()
defer embd.CloseGPIO()
...
pin, err := embd.NewDigitalPin(10)
...
pin.SetDirection(embd.Out)
pin.Write(embd.High)
Or read data from the Bosch BMP085 barometric sensor:
import "github.com/kidoman/embd"
import "github.com/kidoman/embd/sensor/bmp085"
...
bus := embd.NewI2CBus(1)
...
baro := bmp085.New(bus)
...
temp, err := baro.Temperature()
altitude, err := baro.Altitude()
Even find out the heading from the LSM303 magnetometer:
import "github.com/kidoman/embd"
import "github.com/kidoman/embd/sensor/lsm303"
...
bus := embd.NewI2CBus(1)
...
mag := lsm303.New(bus)
...
heading, err := mag.Heading()
The above two examples depend on I2C and therefore will work without change on almost all
platforms.
2013-12-08 22:19:39 +01:00
*/
package embd