Safe Haskell | None |
---|---|
Language | Haskell98 |
Synopsis
- module Language.Copilot
- type Sketch = Sketch' ()
- type Input t = Sketch' (Stream t)
- data Output t
- arduino :: Sketch -> IO ()
- (=:) :: Output t -> Stream t -> Sketch
- (@:) :: Output t -> Stream Bool -> Output t
- boolInput :: Pin -> Input Bool
- boolInput' :: Pin -> [Bool] -> Input Bool
- newtype Pin = Pin Int
- led :: Output Bool
- type MicroSeconds = Int16
- delay :: Output MicroSeconds
- firstIteration :: Stream Bool
- sketchSpec :: Sketch -> Spec
Documentation
module Language.Copilot
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.
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 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 -> [Bool] -> Input Bool Source #
The optional list is used as simulated input when interpreting the program.
Outputs
type MicroSeconds = Int16 Source #
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.