doc: use ``` for embedded code

This commit is contained in:
Karan Misra 2014-05-19 11:27:57 +05:30
parent b0f00069b5
commit 5e17d3721c
1 changed files with 70 additions and 56 deletions

126
README.md
View File

@ -100,82 +100,96 @@ we will show a few choice examples here.
Use the **LED** driver to toggle LEDs on the BBB: Use the **LED** driver to toggle LEDs on the BBB:
import "github.com/kidoman/embd" ```go
... import "github.com/kidoman/embd"
embd.InitLED() ...
defer embd.CloseLED() embd.InitLED()
... defer embd.CloseLED()
led, err := embd.NewLED(3) ...
... led, err := embd.NewLED(3)
led.Toggle() ...
led.Toggle()
```
Even shorter when quickly trying things out: Even shorter when quickly trying things out:
import "github.com/kidoman/embd" ```go
... import "github.com/kidoman/embd"
embd.InitLED() ...
defer embd.CloseLED() embd.InitLED()
... defer embd.CloseLED()
embd.ToggleLED(3) ...
embd.ToggleLED(3)
```
**3** is the same as **USR3** for all intents and purposes. The driver is smart enough to figure all this out. **3** is the same as **USR3** for all intents and purposes. The driver is smart enough to figure all this out.
BBB + **PWM**: BBB + **PWM**:
import "github.com/kidoman/embd" ```go
... import "github.com/kidoman/embd"
embd.InitGPIO() ...
defer embd.CloseGPIO() embd.InitGPIO()
... defer embd.CloseGPIO()
pwm, _ := embd.NewPWMPin("P9_14") ...
defer pwm.Close() pwm, _ := embd.NewPWMPin("P9_14")
... defer pwm.Close()
pwm.SetDuty(1000) ...
pwm.SetDuty(1000)
```
Control **GPIO** pins on the RaspberryPi / BeagleBone Black: Control **GPIO** pins on the RaspberryPi / BeagleBone Black:
import "github.com/kidoman/embd" ```go
... import "github.com/kidoman/embd"
embd.InitGPIO() ...
defer embd.CloseGPIO() embd.InitGPIO()
... defer embd.CloseGPIO()
embd.SetDirection(10, embd.Out) ...
embd.DigitalWrite(10, embd.High) embd.SetDirection(10, embd.Out)
embd.DigitalWrite(10, embd.High)
```
Could also do: Could also do:
import "github.com/kidoman/embd" ```go
... import "github.com/kidoman/embd"
embd.InitGPIO() ...
defer embd.CloseGPIO() embd.InitGPIO()
... defer embd.CloseGPIO()
pin, err := embd.NewDigitalPin(10) ...
... pin, err := embd.NewDigitalPin(10)
pin.SetDirection(embd.Out) ...
pin.Write(embd.High) pin.SetDirection(embd.Out)
pin.Write(embd.High)
```
Or read data from the **Bosch BMP085** barometric sensor: Or read data from the **Bosch BMP085** barometric sensor:
import "github.com/kidoman/embd" ```go
import "github.com/kidoman/embd/sensor/bmp085" import "github.com/kidoman/embd"
... import "github.com/kidoman/embd/sensor/bmp085"
bus := embd.NewI2CBus(1) ...
... bus := embd.NewI2CBus(1)
baro := bmp085.New(bus) ...
... baro := bmp085.New(bus)
temp, err := baro.Temperature() ...
altitude, err := baro.Altitude() temp, err := baro.Temperature()
altitude, err := baro.Altitude()
```
Even find out the heading from the **LSM303** magnetometer: Even find out the heading from the **LSM303** magnetometer:
import "github.com/kidoman/embd" ```go
import "github.com/kidoman/embd/sensor/lsm303" import "github.com/kidoman/embd"
... import "github.com/kidoman/embd/sensor/lsm303"
bus := embd.NewI2CBus(1) ...
... bus := embd.NewI2CBus(1)
mag := lsm303.New(bus) ...
... mag := lsm303.New(bus)
heading, err := mag.Heading() ...
heading, err := mag.Heading()
```
The above two examples depend on **I2C** and therefore will work without change on almost all The above two examples depend on **I2C** and therefore will work without change on almost all
platforms. platforms.