gopherbot

package module
v0.0.0-...-b471d4c Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

README

Gopherbot

Gopherbot is a robot gopher plushie that is programmable using TinyGo (https://tinygo.org)

GoDoc

Uses an Adafruit Circuit Playground Express with a 3D printed helmet and backpack.

Here is a TinyGo program that blinks all of the various built-in LEDs all at the same time when the slider switch is in the "on" position.

package main

import (
	"time"

	"github.com/hybridgroup/gopherbot"
)

func main() {
	led := gopherbot.StatusLED()
	antenna := gopherbot.Antenna()
	visor := gopherbot.Visor()
	backpack := gopherbot.Backpack()

	slider := gopherbot.Slider()

	for {
		if slider.IsOn() {
			led.On()
			antenna.On()
			visor.Blue()
			backpack.Blue()
			time.Sleep(500 * time.Millisecond)

			led.Off()
			antenna.Off()
			visor.Off()
			backpack.Off()
			time.Sleep(500 * time.Millisecond)
		}
	}
}

Assembling Your Kit

Did you receive a Gopherbot kit? Awesome! For assembly instructions, go here:

Gopherbot Assembly Instructions

The 3D designs for the helmet, ears, and backpack are created by Damen Evans under the Creative Commons - Attribution - Non-Commercial license. The files are located here:

https://www.thingiverse.com/thing:3761937

Installation

To put code on Gopherbot, you need to install some software on your own machine.

Go 1.18

If you have not installed Go 1.18 on your computer already, you can download it here:

https://golang.org/dl/

TinyGo

Follow the instructions here to install TinyGo:

https://tinygo.org/getting-started/

Gopherbot code

Lastly, get the code from this repository:

git clone https://github.com/hybridgroup/gopherbot.git
cd gopherbot

OK great, we're ready to write our first TinyGo program and put it on Gopherbot.

Hello, Gopherbot

Gopherbot uses an Adafruit Circuit Playground Express as its "brain". To put new code on the Circuit Playground Express you can copy a file in the correct format from your computer to the board using a USB connection without having to install any extra flashing software. This is because it comes with a "bootloader" named UF2 already installed, that lets to do the flashing. Here is more information about the UF2 bootloader if you are interested.

Here is what to do:

  • Plug your Circuit Playground Express into your computer's USB port.
  • Build and flash your TinyGo program to the board in .uf2 format using this command:
tinygo flash -target=gopherbot examples/blinky1
  • The Circuit Playground Express board should restart and then begin running your program. This program just causes the small LED labelled "D13" on the Circuit Playground Express board to start blinking on and off.

Now you are ready to try something a little more flashy.

  • Build and flash the demo TinyGo program to the board using this command:
tinygo flash -target=circuitplay-express ./examples/blink/

Now THAT is a blink!

What To Do Next?

If you want to load one of the example programs on Gopherbot, check out our examples located here.

For a series of activities to learn programming TinyGo using Gopherbot, check out the learn folder.

Have fun!

Gopherbot 2

The Gopherbot 2 is the same as the Gopherbot but uses a Circuit Playground Bluefruit board, which has a Nordic Semiconductors nrf52840 processor with built-in Bluetooth radio.

To flash code on the Gopherbot 2, use the same commands but with the target=gopherbot2.

tinygo flash -target=gopherbot2 ./examples/blink/

Documentation

Overview

Package gopherbot is the TinyGo code for the Gopherbot programmable robotic plushie.

Index

Constants

View Source
const (
	// BackpackLEDCount is how many WS2812 LEDs are on the backpack, aka
	// the Circuit Playground Express.
	BackpackLEDCount = 10

	// VisorLEDCount is how many WS2812 LEDs are on the helmet visor.
	VisorLEDCount = 12
)

Variables

This section is empty.

Functions

func EnsureADCInit

func EnsureADCInit()

EnsureADCInit makes sure that the Gopherbot ADC has been initialized, but is only initialized once.

func EnsureI2CInit

func EnsureI2CInit()

EnsureI2CInit makes sure that the Gopherbot I2C has been initialized, but is only initialized once.

func Rescale

func Rescale(input, fromMin, fromMax, toMin, toMax int32) int32

Rescale performs a direct linear rescaling of an integer from one scale to another.

For example:

val := gopherbot.Rescale(25, 0, 100, 0, 10)

This re-scales the number 25 from a scale that ranges from 0-100, to a scale that ranges from 0-10.

Types

type AccelerometerDevice

type AccelerometerDevice struct {
	lis3dh.Device
}

AccelerometerDevice controls the Gopherbot built-in LIS3DH.

func Accelerometer

func Accelerometer() *AccelerometerDevice

Accelerometer returns the AccelerometerDevice.

type AntennaDevice

type AntennaDevice struct {
	LEDDevice
}

AntennaDevice controls the LED of the Gopherbot Helmet's antenna.

func Antenna

func Antenna() *AntennaDevice

Antenna returns a the Antenna to control the Gopherbot Antenna LED.

type BackpackDevice

type BackpackDevice struct {
	ws2812.Device
	LED []color.RGBA
	// contains filtered or unexported fields
}

BackpackDevice controls the Gopherbot Backpack LED.

func Backpack

func Backpack() *BackpackDevice

Backpack returns a BackpackDevice to control Gopherbot Backpack.

func (*BackpackDevice) Alternate

func (b *BackpackDevice) Alternate(color1, color2 color.RGBA)

Alternate the 2 colors.

func (*BackpackDevice) Blue

func (b *BackpackDevice) Blue()

Blue turns all of the Backpack LEDs b;ue.

func (*BackpackDevice) Clear

func (b *BackpackDevice) Clear()

Clear clears the Backpack LEDs.

func (*BackpackDevice) Green

func (b *BackpackDevice) Green()

Green turns all of the Backpack LEDs green.

func (*BackpackDevice) Off

func (b *BackpackDevice) Off()

Off turns off all the LEDs.

func (*BackpackDevice) Red

func (b *BackpackDevice) Red()

Red turns all of the Backpack LEDs red.

func (*BackpackDevice) SetColor

func (b *BackpackDevice) SetColor(color color.RGBA)

SetColor sets the Backpack LEDs to a single color.

func (*BackpackDevice) Show

func (b *BackpackDevice) Show()

Show sets the Backpack to display the current LED array state.

func (*BackpackDevice) Xmas

func (b *BackpackDevice) Xmas()

Xmas light style that rotates

type ButtonDevice

type ButtonDevice struct {
	machine.Pin
}

ButtonDevice is a button.

func LeftButton

func LeftButton() *ButtonDevice

LeftButton returns the left ButtonDevice.

func RightButton

func RightButton() *ButtonDevice

RightButton returns the right ButtonDriver.

func (*ButtonDevice) Pushed

func (b *ButtonDevice) Pushed() bool

Pushed checks to see if the button is being pushed.

type LEDDevice

type LEDDevice struct {
	machine.Pin
	Speed time.Duration
}

LEDDevice controls any of the standard LEDs on Gopherbot.

func StatusLED

func StatusLED() *LEDDevice

StatusLED returns the built-in LED of the Circuit Playground Express.

func (a *LEDDevice) Blink()

Blink starts the LED blinking repeatedly.

func (*LEDDevice) Off

func (a *LEDDevice) Off()

Off turns off the LED.

func (*LEDDevice) On

func (a *LEDDevice) On()

On turns on the LED.

type LightMeterDevice

type LightMeterDevice struct {
	machine.ADC
}

LightMeterDevice controls the Gopherbot built-in photoresistor.

func LightMeter

func LightMeter() *LightMeterDevice

LightMeter returns the LightMeterDevice.

type SliderDevice

type SliderDevice struct {
	machine.Pin
}

SliderDevice is the slider switch.

func Slider

func Slider() *SliderDevice

Slider returns the SliderDevice.

func (*SliderDevice) IsOn

func (s *SliderDevice) IsOn() bool

IsOn checks to see if the slider is in on position.

type SpeakerDevice

type SpeakerDevice struct {
	buzzer.Device
}

SpeakerDevice is the Gopherbot speaker.

func (*SpeakerDevice) Bleep

func (s *SpeakerDevice) Bleep()

Bleep makes a bleep sound using the speaker.

func (*SpeakerDevice) Blip

func (s *SpeakerDevice) Blip()

Blip makes a blip sound using the speaker.

func (*SpeakerDevice) Bloop

func (s *SpeakerDevice) Bloop()

Bloop makes a bloop sound using the speaker.

type ThermometerDevice

type ThermometerDevice struct {
	thermistor.Device
}

ThermometerDevice controls the Gopherbot built-in thermistor.

func Thermometer

func Thermometer() *ThermometerDevice

Thermometer returns the ThermometerDevice.

type VisorDevice

type VisorDevice struct {
	ws2812.Device
	LED []color.RGBA
	// contains filtered or unexported fields
}

VisorDevice controls the Gopherbot Visor Neopixel LED.

func Visor

func Visor() *VisorDevice

Visor returns a new VisorDevice to control Gopherbot Visor.

func (*VisorDevice) Alternate

func (v *VisorDevice) Alternate(color1, color2 color.RGBA)

Alternate the 2 colors.

func (*VisorDevice) Blue

func (v *VisorDevice) Blue()

Blue turns all of the Visor LEDs blue.

func (*VisorDevice) Clear

func (v *VisorDevice) Clear()

Clear clears the visor.

func (*VisorDevice) Cylon

func (v *VisorDevice) Cylon()

Cylon visor mode.

func (*VisorDevice) Green

func (v *VisorDevice) Green()

Green turns all of the Visor LEDs green.

func (*VisorDevice) Off

func (v *VisorDevice) Off()

Off turns off all the LEDs.

func (*VisorDevice) Red

func (v *VisorDevice) Red()

Red turns all of the Visor LEDs red.

func (*VisorDevice) SetColor

func (v *VisorDevice) SetColor(color color.RGBA)

SetColor sets the Visor LEDs to a single color.

func (*VisorDevice) Show

func (v *VisorDevice) Show()

Show sets the visor to display the current LED array state.

func (*VisorDevice) Xmas

func (v *VisorDevice) Xmas()

Xmas light style

Directories

Path Synopsis
examples
learn

Jump to

Keyboard shortcuts

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