arduino-copilot-0.0.1: Arduino programming in haskell using the stream DSL

Safe HaskellNone
LanguageHaskell98

Arduino

Contents

Synopsis

Documentation

Arduino sketch generation

type Sketch = Sketch' () Source #

An Arduino sketch, implemented using copilot.

On each iteration of a Sketch, all inputs used by it are first collected, before any outputs are performed.

Like a copilot Spec, a Sketch's outputs are not run in any particular order.

type Input t = Sketch' (Stream t) Source #

A source of a Stream of values input from the Arduino.

data Output t Source #

Somewhere that a Stream can be directed to, in order to control the Arduino.

arduino :: Sketch -> IO () Source #

Typically your Arduino program's main will use this. For example:

 main = arduino $ do
	led =: clk (period 2) (phase 1)
 	delay =: const16 100

The Sketch is compiled into C code using copilot, and written to a .ino file. That can be built and uploaded to your Arduino using the Arduino IDE, or any other toolchain for Arduino sketches.

Combinators

(=:) :: Output t -> Stream t -> Sketch infixr 1 Source #

Connect a Stream to an Output.

(@:) :: Output t -> Stream Bool -> Output t Source #

By default, an Output is written to on each iteration of the Sketch.

For example, this constantly turns on the LED, even though it will already be on after the first iteration.

led =: true

To avoid unnecessary work being done, this combinator can make an Output only be written to when the current value of the provided Stream is True.

So to make the LED only be turned on in the first iteration, and allow it to remain on thereafter without doing extra work:

led @: firstIteration =: true

Inputs

boolInput :: Pin -> Input Bool Source #

Reading from a GPIO pin.

boolInput' :: Pin -> [Bool] -> Input Bool Source #

The optional list is used as simulated input when interpreting the program.

newtype Pin Source #

A GPIO pin

Constructors

Pin Int 

Outputs

led :: Output Bool Source #

The on-board LED.

delay :: Output MicroSeconds Source #

Use this to add a delay between each iteration of the Sketch.

Utilities

firstIteration :: Stream Bool Source #

True on the first iteration of the Sketch, and False thereafter.

sketchSpec :: Sketch -> Spec Source #

Extracts a copilot Spec from a Sketch.

This can be useful to intergrate with other libraries such as copilot-theorem.