spark

package
v0.0.0-...-21b411a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 25, 2014 License: Apache-2.0, Apache-2.0 Imports: 8 Imported by: 0

README

Spark

The Spark Core contains a Wi-Fi connected microcontroller. Once it connects to a Wi-Fi network, it automatically connects with a central server (the "Spark Cloud") and stays connected so it can be controlled from external systems, such as a Gobot program. To run gobot programs please make sure you are running default tinker firmware on the Spark Core.

For more info about the Spark platform click here

How to Install

Installing Gobot with Spark support is pretty easy.

go get github.com/hybridgroup/gobot && go install github.com/hybridgroup/gobot/platforms/spark

How to Use

package main

import (
	"time"

	"github.com/hybridgroup/gobot"
	"github.com/hybridgroup/gobot/platforms/gpio"
	"github.com/hybridgroup/gobot/platforms/spark"
)

func main() {
	gbot := gobot.NewGobot()

	sparkCore := spark.NewSparkCoreAdaptor("spark", "device_id", "access_token")
	led := gpio.NewLedDriver(sparkCore, "led", "D7")

	work := func() {
		gobot.Every(1*time.Second, func() {
			led.Toggle()
		})
	}

	robot := gobot.NewRobot("spark",
		[]gobot.Connection{sparkCore},
		[]gobot.Device{led},
		work,
	)

	gbot.AddRobot(robot)

	gbot.Start()
}

Documentation

Overview

Package spark provides the Gobot adaptor for the Spark Core.

Installing:

go get github.com/hybridgroup/gobot && go install github.com/hybridgroup/gobot/platforms/spark

Example:

package main

import (
	"time"

	"github.com/hybridgroup/gobot"
	"github.com/hybridgroup/gobot/platforms/gpio"
	"github.com/hybridgroup/gobot/platforms/spark"
)

func main() {
	gbot := gobot.NewGobot()

	sparkCore := spark.NewSparkCoreAdaptor("spark", "device_id", "access_token")
	led := gpio.NewLedDriver(sparkCore, "led", "D7")

	work := func() {
		gobot.Every(1*time.Second, func() {
			led.Toggle()
		})
	}

	robot := gobot.NewRobot("spark",
		[]gobot.Connection{sparkCore},
		[]gobot.Device{led},
		work,
	)

	gbot.AddRobot(robot)

	gbot.Start()
}

For further information refer to spark readme: https://github.com/hybridgroup/gobot/blob/master/platforms/spark/README.md

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SparkCoreAdaptor

type SparkCoreAdaptor struct {
	DeviceID    string
	AccessToken string
	APIServer   string
	// contains filtered or unexported fields
}

func NewSparkCoreAdaptor

func NewSparkCoreAdaptor(name string, deviceID string, accessToken string) *SparkCoreAdaptor

NewSparkCoreAdaptor creates new spark core adaptor with deviceId and accessToken using api.spark.io server as default

func (*SparkCoreAdaptor) AnalogRead

func (s *SparkCoreAdaptor) AnalogRead(pin string) (val int, err error)

AnalogRead reads analog ping value using spark cloud api

func (*SparkCoreAdaptor) AnalogWrite

func (s *SparkCoreAdaptor) AnalogWrite(pin string, level byte) (err error)

AnalogWrite writes analog pin with specified level using spark cloud api

func (*SparkCoreAdaptor) Connect

func (s *SparkCoreAdaptor) Connect() (errs []error)

Connect returns true if connection to spark core is succesfull

func (*SparkCoreAdaptor) DigitalRead

func (s *SparkCoreAdaptor) DigitalRead(pin string) (val int, err error)

DigitalRead reads from digital pin using spark cloud api

func (*SparkCoreAdaptor) DigitalWrite

func (s *SparkCoreAdaptor) DigitalWrite(pin string, level byte) (err error)

DigitalWrite writes to a digital pin using spark cloud api

func (*SparkCoreAdaptor) Finalize

func (s *SparkCoreAdaptor) Finalize() (errs []error)

Finalize returns true if connection to spark core is finalized successfully

func (*SparkCoreAdaptor) Name

func (s *SparkCoreAdaptor) Name() string

func (*SparkCoreAdaptor) PwmWrite

func (s *SparkCoreAdaptor) PwmWrite(pin string, level byte) (err error)

PwmWrite writes in pin using analog write api

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL