Getting Started with Arduino and Go by Agus Kurniawan

Getting Started with Arduino and Go by Agus Kurniawan

Author:Agus Kurniawan [Kurniawan, Agus]
Language: eng
Format: epub
Publisher: PE Press
Published: 2015-03-02T05:00:00+00:00


$ go run main.go

On console, you can see the output as below.

Then, you can see LED is blinking on the Arduino board.

3.3 go-firmata

The second Firmata package for Go is go-firmata. You can read it on https://github.com/kraman/go-firmata . You can install this package by typing this command.

$ go get github.com/kraman/go-firmata

For illustration, we build a simple app, blinking led. We use LED on the board, LED on pin 13.

Now we create project called firmataclient by creating a folder, firmataclient.

$ mkdir firmataclient

$ cd firmataclient

Create a file, called main.go. Write the following code.

package main

import (

"fmt"

"time"

"github.com/kraman/go-firmata"

)

func main() {

board, err := firmata.NewClient("COM6", 57600) if err!=nil {

panic(err)

}

defer board.Close()

fmt.Println("SetPinMode")

board.SetPinMode(13,firmata.Output)

go func() {

fmt.Println("go run")

for {

fmt.Println("LED ON")

board.DigitalWrite(13, true)

time.Sleep(1 * time.Second)

fmt.Println("LED OFF")

board.DigitalWrite(13, false)

time.Sleep(1 * time.Second)

}

}()

// press ENTER to exit

fmt.Println("press Enter to exit..")



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.