packages feed

arduino-copilot 1.5.1 → 1.5.2

raw patch · 64 files changed

+1771/−1531 lines, 64 filesdep +arduino-copilotdep +processdep +temporarydep −unixdep ~basePVP ok

version bump matches the API change (PVP)

Dependencies added: arduino-copilot, process, temporary

Dependencies removed: unix

Dependency ranges changed: base

API changes (from Hackage documentation)

+ Copilot.Arduino.Library.Random: data RandomInput
+ Copilot.Arduino.Library.Random: data RandomSeed
+ Copilot.Arduino.Library.Random: instance Copilot.Arduino.Internals.Input Copilot.Arduino.Library.Random.RandomInput GHC.Word.Word32
+ Copilot.Arduino.Library.Random: instance Copilot.Arduino.Internals.Output Copilot.Arduino.Library.Random.RandomSeed (Copilot.Arduino.Internals.Event () (Copilot.Language.Stream.Stream Copilot.Arduino.Internals.ADC))
+ Copilot.Arduino.Library.Random: instance Copilot.Arduino.Internals.Output Copilot.Arduino.Library.Random.RandomSeed (Copilot.Arduino.Internals.Event () (Copilot.Language.Stream.Stream GHC.Word.Word8))
+ Copilot.Arduino.Library.Random: random :: Word32 -> RandomInput
+ Copilot.Arduino.Library.Random: randomR :: (Word32, Word32) -> RandomInput
+ Copilot.Arduino.Library.Random: randomSeed :: RandomSeed
+ Copilot.Arduino.Library.Random: randomSeedPin :: IsAnalogInputPin t => Pin t -> Sketch ()

Files

CHANGELOG view
@@ -1,3 +1,13 @@+arduino-copilot (1.5.2) unstable; urgency=medium++  * Zurihac 2020 edition.+  * Remove dependency on 'unix' to allow building on Windows.+    Thanks, Adam Piper+  * Added Copilot.Arduino.Library.Random+  * Add test suite, which checks that all the examples compile.++ -- Joey Hess <id@joeyh.name>  Sun, 14 Jun 2020 14:55:28 -0400+ arduino-copilot (1.5.1) unstable; urgency=medium    * Fix type of pullup, limiting it to digital IO pins.
+ Examples/Blink/Demo.hs view
@@ -0,0 +1,10 @@+{-# LANGUAGE RebindableSyntax #-}++module Examples.Blink.Demo where++import Copilot.Arduino++main :: IO ()+main = arduino $ do+	led =: blinking+	delay =: MilliSeconds (constant 100)
+ Examples/Blink/Makefile view
@@ -0,0 +1,127 @@+# Arduino Make file. Refer to https://github.com/sudar/Arduino-Makefile+BOARD_TAG    = uno+include /usr/share/arduino/Arduino.mk++# --- leonardo (or pro micro w/leo bootloader)+#BOARD_TAG    = leonardo+#MONITOR_PORT = /dev/ttyACM0+#include /usr/share/arduino/Arduino.mk++# --- mega2560 ide 1.0+#BOARD_TAG    = mega2560+#ARDUINO_PORT = /dev/ttyACM0+#include /usr/share/arduino/Arduino.mk++# --- mega2560 ide 1.6+#BOARD_TAG    = mega+#BOARD_SUB    = atmega2560+#MONITOR_PORT = /dev/ttyACM0+#ARDUINO_DIR  = /where/you/installed/arduino-1.6.5+#include /usr/share/arduino/Arduino.mk++# --- nano ide 1.0+#BOARD_TAG    = nano328+#MONITOR_PORT = /dev/ttyUSB0+#include /usr/share/arduino/Arduino.mk++# --- nano ide 1.6+#BOARD_TAG   = nano+#BOARD_SUB   = atmega328+#ARDUINO_DIR = /where/you/installed/arduino-1.6.5+#include /usr/share/arduino/Arduino.mk++# --- pro mini+#BOARD_TAG    = pro5v328+#MONITOR_PORT = /dev/ttyUSB0+#include /usr/share/arduino/Arduino.mk++# --- sparkfun pro micro+#BOARD_TAG         = promicro16+#ALTERNATE_CORE    = promicro+#BOARDS_TXT        = $(HOME)/arduino/hardware/promicro/boards.txt+#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/promicro/bootloaders+#BOOTLOADER_PATH   = caterina+#BOOTLOADER_FILE   = Caterina-promicro16.hex+#ISP_PROG     	   = usbasp+#AVRDUDE_OPTS 	   = -v+#include /usr/share/arduino/Arduino.mk++# --- chipkit+#BOARD_TAG = mega_pic32+#MPIDE_DIR = /where/you/installed/mpide-0023-linux64-20130817-test+#include /usr/share/arduino/chipKIT.mk++# --- pinoccio+#BOARD_TAG         = pinoccio256+#ALTERNATE_CORE    = pinoccio+#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/pinoccio/bootloaders+#BOOTLOADER_PATH   = STK500RFR2/release_0.51+#BOOTLOADER_FILE   = boot_pinoccio.hex+#CFLAGS_STD        = -std=gnu99+#CXXFLAGS_STD      = -std=gnu++11+#include /usr/share/arduino/Arduino.mk++# --- fio+#BOARD_TAG = fio+#include /usr/share/arduino/Arduino.mk++# --- atmega-ng ide 1.6+#BOARD_TAG    = atmegang+#BOARD_SUB    = atmega168+#MONITOR_PORT = /dev/ttyACM0+#ARDUINO_DIR  = /where/you/installed/arduino-1.6.5+#include /usr/share/arduino/Arduino.mk++# --- arduino-tiny ide 1.0+#ISP_PROG     	    = usbasp+#BOARD_TAG          = attiny85at8+#ALTERNATE_CORE     = tiny+#ARDUINO_VAR_PATH   = $(HOME)/arduino/hardware/tiny/cores/tiny+#ARDUINO_CORE_PATH  = $(HOME)/arduino/hardware/tiny/cores/tiny+#AVRDUDE_OPTS 	    = -v+#include /usr/share/arduino/Arduino.mk++# --- arduino-tiny ide 1.6+#ISP_PROG       = usbasp+#BOARD_TAG      = attiny85at8+#ALTERNATE_CORE = tiny+#ARDUINO_DIR    = /where/you/installed/arduino-1.6.5+#include /usr/share/arduino/Arduino.mk++# --- damellis attiny ide 1.0+#ISP_PROG       = usbasp+#BOARD_TAG      = attiny85+#ALTERNATE_CORE = attiny-master+#AVRDUDE_OPTS   = -v+#include /usr/share/arduino/Arduino.mk++# --- damellis attiny ide 1.6+#ISP_PROG       = usbasp+#BOARD_TAG      = attiny+#BOARD_SUB      = attiny85+#ALTERNATE_CORE = attiny+#F_CPU          = 16000000L+#ARDUINO_DIR    = /where/you/installed/arduino-1.6.5+#include /usr/share/arduino/Arduino.mk++# --- teensy3+#BOARD_TAG 	 = teensy31+#ARDUINO_DIR = /where/you/installed/the/patched/teensy/arduino-1.0.6+#include /usr/share/arduino/Teensy.mk++# --- mighty 1284p+#BOARD_TAG         = mighty_opt+#BOARDS_TXT        = $(HOME)/arduino/hardware/mighty-1284p/boards.txt+#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/mighty-1284p/bootloaders+#BOOTLOADER_PATH   = optiboot+#BOOTLOADER_FILE   = optiboot_atmega1284p.hex+#ISP_PROG     	   = usbasp+#AVRDUDE_OPTS 	   = -v+#include /usr/share/arduino/Arduino.mk++# --- atmega328p on breadboard+#BOARD_TAG    = atmega328bb+#ISP_PROG     = usbasp+#AVRDUDE_OPTS = -v+#BOARDS_TXT   = $(HOME)/arduino/hardware/breadboard/boards.txt+#include /usr/share/arduino/Arduino.mk
+ Examples/Blink/README view
@@ -0,0 +1,28 @@+This is a demo program using arduino-copilot. ++To build the C code:++	runghc Demo.hs++The resulting `.ino` sketch can be loaded into the Arduino IDE and flashed+to an Arduino board using the IDE.++It simply flashes the Arduino's on board LED, so should work on most or all+Arduino boards.++## Arduino-Makefile integration++The `Makefile` and `pre-build-hook.sh` show how to integrate arduino-copilot+with <https://github.com/sudar/Arduino-Makefile>. This automates generating+the C code, compiling that, and flashing it onto an Arduino Uno board,+with a single command++	make upload++Note that you will need to manually build the C code once, as shown above,+since the Arduino-Makefile expects to find a `.ino` file.++The path in the `Makefile` to `Arduino.mk` may need to be adjusted (the+default is the location where on a Debian system, `apt-get install+arduino-mk` will install it). You may also adjust the `Makefile` to target+a different board than the Arduino Uno.
+ Examples/Blink/pre-build-hook.sh view
@@ -0,0 +1,2 @@+#!/bin/sh+exec runghc Demo.hs
+ Examples/Button/Demo.hs view
@@ -0,0 +1,24 @@+{-# LANGUAGE RebindableSyntax #-}++module Examples.Button.Demo where++import Copilot.Arduino.Uno++longer_and_longer :: Stream Word32+longer_and_longer = counter true $ counter true false `mod` 64 == 0++counter :: Stream Bool -> Stream Bool -> Stream Word32+counter inc reset = cnt+   where+	cnt = if reset+		then 0+		else if inc+			then z + 1+			else z+	z = [0] ++ cnt++main :: IO ()+main = arduino $ do+	buttonpressed <- input' pin12 [False, False, False, True, True]+	led =: buttonpressed || blinking+	delay =: MilliSeconds (longer_and_longer * 2)
+ Examples/Button/Makefile view
@@ -0,0 +1,127 @@+# Arduino Make file. Refer to https://github.com/sudar/Arduino-Makefile+BOARD_TAG    = uno+include /usr/share/arduino/Arduino.mk++# --- leonardo (or pro micro w/leo bootloader)+#BOARD_TAG    = leonardo+#MONITOR_PORT = /dev/ttyACM0+#include /usr/share/arduino/Arduino.mk++# --- mega2560 ide 1.0+#BOARD_TAG    = mega2560+#ARDUINO_PORT = /dev/ttyACM0+#include /usr/share/arduino/Arduino.mk++# --- mega2560 ide 1.6+#BOARD_TAG    = mega+#BOARD_SUB    = atmega2560+#MONITOR_PORT = /dev/ttyACM0+#ARDUINO_DIR  = /where/you/installed/arduino-1.6.5+#include /usr/share/arduino/Arduino.mk++# --- nano ide 1.0+#BOARD_TAG    = nano328+#MONITOR_PORT = /dev/ttyUSB0+#include /usr/share/arduino/Arduino.mk++# --- nano ide 1.6+#BOARD_TAG   = nano+#BOARD_SUB   = atmega328+#ARDUINO_DIR = /where/you/installed/arduino-1.6.5+#include /usr/share/arduino/Arduino.mk++# --- pro mini+#BOARD_TAG    = pro5v328+#MONITOR_PORT = /dev/ttyUSB0+#include /usr/share/arduino/Arduino.mk++# --- sparkfun pro micro+#BOARD_TAG         = promicro16+#ALTERNATE_CORE    = promicro+#BOARDS_TXT        = $(HOME)/arduino/hardware/promicro/boards.txt+#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/promicro/bootloaders+#BOOTLOADER_PATH   = caterina+#BOOTLOADER_FILE   = Caterina-promicro16.hex+#ISP_PROG     	   = usbasp+#AVRDUDE_OPTS 	   = -v+#include /usr/share/arduino/Arduino.mk++# --- chipkit+#BOARD_TAG = mega_pic32+#MPIDE_DIR = /where/you/installed/mpide-0023-linux64-20130817-test+#include /usr/share/arduino/chipKIT.mk++# --- pinoccio+#BOARD_TAG         = pinoccio256+#ALTERNATE_CORE    = pinoccio+#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/pinoccio/bootloaders+#BOOTLOADER_PATH   = STK500RFR2/release_0.51+#BOOTLOADER_FILE   = boot_pinoccio.hex+#CFLAGS_STD        = -std=gnu99+#CXXFLAGS_STD      = -std=gnu++11+#include /usr/share/arduino/Arduino.mk++# --- fio+#BOARD_TAG = fio+#include /usr/share/arduino/Arduino.mk++# --- atmega-ng ide 1.6+#BOARD_TAG    = atmegang+#BOARD_SUB    = atmega168+#MONITOR_PORT = /dev/ttyACM0+#ARDUINO_DIR  = /where/you/installed/arduino-1.6.5+#include /usr/share/arduino/Arduino.mk++# --- arduino-tiny ide 1.0+#ISP_PROG     	    = usbasp+#BOARD_TAG          = attiny85at8+#ALTERNATE_CORE     = tiny+#ARDUINO_VAR_PATH   = $(HOME)/arduino/hardware/tiny/cores/tiny+#ARDUINO_CORE_PATH  = $(HOME)/arduino/hardware/tiny/cores/tiny+#AVRDUDE_OPTS 	    = -v+#include /usr/share/arduino/Arduino.mk++# --- arduino-tiny ide 1.6+#ISP_PROG       = usbasp+#BOARD_TAG      = attiny85at8+#ALTERNATE_CORE = tiny+#ARDUINO_DIR    = /where/you/installed/arduino-1.6.5+#include /usr/share/arduino/Arduino.mk++# --- damellis attiny ide 1.0+#ISP_PROG       = usbasp+#BOARD_TAG      = attiny85+#ALTERNATE_CORE = attiny-master+#AVRDUDE_OPTS   = -v+#include /usr/share/arduino/Arduino.mk++# --- damellis attiny ide 1.6+#ISP_PROG       = usbasp+#BOARD_TAG      = attiny+#BOARD_SUB      = attiny85+#ALTERNATE_CORE = attiny+#F_CPU          = 16000000L+#ARDUINO_DIR    = /where/you/installed/arduino-1.6.5+#include /usr/share/arduino/Arduino.mk++# --- teensy3+#BOARD_TAG 	 = teensy31+#ARDUINO_DIR = /where/you/installed/the/patched/teensy/arduino-1.0.6+#include /usr/share/arduino/Teensy.mk++# --- mighty 1284p+#BOARD_TAG         = mighty_opt+#BOARDS_TXT        = $(HOME)/arduino/hardware/mighty-1284p/boards.txt+#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/mighty-1284p/bootloaders+#BOOTLOADER_PATH   = optiboot+#BOOTLOADER_FILE   = optiboot_atmega1284p.hex+#ISP_PROG     	   = usbasp+#AVRDUDE_OPTS 	   = -v+#include /usr/share/arduino/Arduino.mk++# --- atmega328p on breadboard+#BOARD_TAG    = atmega328bb+#ISP_PROG     = usbasp+#AVRDUDE_OPTS = -v+#BOARDS_TXT   = $(HOME)/arduino/hardware/breadboard/boards.txt+#include /usr/share/arduino/Arduino.mk
+ Examples/Button/README view
@@ -0,0 +1,24 @@+This is a demo program using arduino-copilot. ++To build the C code:++	runghc Demo.hs++The resulting `.ino` sketch can be loaded into the Arduino IDE and flashed+to an Arduino Uno board using the IDE.++## Arduino-Makefile integration++The `Makefile` and `pre-build-hook.sh` show how to integrate arduino-copilot+with <https://github.com/sudar/Arduino-Makefile>. This automates generating+the C code, compiling that, and flashing it onto an Arduino Uno board,+with a single command++	make upload++Note that you will need to manually build the C code once, as shown above,+since the Arduino-Makefile expects to find a `.ino` file.++The path in the `Makefile` to `Arduino.mk` may need to be adjusted (the+default is the location where on a Debian system, `apt-get install+arduino-mk` will install it).
+ Examples/Button/pre-build-hook.sh view
@@ -0,0 +1,2 @@+#!/bin/sh+exec runghc Demo.hs
+ Examples/EEPROM/Demo.hs view
@@ -0,0 +1,80 @@+{-# LANGUAGE RebindableSyntax #-}++module Examples.EEPROM.Demo where++import Copilot.Arduino.Uno+import qualified Copilot.Arduino.Library.EEPROMex as EEPROM+import qualified Copilot.Arduino.Library.Serial as Serial+import System.Environment+import qualified Prelude++main :: IO ()+main = do+	z <- lookupEnv "ZERO"+	arduino $ case z of+		Just "y" -> mainZero+		_ -> mainReal++-- Zero out the EEPROM, in preparation for mainReal.+mainZero :: Sketch ()+mainZero = do+	EEPROM.maxAllowedWrites 10++	(_, eepromloc) <- EEPROM.alloc' (20 :: ADC)+	eepromloc =: constant (0 :: ADC) @: firstIteration++	(_, uptimeloc) <- EEPROM.alloc' (0 :: Word32)+	uptimeloc =: constant (0 :: Word32) @: firstIteration++	Serial.baud 9600+	Serial.device =: [ Serial.str "EEPROM zeroed" ] @: firstIteration++mainReal :: Sketch ()+mainReal = do+	-- Store the maximum value read from a1 in the EEPROM.+	-- There are only 1024 possible values, so this can only possibly+	-- write new values that many times, so no delay is needed in this+	-- program. Just in case though, limit the total number of writes:+	EEPROM.maxAllowedWrites 2048+	(bootval, eepromloc) <- EEPROM.alloc' (20 :: ADC)+	currval <- input' a1 [10, 11, 25, 100, 99, 0, 0, 0, 0, 0]+	let maxval = if currval > bootval then currval else bootval+	-- Note that using maxBound here means it will never write+	-- on the first iteration, even if a1 is then larger than bootval.+	-- Any better way to write this that avoids the problem?+	let newmax = currval > ([maxBound] ++ maxval)+	eepromloc =: currval @: newmax++	-- Store the maximum MilliSeconds this program has been left running+	-- in the EEPROM too.+	(bootuptime, uptimeloc) <- EEPROM.alloc' (0 :: Word32)+	uptime <- input' millis (dummyclockinput [1, 1, 1, 2, 2, 2, 3, 3, 3])+	-- micros overflows after ~70 minutes; detect that and use it to+	-- trigger a periodic write of the uptime to EEPROM.+	hourlyish <- microsOverFlowed+	let maxuptime = if uptime > bootuptime then uptime else bootuptime+	uptimeloc =: maxuptime @: hourlyish+	+	Serial.baud 9600+	Serial.device =:+		[ Serial.str "max a1 seen: "+		-- This is not quite right, because maxval resets to+		-- bootval when this is displayed at hourlyish.+		-- Interpreting shows the problem:+		--    --              (3)             (20,3)+		-- How to fix this?+		, Serial.show maxval+		, Serial.str " max uptime: "+		, Serial.show maxuptime+		, Serial.char '\n'+		]+		@: (firstIteration || newmax || hourlyish)++microsOverFlowed :: Sketch (Behavior Bool)+microsOverFlowed = do+	t <- input' micros (dummyclockinput [1, 2, 3])+	let oldt = [0] ++ t+	return (t < oldt)++dummyclockinput :: [Word32] -> [Word32]+dummyclockinput = Prelude.cycle
+ Examples/EEPROM/Makefile view
@@ -0,0 +1,129 @@+# Arduino Make file. Refer to https://github.com/sudar/Arduino-Makefile+BOARD_TAG    = uno+ARDUINO_LIBS = EEPROMEx+CPPFLAGS     = -D_EEPROMEX_DEBUG+include /usr/share/arduino/Arduino.mk++# --- leonardo (or pro micro w/leo bootloader)+#BOARD_TAG    = leonardo+#MONITOR_PORT = /dev/ttyACM0+#include /usr/share/arduino/Arduino.mk++# --- mega2560 ide 1.0+#BOARD_TAG    = mega2560+#ARDUINO_PORT = /dev/ttyACM0+#include /usr/share/arduino/Arduino.mk++# --- mega2560 ide 1.6+#BOARD_TAG    = mega+#BOARD_SUB    = atmega2560+#MONITOR_PORT = /dev/ttyACM0+#ARDUINO_DIR  = /where/you/installed/arduino-1.6.5+#include /usr/share/arduino/Arduino.mk++# --- nano ide 1.0+#BOARD_TAG    = nano328+#MONITOR_PORT = /dev/ttyUSB0+#include /usr/share/arduino/Arduino.mk++# --- nano ide 1.6+#BOARD_TAG   = nano+#BOARD_SUB   = atmega328+#ARDUINO_DIR = /where/you/installed/arduino-1.6.5+#include /usr/share/arduino/Arduino.mk++# --- pro mini+#BOARD_TAG    = pro5v328+#MONITOR_PORT = /dev/ttyUSB0+#include /usr/share/arduino/Arduino.mk++# --- sparkfun pro micro+#BOARD_TAG         = promicro16+#ALTERNATE_CORE    = promicro+#BOARDS_TXT        = $(HOME)/arduino/hardware/promicro/boards.txt+#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/promicro/bootloaders+#BOOTLOADER_PATH   = caterina+#BOOTLOADER_FILE   = Caterina-promicro16.hex+#ISP_PROG     	   = usbasp+#AVRDUDE_OPTS 	   = -v+#include /usr/share/arduino/Arduino.mk++# --- chipkit+#BOARD_TAG = mega_pic32+#MPIDE_DIR = /where/you/installed/mpide-0023-linux64-20130817-test+#include /usr/share/arduino/chipKIT.mk++# --- pinoccio+#BOARD_TAG         = pinoccio256+#ALTERNATE_CORE    = pinoccio+#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/pinoccio/bootloaders+#BOOTLOADER_PATH   = STK500RFR2/release_0.51+#BOOTLOADER_FILE   = boot_pinoccio.hex+#CFLAGS_STD        = -std=gnu99+#CXXFLAGS_STD      = -std=gnu++11+#include /usr/share/arduino/Arduino.mk++# --- fio+#BOARD_TAG = fio+#include /usr/share/arduino/Arduino.mk++# --- atmega-ng ide 1.6+#BOARD_TAG    = atmegang+#BOARD_SUB    = atmega168+#MONITOR_PORT = /dev/ttyACM0+#ARDUINO_DIR  = /where/you/installed/arduino-1.6.5+#include /usr/share/arduino/Arduino.mk++# --- arduino-tiny ide 1.0+#ISP_PROG     	    = usbasp+#BOARD_TAG          = attiny85at8+#ALTERNATE_CORE     = tiny+#ARDUINO_VAR_PATH   = $(HOME)/arduino/hardware/tiny/cores/tiny+#ARDUINO_CORE_PATH  = $(HOME)/arduino/hardware/tiny/cores/tiny+#AVRDUDE_OPTS 	    = -v+#include /usr/share/arduino/Arduino.mk++# --- arduino-tiny ide 1.6+#ISP_PROG       = usbasp+#BOARD_TAG      = attiny85at8+#ALTERNATE_CORE = tiny+#ARDUINO_DIR    = /where/you/installed/arduino-1.6.5+#include /usr/share/arduino/Arduino.mk++# --- damellis attiny ide 1.0+#ISP_PROG       = usbasp+#BOARD_TAG      = attiny85+#ALTERNATE_CORE = attiny-master+#AVRDUDE_OPTS   = -v+#include /usr/share/arduino/Arduino.mk++# --- damellis attiny ide 1.6+#ISP_PROG       = usbasp+#BOARD_TAG      = attiny+#BOARD_SUB      = attiny85+#ALTERNATE_CORE = attiny+#F_CPU          = 16000000L+#ARDUINO_DIR    = /where/you/installed/arduino-1.6.5+#include /usr/share/arduino/Arduino.mk++# --- teensy3+#BOARD_TAG 	 = teensy31+#ARDUINO_DIR = /where/you/installed/the/patched/teensy/arduino-1.0.6+#include /usr/share/arduino/Teensy.mk++# --- mighty 1284p+#BOARD_TAG         = mighty_opt+#BOARDS_TXT        = $(HOME)/arduino/hardware/mighty-1284p/boards.txt+#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/mighty-1284p/bootloaders+#BOOTLOADER_PATH   = optiboot+#BOOTLOADER_FILE   = optiboot_atmega1284p.hex+#ISP_PROG     	   = usbasp+#AVRDUDE_OPTS 	   = -v+#include /usr/share/arduino/Arduino.mk++# --- atmega328p on breadboard+#BOARD_TAG    = atmega328bb+#ISP_PROG     = usbasp+#AVRDUDE_OPTS = -v+#BOARDS_TXT   = $(HOME)/arduino/hardware/breadboard/boards.txt+#include /usr/share/arduino/Arduino.mk
+ Examples/EEPROM/README view
@@ -0,0 +1,25 @@+This is a demo program using arduino-copilot, showing how to use EEPROMex.++This needs the Arduino-Makefile to be installed. It relies on it+to set CPPFLAGS=-D_EEPROMEX_DEBUG when building the C code.+<https://github.com/sudar/Arduino-Makefile>++The path in the `Makefile` to `Arduino.mk` may need to be adjusted (the+default is the location where on a Debian system, `apt-get install+arduino-mk` will install it).++You will also need to install the EEPROMex library to someplace where+the Arduino toolchain can find it.+<https://github.com/thijse/Arduino-EEPROMEx/>++First, run this to build and upload a sketch that zeros out some values of+the EEPROM.++	ZERO=y runghc Demo.hs+	ZERO=y make upload++Then, you can build and upload the sketch that actually does something+interesting.++	runghc Demo.hs+	make upload
+ Examples/EEPROM/pre-build-hook.sh view
@@ -0,0 +1,2 @@+#!/bin/sh+exec runghc Demo.hs
+ Examples/EEPROMrange/Demo.hs view
@@ -0,0 +1,49 @@+{-# LANGUAGE RebindableSyntax #-}++module Examples.EEPROMrange.Demo where++import Copilot.Arduino.Uno+import qualified Copilot.Arduino.Library.EEPROMex as EEPROM+import qualified Copilot.Arduino.Library.Serial as Serial+import System.Environment++-- Change this to use a smaller part of the EEPROM.+sz :: Word16+sz = sizeOfEEPROM++main :: IO ()+main = do+	z <- lookupEnv "ZERO"+	arduino $ case z of+		Just "y" -> mainZero+		_ -> mainReal++-- Zero out the EEPROM, in preparation for mainReal.+mainZero :: Sketch ()+mainZero = do+	EEPROM.maxAllowedWrites sz++	range <- EEPROM.allocRange sz :: Sketch (EEPROM.Range Word8)+	range =: EEPROM.sweepRange 0 (constant (0 :: Word8))+	+	Serial.baud 9600+	Serial.device =: [ Serial.str "EEPROM zeroing started" ]+		@: firstIteration++mainReal :: Sketch ()+mainReal = do+	EEPROM.maxAllowedWrites (sz * 10)+	range <- EEPROM.allocRange sz :: Sketch (EEPROM.Range ADC)+	v <- input' a1 ([10, 20..] :: [ADC])+	range =: EEPROM.sweepRange 0 v @: frequency 3+	oldv <- input' (EEPROM.scanRange range 1) [11..] :: Sketch (Behavior ADC)+	led =: frequency 3+	Serial.device =:+		[ Serial.str "a1:"+		, Serial.show v+		, Serial.str " old EEPROM value:"+		, Serial.show oldv+		, Serial.char '\n'+		]+	delay =: MilliSeconds (constant 10000)+	Serial.baud 9600
+ Examples/EEPROMrange/Makefile view
@@ -0,0 +1,129 @@+# Arduino Make file. Refer to https://github.com/sudar/Arduino-Makefile+BOARD_TAG    = uno+ARDUINO_LIBS = EEPROMEx+CPPFLAGS     = -D_EEPROMEX_DEBUG+include /usr/share/arduino/Arduino.mk++# --- leonardo (or pro micro w/leo bootloader)+#BOARD_TAG    = leonardo+#MONITOR_PORT = /dev/ttyACM0+#include /usr/share/arduino/Arduino.mk++# --- mega2560 ide 1.0+#BOARD_TAG    = mega2560+#ARDUINO_PORT = /dev/ttyACM0+#include /usr/share/arduino/Arduino.mk++# --- mega2560 ide 1.6+#BOARD_TAG    = mega+#BOARD_SUB    = atmega2560+#MONITOR_PORT = /dev/ttyACM0+#ARDUINO_DIR  = /where/you/installed/arduino-1.6.5+#include /usr/share/arduino/Arduino.mk++# --- nano ide 1.0+#BOARD_TAG    = nano328+#MONITOR_PORT = /dev/ttyUSB0+#include /usr/share/arduino/Arduino.mk++# --- nano ide 1.6+#BOARD_TAG   = nano+#BOARD_SUB   = atmega328+#ARDUINO_DIR = /where/you/installed/arduino-1.6.5+#include /usr/share/arduino/Arduino.mk++# --- pro mini+#BOARD_TAG    = pro5v328+#MONITOR_PORT = /dev/ttyUSB0+#include /usr/share/arduino/Arduino.mk++# --- sparkfun pro micro+#BOARD_TAG         = promicro16+#ALTERNATE_CORE    = promicro+#BOARDS_TXT        = $(HOME)/arduino/hardware/promicro/boards.txt+#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/promicro/bootloaders+#BOOTLOADER_PATH   = caterina+#BOOTLOADER_FILE   = Caterina-promicro16.hex+#ISP_PROG     	   = usbasp+#AVRDUDE_OPTS 	   = -v+#include /usr/share/arduino/Arduino.mk++# --- chipkit+#BOARD_TAG = mega_pic32+#MPIDE_DIR = /where/you/installed/mpide-0023-linux64-20130817-test+#include /usr/share/arduino/chipKIT.mk++# --- pinoccio+#BOARD_TAG         = pinoccio256+#ALTERNATE_CORE    = pinoccio+#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/pinoccio/bootloaders+#BOOTLOADER_PATH   = STK500RFR2/release_0.51+#BOOTLOADER_FILE   = boot_pinoccio.hex+#CFLAGS_STD        = -std=gnu99+#CXXFLAGS_STD      = -std=gnu++11+#include /usr/share/arduino/Arduino.mk++# --- fio+#BOARD_TAG = fio+#include /usr/share/arduino/Arduino.mk++# --- atmega-ng ide 1.6+#BOARD_TAG    = atmegang+#BOARD_SUB    = atmega168+#MONITOR_PORT = /dev/ttyACM0+#ARDUINO_DIR  = /where/you/installed/arduino-1.6.5+#include /usr/share/arduino/Arduino.mk++# --- arduino-tiny ide 1.0+#ISP_PROG     	    = usbasp+#BOARD_TAG          = attiny85at8+#ALTERNATE_CORE     = tiny+#ARDUINO_VAR_PATH   = $(HOME)/arduino/hardware/tiny/cores/tiny+#ARDUINO_CORE_PATH  = $(HOME)/arduino/hardware/tiny/cores/tiny+#AVRDUDE_OPTS 	    = -v+#include /usr/share/arduino/Arduino.mk++# --- arduino-tiny ide 1.6+#ISP_PROG       = usbasp+#BOARD_TAG      = attiny85at8+#ALTERNATE_CORE = tiny+#ARDUINO_DIR    = /where/you/installed/arduino-1.6.5+#include /usr/share/arduino/Arduino.mk++# --- damellis attiny ide 1.0+#ISP_PROG       = usbasp+#BOARD_TAG      = attiny85+#ALTERNATE_CORE = attiny-master+#AVRDUDE_OPTS   = -v+#include /usr/share/arduino/Arduino.mk++# --- damellis attiny ide 1.6+#ISP_PROG       = usbasp+#BOARD_TAG      = attiny+#BOARD_SUB      = attiny85+#ALTERNATE_CORE = attiny+#F_CPU          = 16000000L+#ARDUINO_DIR    = /where/you/installed/arduino-1.6.5+#include /usr/share/arduino/Arduino.mk++# --- teensy3+#BOARD_TAG 	 = teensy31+#ARDUINO_DIR = /where/you/installed/the/patched/teensy/arduino-1.0.6+#include /usr/share/arduino/Teensy.mk++# --- mighty 1284p+#BOARD_TAG         = mighty_opt+#BOARDS_TXT        = $(HOME)/arduino/hardware/mighty-1284p/boards.txt+#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/mighty-1284p/bootloaders+#BOOTLOADER_PATH   = optiboot+#BOOTLOADER_FILE   = optiboot_atmega1284p.hex+#ISP_PROG     	   = usbasp+#AVRDUDE_OPTS 	   = -v+#include /usr/share/arduino/Arduino.mk++# --- atmega328p on breadboard+#BOARD_TAG    = atmega328bb+#ISP_PROG     = usbasp+#AVRDUDE_OPTS = -v+#BOARDS_TXT   = $(HOME)/arduino/hardware/breadboard/boards.txt+#include /usr/share/arduino/Arduino.mk
+ Examples/EEPROMrange/README view
@@ -0,0 +1,26 @@+This is a demo program using arduino-copilot, showing how to use EEPROMex+with ranges.++This needs the Arduino-Makefile to be installed. It relies on it+to set CPPFLAGS=-D_EEPROMEX_DEBUG when building the C code.+<https://github.com/sudar/Arduino-Makefile>++The path in the `Makefile` to `Arduino.mk` may need to be adjusted (the+default is the location where on a Debian system, `apt-get install+arduino-mk` will install it).++You will also need to install the EEPROMex library to someplace where+the Arduino toolchain can find it.+<https://github.com/thijse/Arduino-EEPROMEx/>++First, run this to build and upload a sketch that zeros out the entire+EEPROM.++	ZERO=y runghc Demo.hs+	ZERO=y make upload++Then, you can build and upload the sketch that actually does something+interesting.++	runghc Demo.hs+	make upload
+ Examples/EEPROMrange/pre-build-hook.sh view
@@ -0,0 +1,2 @@+#!/bin/sh+exec runghc Demo.hs
+ Examples/Random/Demo.hs view
@@ -0,0 +1,14 @@+{-# LANGUAGE RebindableSyntax #-}++module Examples.Random.Demo where++import Copilot.Arduino.Uno+import Copilot.Arduino.Library.Random++main :: IO ()+main = arduino $ do+	if firstIteration+		then randomSeedPin a0+		else do+			n <- input (random 10) :: Sketch (Behavior Word32)+			led =: (n >= 5)
+ Examples/Random/Makefile view
@@ -0,0 +1,127 @@+# Arduino Make file. Refer to https://github.com/sudar/Arduino-Makefile+BOARD_TAG    = uno+include /usr/share/arduino/Arduino.mk++# --- leonardo (or pro micro w/leo bootloader)+#BOARD_TAG    = leonardo+#MONITOR_PORT = /dev/ttyACM0+#include /usr/share/arduino/Arduino.mk++# --- mega2560 ide 1.0+#BOARD_TAG    = mega2560+#ARDUINO_PORT = /dev/ttyACM0+#include /usr/share/arduino/Arduino.mk++# --- mega2560 ide 1.6+#BOARD_TAG    = mega+#BOARD_SUB    = atmega2560+#MONITOR_PORT = /dev/ttyACM0+#ARDUINO_DIR  = /where/you/installed/arduino-1.6.5+#include /usr/share/arduino/Arduino.mk++# --- nano ide 1.0+#BOARD_TAG    = nano328+#MONITOR_PORT = /dev/ttyUSB0+#include /usr/share/arduino/Arduino.mk++# --- nano ide 1.6+#BOARD_TAG   = nano+#BOARD_SUB   = atmega328+#ARDUINO_DIR = /where/you/installed/arduino-1.6.5+#include /usr/share/arduino/Arduino.mk++# --- pro mini+#BOARD_TAG    = pro5v328+#MONITOR_PORT = /dev/ttyUSB0+#include /usr/share/arduino/Arduino.mk++# --- sparkfun pro micro+#BOARD_TAG         = promicro16+#ALTERNATE_CORE    = promicro+#BOARDS_TXT        = $(HOME)/arduino/hardware/promicro/boards.txt+#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/promicro/bootloaders+#BOOTLOADER_PATH   = caterina+#BOOTLOADER_FILE   = Caterina-promicro16.hex+#ISP_PROG     	   = usbasp+#AVRDUDE_OPTS 	   = -v+#include /usr/share/arduino/Arduino.mk++# --- chipkit+#BOARD_TAG = mega_pic32+#MPIDE_DIR = /where/you/installed/mpide-0023-linux64-20130817-test+#include /usr/share/arduino/chipKIT.mk++# --- pinoccio+#BOARD_TAG         = pinoccio256+#ALTERNATE_CORE    = pinoccio+#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/pinoccio/bootloaders+#BOOTLOADER_PATH   = STK500RFR2/release_0.51+#BOOTLOADER_FILE   = boot_pinoccio.hex+#CFLAGS_STD        = -std=gnu99+#CXXFLAGS_STD      = -std=gnu++11+#include /usr/share/arduino/Arduino.mk++# --- fio+#BOARD_TAG = fio+#include /usr/share/arduino/Arduino.mk++# --- atmega-ng ide 1.6+#BOARD_TAG    = atmegang+#BOARD_SUB    = atmega168+#MONITOR_PORT = /dev/ttyACM0+#ARDUINO_DIR  = /where/you/installed/arduino-1.6.5+#include /usr/share/arduino/Arduino.mk++# --- arduino-tiny ide 1.0+#ISP_PROG     	    = usbasp+#BOARD_TAG          = attiny85at8+#ALTERNATE_CORE     = tiny+#ARDUINO_VAR_PATH   = $(HOME)/arduino/hardware/tiny/cores/tiny+#ARDUINO_CORE_PATH  = $(HOME)/arduino/hardware/tiny/cores/tiny+#AVRDUDE_OPTS 	    = -v+#include /usr/share/arduino/Arduino.mk++# --- arduino-tiny ide 1.6+#ISP_PROG       = usbasp+#BOARD_TAG      = attiny85at8+#ALTERNATE_CORE = tiny+#ARDUINO_DIR    = /where/you/installed/arduino-1.6.5+#include /usr/share/arduino/Arduino.mk++# --- damellis attiny ide 1.0+#ISP_PROG       = usbasp+#BOARD_TAG      = attiny85+#ALTERNATE_CORE = attiny-master+#AVRDUDE_OPTS   = -v+#include /usr/share/arduino/Arduino.mk++# --- damellis attiny ide 1.6+#ISP_PROG       = usbasp+#BOARD_TAG      = attiny+#BOARD_SUB      = attiny85+#ALTERNATE_CORE = attiny+#F_CPU          = 16000000L+#ARDUINO_DIR    = /where/you/installed/arduino-1.6.5+#include /usr/share/arduino/Arduino.mk++# --- teensy3+#BOARD_TAG 	 = teensy31+#ARDUINO_DIR = /where/you/installed/the/patched/teensy/arduino-1.0.6+#include /usr/share/arduino/Teensy.mk++# --- mighty 1284p+#BOARD_TAG         = mighty_opt+#BOARDS_TXT        = $(HOME)/arduino/hardware/mighty-1284p/boards.txt+#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/mighty-1284p/bootloaders+#BOOTLOADER_PATH   = optiboot+#BOOTLOADER_FILE   = optiboot_atmega1284p.hex+#ISP_PROG     	   = usbasp+#AVRDUDE_OPTS 	   = -v+#include /usr/share/arduino/Arduino.mk++# --- atmega328p on breadboard+#BOARD_TAG    = atmega328bb+#ISP_PROG     = usbasp+#AVRDUDE_OPTS = -v+#BOARDS_TXT   = $(HOME)/arduino/hardware/breadboard/boards.txt+#include /usr/share/arduino/Arduino.mk
+ Examples/Random/README view
@@ -0,0 +1,27 @@+This is a demo program using arduino-copilot. ++To build the C code:++	runghc Demo.hs++The resulting `.ino` sketch can be loaded into the Arduino IDE and flashed+to an Arduino board using the IDE.++It randomly flashes the Arduino's on board LED.++## Arduino-Makefile integration++The `Makefile` and `pre-build-hook.sh` show how to integrate arduino-copilot+with <https://github.com/sudar/Arduino-Makefile>. This automates generating+the C code, compiling that, and flashing it onto an Arduino Uno board,+with a single command++	make upload++Note that you will need to manually build the C code once, as shown above,+since the Arduino-Makefile expects to find a `.ino` file.++The path in the `Makefile` to `Arduino.mk` may need to be adjusted (the+default is the location where on a Debian system, `apt-get install+arduino-mk` will install it). You may also adjust the `Makefile` to target+a different board than the Arduino Uno.
+ Examples/Random/pre-build-hook.sh view
@@ -0,0 +1,2 @@+#!/bin/sh+exec runghc Demo.hs
+ Examples/Robot/Demo.hs view
@@ -0,0 +1,92 @@+{- A simple line-following robot.+ -+ - This is not the most efficient or best way to implement it+ - (it compiles to around 500 lines of C code), but+ - it is a good example of building up a Sketch by combining+ - simpler Sketches.+ -}++{-# LANGUAGE RebindableSyntax #-}++module Examples.Robot.Demo where++import Copilot.Arduino.Uno+import qualified Copilot.Arduino.Library.Serial.XBee as XBee++main :: IO ()+main = arduino $ do+	XBee.configure pin2 pin3 (XBee.Baud 9600)+	emergencystop <- input pin4+	if emergencystop+		then stop+		else do+			ll <- leftLineSensed+			rl <- rightLineSensed+			if ll && rl+				then stop+				else if ll+					then turnLeft+					else if rl+						then turnRight+						else goForward++stop :: Sketch ()+stop = do+	led =: true+	XBee.device =: [XBee.str "stopped\n"]+	rightWheelMotor true (constant 0)+	leftWheelMotor true (constant 0)++goForward :: Sketch ()+goForward = do+	led =: false+	XBee.device =: [XBee.str "forward\n"]+	leftWheelMotor true (constant 255)+	rightWheelMotor true (constant 255)++turnLeft :: Sketch ()+turnLeft = do+	led =: blinking+	XBee.device =: [XBee.str "turn left\n"]+	rightWheelMotor true (constant 128)+	leftWheelMotor false (constant 128)++turnRight :: Sketch ()+turnRight = do+	led =: blinking+	XBee.device =: [XBee.str "turn right\n"]+	rightWheelMotor false (constant 128)+	leftWheelMotor true (constant 128)++leftLineSensed :: Sketch (Behavior Bool)+leftLineSensed = lineSensed a1 "left"++rightLineSensed :: Sketch (Behavior Bool)+rightLineSensed = lineSensed a2 "right"++lineSensed :: IsAnalogInputPin t => Pin t -> [Char] -> Sketch (Stream Bool)+lineSensed pin desc = do+	v <- input pin :: Sketch (Behavior ADC)+	XBee.device =: +		[ XBee.str (desc <> " line sensor:")+		, XBee.show v+		, XBee.char '\n'+		]+	return (v > 50)++leftWheelMotor :: Behavior Bool -> Behavior Word8 -> Sketch ()+leftWheelMotor = wheelMotor pin5 pin6++rightWheelMotor :: Behavior Bool -> Behavior Word8 -> Sketch ()+rightWheelMotor = wheelMotor pin9 pin10++wheelMotor+	:: (IsPWMPin t1, IsPWMPin t2)+	=> Pin t1 -- ^ pin to drive motor forward+	-> Pin t2 -- ^ pin to drive motor backward+	-> Behavior Bool -- ^ True when driving forward+	-> Behavior Word8 -- ^ How hard to drive the motor.+	-> Sketch ()+wheelMotor forwardpin backwardpin forward power = do+	forwardpin =: pwm (if forward then power else constant 0)+	backwardpin =: pwm (if forward then constant 0 else power)
+ Examples/SerialPort/Demo.hs view
@@ -0,0 +1,54 @@+{-# LANGUAGE RebindableSyntax #-}+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE FlexibleContexts #-}++module Examples.SerialPort.Demo where++import Copilot.Arduino.Uno+import qualified Copilot.Arduino.Library.Serial as Serial+import qualified Copilot.Arduino.Library.Serial.XBee as XBee+import Control.Monad++-- Should it use the onboard serial port?+useSerial :: Bool+useSerial = True++-- Should it use the XBee wireless serial port?+-- (it can use more than one serial port at the same time.)+useXBee :: Bool+useXBee = True++userIsTyping :: Behavior Int8 -> Behavior Bool+userIsTyping userinput = userinput /= constant Serial.noInput++getSerial :: Input o Int8 => Bool -> o -> Sketch (Behavior Int8)+getSerial True i = input' i (repeat Serial.noInput)+getSerial False _ = return (constant Serial.noInput)++main :: IO ()+main = arduino $ do+	when useSerial $ Serial.baud 9600+	when useXBee $ XBee.configure pin2 pin3 (XBee.Baud 9600)++	-- Measure the an analog input, and display it to the+	-- serial port. This is a handy demo because with nothing connected+	-- to a0, just moving your hand close to the arduino will probably+	-- cause some noise to be read.+	n <- input' a0 [1, 50, 11, 99, 120] :: Sketch (Behavior ADC)+	c <- input' millis [20, 60, 80, 100] :: Sketch (Behavior Word32)+	let msg = +		[ Serial.str "analog input:"+		, Serial.showFormatted n Serial.HEX+		, Serial.str " millis:"+		, Serial.show c+		, Serial.char '\n'+		]+	when useSerial $ Serial.device =: msg+	when useXBee $ XBee.device =: msg++	-- Light the led whenever the user types on the serial port.+	userinput <- getSerial useSerial Serial.device+	userinputxbee <- getSerial useXBee XBee.device+	led =: userIsTyping userinput || userIsTyping userinputxbee++	delay =: MilliSeconds (constant 100)
+ Examples/SerialPort/Makefile view
@@ -0,0 +1,127 @@+# Arduino Make file. Refer to https://github.com/sudar/Arduino-Makefile+BOARD_TAG    = uno+include /usr/share/arduino/Arduino.mk++# --- leonardo (or pro micro w/leo bootloader)+#BOARD_TAG    = leonardo+#MONITOR_PORT = /dev/ttyACM0+#include /usr/share/arduino/Arduino.mk++# --- mega2560 ide 1.0+#BOARD_TAG    = mega2560+#ARDUINO_PORT = /dev/ttyACM0+#include /usr/share/arduino/Arduino.mk++# --- mega2560 ide 1.6+#BOARD_TAG    = mega+#BOARD_SUB    = atmega2560+#MONITOR_PORT = /dev/ttyACM0+#ARDUINO_DIR  = /where/you/installed/arduino-1.6.5+#include /usr/share/arduino/Arduino.mk++# --- nano ide 1.0+#BOARD_TAG    = nano328+#MONITOR_PORT = /dev/ttyUSB0+#include /usr/share/arduino/Arduino.mk++# --- nano ide 1.6+#BOARD_TAG   = nano+#BOARD_SUB   = atmega328+#ARDUINO_DIR = /where/you/installed/arduino-1.6.5+#include /usr/share/arduino/Arduino.mk++# --- pro mini+#BOARD_TAG    = pro5v328+#MONITOR_PORT = /dev/ttyUSB0+#include /usr/share/arduino/Arduino.mk++# --- sparkfun pro micro+#BOARD_TAG         = promicro16+#ALTERNATE_CORE    = promicro+#BOARDS_TXT        = $(HOME)/arduino/hardware/promicro/boards.txt+#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/promicro/bootloaders+#BOOTLOADER_PATH   = caterina+#BOOTLOADER_FILE   = Caterina-promicro16.hex+#ISP_PROG     	   = usbasp+#AVRDUDE_OPTS 	   = -v+#include /usr/share/arduino/Arduino.mk++# --- chipkit+#BOARD_TAG = mega_pic32+#MPIDE_DIR = /where/you/installed/mpide-0023-linux64-20130817-test+#include /usr/share/arduino/chipKIT.mk++# --- pinoccio+#BOARD_TAG         = pinoccio256+#ALTERNATE_CORE    = pinoccio+#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/pinoccio/bootloaders+#BOOTLOADER_PATH   = STK500RFR2/release_0.51+#BOOTLOADER_FILE   = boot_pinoccio.hex+#CFLAGS_STD        = -std=gnu99+#CXXFLAGS_STD      = -std=gnu++11+#include /usr/share/arduino/Arduino.mk++# --- fio+#BOARD_TAG = fio+#include /usr/share/arduino/Arduino.mk++# --- atmega-ng ide 1.6+#BOARD_TAG    = atmegang+#BOARD_SUB    = atmega168+#MONITOR_PORT = /dev/ttyACM0+#ARDUINO_DIR  = /where/you/installed/arduino-1.6.5+#include /usr/share/arduino/Arduino.mk++# --- arduino-tiny ide 1.0+#ISP_PROG     	    = usbasp+#BOARD_TAG          = attiny85at8+#ALTERNATE_CORE     = tiny+#ARDUINO_VAR_PATH   = $(HOME)/arduino/hardware/tiny/cores/tiny+#ARDUINO_CORE_PATH  = $(HOME)/arduino/hardware/tiny/cores/tiny+#AVRDUDE_OPTS 	    = -v+#include /usr/share/arduino/Arduino.mk++# --- arduino-tiny ide 1.6+#ISP_PROG       = usbasp+#BOARD_TAG      = attiny85at8+#ALTERNATE_CORE = tiny+#ARDUINO_DIR    = /where/you/installed/arduino-1.6.5+#include /usr/share/arduino/Arduino.mk++# --- damellis attiny ide 1.0+#ISP_PROG       = usbasp+#BOARD_TAG      = attiny85+#ALTERNATE_CORE = attiny-master+#AVRDUDE_OPTS   = -v+#include /usr/share/arduino/Arduino.mk++# --- damellis attiny ide 1.6+#ISP_PROG       = usbasp+#BOARD_TAG      = attiny+#BOARD_SUB      = attiny85+#ALTERNATE_CORE = attiny+#F_CPU          = 16000000L+#ARDUINO_DIR    = /where/you/installed/arduino-1.6.5+#include /usr/share/arduino/Arduino.mk++# --- teensy3+#BOARD_TAG 	 = teensy31+#ARDUINO_DIR = /where/you/installed/the/patched/teensy/arduino-1.0.6+#include /usr/share/arduino/Teensy.mk++# --- mighty 1284p+#BOARD_TAG         = mighty_opt+#BOARDS_TXT        = $(HOME)/arduino/hardware/mighty-1284p/boards.txt+#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/mighty-1284p/bootloaders+#BOOTLOADER_PATH   = optiboot+#BOOTLOADER_FILE   = optiboot_atmega1284p.hex+#ISP_PROG     	   = usbasp+#AVRDUDE_OPTS 	   = -v+#include /usr/share/arduino/Arduino.mk++# --- atmega328p on breadboard+#BOARD_TAG    = atmega328bb+#ISP_PROG     = usbasp+#AVRDUDE_OPTS = -v+#BOARDS_TXT   = $(HOME)/arduino/hardware/breadboard/boards.txt+#include /usr/share/arduino/Arduino.mk
+ Examples/SerialPort/README view
@@ -0,0 +1,24 @@+This is a demo program using arduino-copilot. ++To build the C code:++	runghc Demo.hs++The resulting `.ino` sketch can be loaded into the Arduino IDE and flashed+to an Arduino Uno board using the IDE.++## Arduino-Makefile integration++The `Makefile` and `pre-build-hook.sh` show how to integrate arduino-copilot+with <https://github.com/sudar/Arduino-Makefile>. This automates generating+the C code, compiling that, and flashing it onto an Arduino Uno board,+with a single command++	make upload++Note that you will need to manually build the C code once, as shown above,+since the Arduino-Makefile expects to find a `.ino` file.++The path in the `Makefile` to `Arduino.mk` may need to be adjusted (the+default is the location where on a Debian system, `apt-get install+arduino-mk` will install it).
+ Examples/SerialPort/pre-build-hook.sh view
@@ -0,0 +1,2 @@+#!/bin/sh+exec runghc Demo.hs
+ Examples/WaterHeater/Demo.hs view
@@ -0,0 +1,71 @@+{- Controlling a hot water heater.+ -+ - This shows how additional types can be used to eg, keep track of units+ - of measurement, while using the Copilot DSL.+ -}++{-# LANGUAGE RebindableSyntax #-}+{-# LANGUAGE EmptyDataDecls #-}++module Examples.WaterHeater.Demo where++import Copilot.Arduino.Uno+import Data.List.NonEmpty (NonEmpty(..))+import qualified Data.List.NonEmpty as L++-- For use as phantom types in TypedBehavior+data PSI+data Celsius++maxSafePSI :: TypedBehavior PSI Float+maxSafePSI = TypedBehavior (constant 45)++maxWaterTemp :: TypedBehavior Celsius Float+maxWaterTemp = TypedBehavior (constant 35)++warmWaterTemp :: TypedBehavior Celsius Float+warmWaterTemp = TypedBehavior (constant 30)++isSafeTemp :: TypedBehavior Celsius Float -> Behavior Bool+isSafeTemp t = liftB2 (<) t maxWaterTemp++isSafePSI :: TypedBehavior PSI Float -> Behavior Bool+isSafePSI p = liftB2 (<) p maxSafePSI++-- Avoid explosions and scalding water.+isSafeToHeat :: TypedBehavior PSI Float -> NonEmpty (TypedBehavior Celsius Float) -> Behavior Bool+isSafeToHeat p cs = foldl (&&) (isSafePSI p) (L.map isSafeTemp cs)++-- Convert a raw value read from an ADC into a temperature in Celsius.+--+-- Assumes the ADC value is 0 at 0F, and 1024 at 200F.+adcToCelsius :: Behavior ADC -> TypedBehavior Celsius Float+adcToCelsius v = TypedBehavior $ v' * (constant 200 / constant 1024)+  where+	v' :: Behavior Float+	v' = unsafeCast v++-- Convert a raw value read from an ADC into a PSI.+--+-- Assumes the ADCI value is 0 at 0 PSI, and 1024 at 150 PSI.+adcToPSI :: Behavior ADC -> TypedBehavior PSI Float+adcToPSI v = TypedBehavior $ v' * (constant 150 / constant 1024)+  where+	v' :: Behavior Float+	v' = unsafeCast v++main :: IO ()+main = arduino $ do+	uppertemp <- adcToCelsius <$> input a1+	lowertemp <- adcToCelsius <$> input a2+	pressure <- adcToPSI <$> input a3+	let upperheatingelement = pin4+	let lowerheatingelement = pin5+	whenB (isSafeToHeat pressure (uppertemp :| [lowertemp])) $ do+		-- Run the upper heating element if the upper water temp is+		-- low, to provide hot water on demand. Run the lower+		-- heating element only when the upper is off.+		let runupper = liftB2 (<) uppertemp warmWaterTemp+		upperheatingelement =: runupper+		lowerheatingelement =: not runupper+	delay =: MilliSeconds 1000
+ Examples/WaterHeater/Makefile view
@@ -0,0 +1,127 @@+# Arduino Make file. Refer to https://github.com/sudar/Arduino-Makefile+BOARD_TAG    = uno+include /usr/share/arduino/Arduino.mk++# --- leonardo (or pro micro w/leo bootloader)+#BOARD_TAG    = leonardo+#MONITOR_PORT = /dev/ttyACM0+#include /usr/share/arduino/Arduino.mk++# --- mega2560 ide 1.0+#BOARD_TAG    = mega2560+#ARDUINO_PORT = /dev/ttyACM0+#include /usr/share/arduino/Arduino.mk++# --- mega2560 ide 1.6+#BOARD_TAG    = mega+#BOARD_SUB    = atmega2560+#MONITOR_PORT = /dev/ttyACM0+#ARDUINO_DIR  = /where/you/installed/arduino-1.6.5+#include /usr/share/arduino/Arduino.mk++# --- nano ide 1.0+#BOARD_TAG    = nano328+#MONITOR_PORT = /dev/ttyUSB0+#include /usr/share/arduino/Arduino.mk++# --- nano ide 1.6+#BOARD_TAG   = nano+#BOARD_SUB   = atmega328+#ARDUINO_DIR = /where/you/installed/arduino-1.6.5+#include /usr/share/arduino/Arduino.mk++# --- pro mini+#BOARD_TAG    = pro5v328+#MONITOR_PORT = /dev/ttyUSB0+#include /usr/share/arduino/Arduino.mk++# --- sparkfun pro micro+#BOARD_TAG         = promicro16+#ALTERNATE_CORE    = promicro+#BOARDS_TXT        = $(HOME)/arduino/hardware/promicro/boards.txt+#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/promicro/bootloaders+#BOOTLOADER_PATH   = caterina+#BOOTLOADER_FILE   = Caterina-promicro16.hex+#ISP_PROG     	   = usbasp+#AVRDUDE_OPTS 	   = -v+#include /usr/share/arduino/Arduino.mk++# --- chipkit+#BOARD_TAG = mega_pic32+#MPIDE_DIR = /where/you/installed/mpide-0023-linux64-20130817-test+#include /usr/share/arduino/chipKIT.mk++# --- pinoccio+#BOARD_TAG         = pinoccio256+#ALTERNATE_CORE    = pinoccio+#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/pinoccio/bootloaders+#BOOTLOADER_PATH   = STK500RFR2/release_0.51+#BOOTLOADER_FILE   = boot_pinoccio.hex+#CFLAGS_STD        = -std=gnu99+#CXXFLAGS_STD      = -std=gnu++11+#include /usr/share/arduino/Arduino.mk++# --- fio+#BOARD_TAG = fio+#include /usr/share/arduino/Arduino.mk++# --- atmega-ng ide 1.6+#BOARD_TAG    = atmegang+#BOARD_SUB    = atmega168+#MONITOR_PORT = /dev/ttyACM0+#ARDUINO_DIR  = /where/you/installed/arduino-1.6.5+#include /usr/share/arduino/Arduino.mk++# --- arduino-tiny ide 1.0+#ISP_PROG     	    = usbasp+#BOARD_TAG          = attiny85at8+#ALTERNATE_CORE     = tiny+#ARDUINO_VAR_PATH   = $(HOME)/arduino/hardware/tiny/cores/tiny+#ARDUINO_CORE_PATH  = $(HOME)/arduino/hardware/tiny/cores/tiny+#AVRDUDE_OPTS 	    = -v+#include /usr/share/arduino/Arduino.mk++# --- arduino-tiny ide 1.6+#ISP_PROG       = usbasp+#BOARD_TAG      = attiny85at8+#ALTERNATE_CORE = tiny+#ARDUINO_DIR    = /where/you/installed/arduino-1.6.5+#include /usr/share/arduino/Arduino.mk++# --- damellis attiny ide 1.0+#ISP_PROG       = usbasp+#BOARD_TAG      = attiny85+#ALTERNATE_CORE = attiny-master+#AVRDUDE_OPTS   = -v+#include /usr/share/arduino/Arduino.mk++# --- damellis attiny ide 1.6+#ISP_PROG       = usbasp+#BOARD_TAG      = attiny+#BOARD_SUB      = attiny85+#ALTERNATE_CORE = attiny+#F_CPU          = 16000000L+#ARDUINO_DIR    = /where/you/installed/arduino-1.6.5+#include /usr/share/arduino/Arduino.mk++# --- teensy3+#BOARD_TAG 	 = teensy31+#ARDUINO_DIR = /where/you/installed/the/patched/teensy/arduino-1.0.6+#include /usr/share/arduino/Teensy.mk++# --- mighty 1284p+#BOARD_TAG         = mighty_opt+#BOARDS_TXT        = $(HOME)/arduino/hardware/mighty-1284p/boards.txt+#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/mighty-1284p/bootloaders+#BOOTLOADER_PATH   = optiboot+#BOOTLOADER_FILE   = optiboot_atmega1284p.hex+#ISP_PROG     	   = usbasp+#AVRDUDE_OPTS 	   = -v+#include /usr/share/arduino/Arduino.mk++# --- atmega328p on breadboard+#BOARD_TAG    = atmega328bb+#ISP_PROG     = usbasp+#AVRDUDE_OPTS = -v+#BOARDS_TXT   = $(HOME)/arduino/hardware/breadboard/boards.txt+#include /usr/share/arduino/Arduino.mk
+ Examples/WaterHeater/README view
@@ -0,0 +1,24 @@+This is a demo program using arduino-copilot. ++To build the C code:++	runghc Demo.hs++The resulting `.ino` sketch can be loaded into the Arduino IDE and flashed+to an Arduino Uno board using the IDE.++## Arduino-Makefile integration++The `Makefile` and `pre-build-hook.sh` show how to integrate arduino-copilot+with <https://github.com/sudar/Arduino-Makefile>. This automates generating+the C code, compiling that, and flashing it onto an Arduino Uno board,+with a single command++	make upload++Note that you will need to manually build the C code once, as shown above,+since the Arduino-Makefile expects to find a `.ino` file.++The path in the `Makefile` to `Arduino.mk` may need to be adjusted (the+default is the location where on a Debian system, `apt-get install+arduino-mk` will install it).
+ Examples/WaterHeater/pre-build-hook.sh view
@@ -0,0 +1,2 @@+#!/bin/sh+exec runghc Demo.hs
README view
@@ -10,7 +10,7 @@ 		led =: blinking 		delay =: MilliSeconds (constant 100) -This and other examples are included in the examples/ directory, each+This and other examples are included in the Examples/ directory, each with their own README explaining how to build and use them.  ## Contributing
TODO view
@@ -1,3 +1,33 @@+* More board definition modules other than Nano and Uno. Need hardware to+  test.++* The Nano board definition has not been tested on actual hardware,+  and we wonder if eg pin10 can really handle PWM. Some documentation seems+  to say not. It would be good to check it's basically working.++* analogReference()+  Takes one of a set of defines, which vary depending on board,+  so how to pass that through Copilot? Could write a C+  switch statement, on an int, and have the board modules define+  effectively enums.++* ADC is a raw ADC value; add a stream function to convert that+  to a floating point actual voltage, given also a stream that contains+  the reference voltage.++* advanced IO (pulses, tones, and shiftin, shiftout)++* Wire library++* EEPROMex supports writing individial bits of a byte, but the haskell+  library does not expose it. What would be a good haskell interface to+  that, a Stream (Array 8 Bool)?++* Factor out Range from EEPROMex, and use it to also implement RAM ranges.+  Maybe redundant with Copilot's support for Array, but Copilot's+  facilities for operating on Array are limited so it could be useful to+  have a Range interface too.+ * liftB and liftB2 imply liftB[3..5] at least ought to exist.    Really, want something like Applicative. But apparently TypedBehavior@@ -11,6 +41,10 @@   (Then rename TypedBehavior to Behavior and make everything produce   and consume that, rather than the underlying Stream?) +  Alternativly, copilot could be improved, see+  https://github.com/Copilot-Language/copilot/issues/56+  https://github.com/Copilot-Language/copilot/issues/59+ * using whenB with an input' makes the interpretation see   each value from the list, even when the whenB is supposed to prevent the   input' from having run, and the value should be whatever was input@@ -35,25 +69,3 @@    The workaround, for now, is to use ifM_ etc to switch between different   sketches for the different output formats.--* analogReference()-  Takes one of a set of defines, which vary depending on board,-  so how to pass that through Copilot? Could write a C-  switch statement, on an int, and have the boade modules define-  effectively enums.-* ADC is a raw ADC value; add a stream function to convert that-  to a floating point actual voltage, given also a stream that contains-  the reference voltage.-* pulses-* random numbers-* Wire library-* test.hs is not wired into the cabal file because it depends on runghc-  having the library available-* EEPROMex supports writing individial bits of a byte, but the haskell-  library does not expose it. What would be a good haskell interface to-  that, a Stream (Array 8 Bool)?-* Factor out Range from EEPROMex, and use it to also implement RAM ranges.-  Maybe redundant with Copilot's support for Array, but Copilot's-  facilities for operating on Array are limited so it could be useful to-  have a Range interface too.-
arduino-copilot.cabal view
@@ -1,6 +1,6 @@ Name: arduino-copilot-Version: 1.5.1-Cabal-Version: >= 1.8+Version: 1.5.2+Cabal-Version: >= 1.10 License: BSD3 Maintainer: Joey Hess <id@joeyh.name> Author: Joey Hess@@ -33,38 +33,52 @@   CHANGELOG   TODO   stack.yaml-  examples/blink/Makefile-  examples/blink/README-  examples/blink/demo.hs-  examples/blink/pre-build-hook.sh-  examples/button/Makefile-  examples/button/README-  examples/button/demo.hs-  examples/button/pre-build-hook.sh-  examples/serialport/Makefile-  examples/serialport/README-  examples/serialport/demo.hs-  examples/serialport/pre-build-hook.sh-  examples/eeprom/Makefile-  examples/eeprom/README-  examples/eeprom/demo.hs-  examples/eeprom/pre-build-hook.sh-  examples/eepromrange/Makefile-  examples/eepromrange/README-  examples/eepromrange/demo.hs-  examples/eepromrange/pre-build-hook.sh-  examples/robot/Makefile-  examples/robot/README-  examples/robot/demo.hs-  examples/robot/pre-build-hook.sh-  examples/waterheater/Makefile-  examples/waterheater/README-  examples/waterheater/demo.hs-  examples/waterheater/pre-build-hook.sh-  test.hs+  Examples/Blink/Makefile+  Examples/Blink/README+  Examples/Blink/pre-build-hook.sh+  Examples/Button/Makefile+  Examples/Button/README+  Examples/Button/pre-build-hook.sh+  Examples/EEPROM/Makefile+  Examples/EEPROM/README+  Examples/EEPROM/pre-build-hook.sh+  Examples/EEPROMrange/Makefile+  Examples/EEPROMrange/README+  Examples/EEPROMrange/pre-build-hook.sh+  Examples/Random/Makefile+  Examples/Random/README+  Examples/Random/pre-build-hook.sh+  Examples/SerialPort/Makefile+  Examples/SerialPort/README+  Examples/SerialPort/pre-build-hook.sh+  Examples/WaterHeater/Makefile+  Examples/WaterHeater/README+  Examples/WaterHeater/pre-build-hook.sh +test-suite test+  Main-Is: test.hs+  Type: exitcode-stdio-1.0+  GHC-Options: -Wall -fno-warn-tabs+  Default-Language: Haskell2010+  Build-Depends:+    base (>= 4.6 && < 5),+    arduino-copilot,+    temporary,+    directory,+    process+  Other-Modules:+    Examples.Blink.Demo+    Examples.Button.Demo+    Examples.EEPROM.Demo+    Examples.EEPROMrange.Demo+    Examples.Random.Demo+    Examples.Robot.Demo+    Examples.SerialPort.Demo+    Examples.WaterHeater.Demo+ Library   GHC-Options: -Wall -fno-warn-tabs+  Default-Language: Haskell2010   Hs-Source-Dirs: src   Exposed-Modules:     Copilot.Arduino@@ -75,6 +89,7 @@     Copilot.Arduino.Library.Serial.Device     Copilot.Arduino.Library.Serial.XBee     Copilot.Arduino.Library.EEPROMex+    Copilot.Arduino.Library.Random   Other-Modules:     Copilot.Arduino.Main   Build-Depends:@@ -85,7 +100,7 @@     filepath,     directory,     mtl,-    unix,+    temporary,     optparse-applicative (>= 0.14.1),     containers 
− examples/blink/Makefile
@@ -1,127 +0,0 @@-# Arduino Make file. Refer to https://github.com/sudar/Arduino-Makefile-BOARD_TAG    = uno-include /usr/share/arduino/Arduino.mk--# --- leonardo (or pro micro w/leo bootloader)-#BOARD_TAG    = leonardo-#MONITOR_PORT = /dev/ttyACM0-#include /usr/share/arduino/Arduino.mk--# --- mega2560 ide 1.0-#BOARD_TAG    = mega2560-#ARDUINO_PORT = /dev/ttyACM0-#include /usr/share/arduino/Arduino.mk--# --- mega2560 ide 1.6-#BOARD_TAG    = mega-#BOARD_SUB    = atmega2560-#MONITOR_PORT = /dev/ttyACM0-#ARDUINO_DIR  = /where/you/installed/arduino-1.6.5-#include /usr/share/arduino/Arduino.mk--# --- nano ide 1.0-#BOARD_TAG    = nano328-#MONITOR_PORT = /dev/ttyUSB0-#include /usr/share/arduino/Arduino.mk--# --- nano ide 1.6-#BOARD_TAG   = nano-#BOARD_SUB   = atmega328-#ARDUINO_DIR = /where/you/installed/arduino-1.6.5-#include /usr/share/arduino/Arduino.mk--# --- pro mini-#BOARD_TAG    = pro5v328-#MONITOR_PORT = /dev/ttyUSB0-#include /usr/share/arduino/Arduino.mk--# --- sparkfun pro micro-#BOARD_TAG         = promicro16-#ALTERNATE_CORE    = promicro-#BOARDS_TXT        = $(HOME)/arduino/hardware/promicro/boards.txt-#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/promicro/bootloaders-#BOOTLOADER_PATH   = caterina-#BOOTLOADER_FILE   = Caterina-promicro16.hex-#ISP_PROG     	   = usbasp-#AVRDUDE_OPTS 	   = -v-#include /usr/share/arduino/Arduino.mk--# --- chipkit-#BOARD_TAG = mega_pic32-#MPIDE_DIR = /where/you/installed/mpide-0023-linux64-20130817-test-#include /usr/share/arduino/chipKIT.mk--# --- pinoccio-#BOARD_TAG         = pinoccio256-#ALTERNATE_CORE    = pinoccio-#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/pinoccio/bootloaders-#BOOTLOADER_PATH   = STK500RFR2/release_0.51-#BOOTLOADER_FILE   = boot_pinoccio.hex-#CFLAGS_STD        = -std=gnu99-#CXXFLAGS_STD      = -std=gnu++11-#include /usr/share/arduino/Arduino.mk--# --- fio-#BOARD_TAG = fio-#include /usr/share/arduino/Arduino.mk--# --- atmega-ng ide 1.6-#BOARD_TAG    = atmegang-#BOARD_SUB    = atmega168-#MONITOR_PORT = /dev/ttyACM0-#ARDUINO_DIR  = /where/you/installed/arduino-1.6.5-#include /usr/share/arduino/Arduino.mk--# --- arduino-tiny ide 1.0-#ISP_PROG     	    = usbasp-#BOARD_TAG          = attiny85at8-#ALTERNATE_CORE     = tiny-#ARDUINO_VAR_PATH   = $(HOME)/arduino/hardware/tiny/cores/tiny-#ARDUINO_CORE_PATH  = $(HOME)/arduino/hardware/tiny/cores/tiny-#AVRDUDE_OPTS 	    = -v-#include /usr/share/arduino/Arduino.mk--# --- arduino-tiny ide 1.6-#ISP_PROG       = usbasp-#BOARD_TAG      = attiny85at8-#ALTERNATE_CORE = tiny-#ARDUINO_DIR    = /where/you/installed/arduino-1.6.5-#include /usr/share/arduino/Arduino.mk--# --- damellis attiny ide 1.0-#ISP_PROG       = usbasp-#BOARD_TAG      = attiny85-#ALTERNATE_CORE = attiny-master-#AVRDUDE_OPTS   = -v-#include /usr/share/arduino/Arduino.mk--# --- damellis attiny ide 1.6-#ISP_PROG       = usbasp-#BOARD_TAG      = attiny-#BOARD_SUB      = attiny85-#ALTERNATE_CORE = attiny-#F_CPU          = 16000000L-#ARDUINO_DIR    = /where/you/installed/arduino-1.6.5-#include /usr/share/arduino/Arduino.mk--# --- teensy3-#BOARD_TAG 	 = teensy31-#ARDUINO_DIR = /where/you/installed/the/patched/teensy/arduino-1.0.6-#include /usr/share/arduino/Teensy.mk--# --- mighty 1284p-#BOARD_TAG         = mighty_opt-#BOARDS_TXT        = $(HOME)/arduino/hardware/mighty-1284p/boards.txt-#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/mighty-1284p/bootloaders-#BOOTLOADER_PATH   = optiboot-#BOOTLOADER_FILE   = optiboot_atmega1284p.hex-#ISP_PROG     	   = usbasp-#AVRDUDE_OPTS 	   = -v-#include /usr/share/arduino/Arduino.mk--# --- atmega328p on breadboard-#BOARD_TAG    = atmega328bb-#ISP_PROG     = usbasp-#AVRDUDE_OPTS = -v-#BOARDS_TXT   = $(HOME)/arduino/hardware/breadboard/boards.txt-#include /usr/share/arduino/Arduino.mk
− examples/blink/README
@@ -1,28 +0,0 @@-This is a demo program using arduino-copilot. --To build the C code:--	runghc demo.hs--The resulting `.ino` sketch can be loaded into the Arduino IDE and flashed-to an Arduino board using the IDE.--It simply flashes the Arduino's on board LED, so should work on most or all-Arduino boards.--## Arduino-Makefile integration--The `Makefile` and `pre-build-hook.sh` show how to integrate arduino-copilot-with <https://github.com/sudar/Arduino-Makefile>. This automates generating-the C code, compiling that, and flashing it onto an Arduino Uno board,-with a single command--	make upload--Note that you will need to manually build the C code once, as shown above-, since the Arduino-Makefile expects to find a `.ino` file.--The path in the `Makefile` to `Arduino.mk` may need to be adjusted (the-default is the location where on a Debian system, `apt-get install-arduino-mk` will install it). You may also adjust the `Makefile` to target-a different board than the Arduino Uno.
− examples/blink/demo.hs
@@ -1,8 +0,0 @@-{-# LANGUAGE RebindableSyntax #-}--import Copilot.Arduino--main :: IO ()-main = arduino $ do-	led =: blinking-	delay =: MilliSeconds (constant 100)
− examples/blink/pre-build-hook.sh
@@ -1,2 +0,0 @@-#!/bin/sh-exec runghc demo.hs
− examples/button/Makefile
@@ -1,127 +0,0 @@-# Arduino Make file. Refer to https://github.com/sudar/Arduino-Makefile-BOARD_TAG    = uno-include /usr/share/arduino/Arduino.mk--# --- leonardo (or pro micro w/leo bootloader)-#BOARD_TAG    = leonardo-#MONITOR_PORT = /dev/ttyACM0-#include /usr/share/arduino/Arduino.mk--# --- mega2560 ide 1.0-#BOARD_TAG    = mega2560-#ARDUINO_PORT = /dev/ttyACM0-#include /usr/share/arduino/Arduino.mk--# --- mega2560 ide 1.6-#BOARD_TAG    = mega-#BOARD_SUB    = atmega2560-#MONITOR_PORT = /dev/ttyACM0-#ARDUINO_DIR  = /where/you/installed/arduino-1.6.5-#include /usr/share/arduino/Arduino.mk--# --- nano ide 1.0-#BOARD_TAG    = nano328-#MONITOR_PORT = /dev/ttyUSB0-#include /usr/share/arduino/Arduino.mk--# --- nano ide 1.6-#BOARD_TAG   = nano-#BOARD_SUB   = atmega328-#ARDUINO_DIR = /where/you/installed/arduino-1.6.5-#include /usr/share/arduino/Arduino.mk--# --- pro mini-#BOARD_TAG    = pro5v328-#MONITOR_PORT = /dev/ttyUSB0-#include /usr/share/arduino/Arduino.mk--# --- sparkfun pro micro-#BOARD_TAG         = promicro16-#ALTERNATE_CORE    = promicro-#BOARDS_TXT        = $(HOME)/arduino/hardware/promicro/boards.txt-#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/promicro/bootloaders-#BOOTLOADER_PATH   = caterina-#BOOTLOADER_FILE   = Caterina-promicro16.hex-#ISP_PROG     	   = usbasp-#AVRDUDE_OPTS 	   = -v-#include /usr/share/arduino/Arduino.mk--# --- chipkit-#BOARD_TAG = mega_pic32-#MPIDE_DIR = /where/you/installed/mpide-0023-linux64-20130817-test-#include /usr/share/arduino/chipKIT.mk--# --- pinoccio-#BOARD_TAG         = pinoccio256-#ALTERNATE_CORE    = pinoccio-#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/pinoccio/bootloaders-#BOOTLOADER_PATH   = STK500RFR2/release_0.51-#BOOTLOADER_FILE   = boot_pinoccio.hex-#CFLAGS_STD        = -std=gnu99-#CXXFLAGS_STD      = -std=gnu++11-#include /usr/share/arduino/Arduino.mk--# --- fio-#BOARD_TAG = fio-#include /usr/share/arduino/Arduino.mk--# --- atmega-ng ide 1.6-#BOARD_TAG    = atmegang-#BOARD_SUB    = atmega168-#MONITOR_PORT = /dev/ttyACM0-#ARDUINO_DIR  = /where/you/installed/arduino-1.6.5-#include /usr/share/arduino/Arduino.mk--# --- arduino-tiny ide 1.0-#ISP_PROG     	    = usbasp-#BOARD_TAG          = attiny85at8-#ALTERNATE_CORE     = tiny-#ARDUINO_VAR_PATH   = $(HOME)/arduino/hardware/tiny/cores/tiny-#ARDUINO_CORE_PATH  = $(HOME)/arduino/hardware/tiny/cores/tiny-#AVRDUDE_OPTS 	    = -v-#include /usr/share/arduino/Arduino.mk--# --- arduino-tiny ide 1.6-#ISP_PROG       = usbasp-#BOARD_TAG      = attiny85at8-#ALTERNATE_CORE = tiny-#ARDUINO_DIR    = /where/you/installed/arduino-1.6.5-#include /usr/share/arduino/Arduino.mk--# --- damellis attiny ide 1.0-#ISP_PROG       = usbasp-#BOARD_TAG      = attiny85-#ALTERNATE_CORE = attiny-master-#AVRDUDE_OPTS   = -v-#include /usr/share/arduino/Arduino.mk--# --- damellis attiny ide 1.6-#ISP_PROG       = usbasp-#BOARD_TAG      = attiny-#BOARD_SUB      = attiny85-#ALTERNATE_CORE = attiny-#F_CPU          = 16000000L-#ARDUINO_DIR    = /where/you/installed/arduino-1.6.5-#include /usr/share/arduino/Arduino.mk--# --- teensy3-#BOARD_TAG 	 = teensy31-#ARDUINO_DIR = /where/you/installed/the/patched/teensy/arduino-1.0.6-#include /usr/share/arduino/Teensy.mk--# --- mighty 1284p-#BOARD_TAG         = mighty_opt-#BOARDS_TXT        = $(HOME)/arduino/hardware/mighty-1284p/boards.txt-#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/mighty-1284p/bootloaders-#BOOTLOADER_PATH   = optiboot-#BOOTLOADER_FILE   = optiboot_atmega1284p.hex-#ISP_PROG     	   = usbasp-#AVRDUDE_OPTS 	   = -v-#include /usr/share/arduino/Arduino.mk--# --- atmega328p on breadboard-#BOARD_TAG    = atmega328bb-#ISP_PROG     = usbasp-#AVRDUDE_OPTS = -v-#BOARDS_TXT   = $(HOME)/arduino/hardware/breadboard/boards.txt-#include /usr/share/arduino/Arduino.mk
− examples/button/README
@@ -1,24 +0,0 @@-This is a demo program using arduino-copilot. --To build the C code:--	runghc demo.hs--The resulting `.ino` sketch can be loaded into the Arduino IDE and flashed-to an Arduino Uno board using the IDE.--## Arduino-Makefile integration--The `Makefile` and `pre-build-hook.sh` show how to integrate arduino-copilot-with <https://github.com/sudar/Arduino-Makefile>. This automates generating-the C code, compiling that, and flashing it onto an Arduino Uno board,-with a single command--	make upload--Note that you will need to manually build the C code once, as shown above-, since the Arduino-Makefile expects to find a `.ino` file.--The path in the `Makefile` to `Arduino.mk` may need to be adjusted (the-default is the location where on a Debian system, `apt-get install-arduino-mk` will install it).
− examples/button/demo.hs
@@ -1,22 +0,0 @@-{-# LANGUAGE RebindableSyntax #-}--import Copilot.Arduino.Uno--longer_and_longer :: Stream Word32-longer_and_longer = counter true $ counter true false `mod` 64 == 0--counter :: Stream Bool -> Stream Bool -> Stream Word32-counter inc reset = cnt-   where-	cnt = if reset-		then 0-		else if inc-			then z + 1-			else z-	z = [0] ++ cnt--main :: IO ()-main = arduino $ do-	buttonpressed <- input' pin12 [False, False, False, True, True]-	led =: buttonpressed || blinking-	delay =: MilliSeconds (longer_and_longer * 2)
− examples/button/pre-build-hook.sh
@@ -1,2 +0,0 @@-#!/bin/sh-exec runghc demo.hs
− examples/eeprom/Makefile
@@ -1,129 +0,0 @@-# Arduino Make file. Refer to https://github.com/sudar/Arduino-Makefile-BOARD_TAG    = uno-ARDUINO_LIBS = EEPROMEx-CPPFLAGS     = -D_EEPROMEX_DEBUG-include /usr/share/arduino/Arduino.mk--# --- leonardo (or pro micro w/leo bootloader)-#BOARD_TAG    = leonardo-#MONITOR_PORT = /dev/ttyACM0-#include /usr/share/arduino/Arduino.mk--# --- mega2560 ide 1.0-#BOARD_TAG    = mega2560-#ARDUINO_PORT = /dev/ttyACM0-#include /usr/share/arduino/Arduino.mk--# --- mega2560 ide 1.6-#BOARD_TAG    = mega-#BOARD_SUB    = atmega2560-#MONITOR_PORT = /dev/ttyACM0-#ARDUINO_DIR  = /where/you/installed/arduino-1.6.5-#include /usr/share/arduino/Arduino.mk--# --- nano ide 1.0-#BOARD_TAG    = nano328-#MONITOR_PORT = /dev/ttyUSB0-#include /usr/share/arduino/Arduino.mk--# --- nano ide 1.6-#BOARD_TAG   = nano-#BOARD_SUB   = atmega328-#ARDUINO_DIR = /where/you/installed/arduino-1.6.5-#include /usr/share/arduino/Arduino.mk--# --- pro mini-#BOARD_TAG    = pro5v328-#MONITOR_PORT = /dev/ttyUSB0-#include /usr/share/arduino/Arduino.mk--# --- sparkfun pro micro-#BOARD_TAG         = promicro16-#ALTERNATE_CORE    = promicro-#BOARDS_TXT        = $(HOME)/arduino/hardware/promicro/boards.txt-#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/promicro/bootloaders-#BOOTLOADER_PATH   = caterina-#BOOTLOADER_FILE   = Caterina-promicro16.hex-#ISP_PROG     	   = usbasp-#AVRDUDE_OPTS 	   = -v-#include /usr/share/arduino/Arduino.mk--# --- chipkit-#BOARD_TAG = mega_pic32-#MPIDE_DIR = /where/you/installed/mpide-0023-linux64-20130817-test-#include /usr/share/arduino/chipKIT.mk--# --- pinoccio-#BOARD_TAG         = pinoccio256-#ALTERNATE_CORE    = pinoccio-#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/pinoccio/bootloaders-#BOOTLOADER_PATH   = STK500RFR2/release_0.51-#BOOTLOADER_FILE   = boot_pinoccio.hex-#CFLAGS_STD        = -std=gnu99-#CXXFLAGS_STD      = -std=gnu++11-#include /usr/share/arduino/Arduino.mk--# --- fio-#BOARD_TAG = fio-#include /usr/share/arduino/Arduino.mk--# --- atmega-ng ide 1.6-#BOARD_TAG    = atmegang-#BOARD_SUB    = atmega168-#MONITOR_PORT = /dev/ttyACM0-#ARDUINO_DIR  = /where/you/installed/arduino-1.6.5-#include /usr/share/arduino/Arduino.mk--# --- arduino-tiny ide 1.0-#ISP_PROG     	    = usbasp-#BOARD_TAG          = attiny85at8-#ALTERNATE_CORE     = tiny-#ARDUINO_VAR_PATH   = $(HOME)/arduino/hardware/tiny/cores/tiny-#ARDUINO_CORE_PATH  = $(HOME)/arduino/hardware/tiny/cores/tiny-#AVRDUDE_OPTS 	    = -v-#include /usr/share/arduino/Arduino.mk--# --- arduino-tiny ide 1.6-#ISP_PROG       = usbasp-#BOARD_TAG      = attiny85at8-#ALTERNATE_CORE = tiny-#ARDUINO_DIR    = /where/you/installed/arduino-1.6.5-#include /usr/share/arduino/Arduino.mk--# --- damellis attiny ide 1.0-#ISP_PROG       = usbasp-#BOARD_TAG      = attiny85-#ALTERNATE_CORE = attiny-master-#AVRDUDE_OPTS   = -v-#include /usr/share/arduino/Arduino.mk--# --- damellis attiny ide 1.6-#ISP_PROG       = usbasp-#BOARD_TAG      = attiny-#BOARD_SUB      = attiny85-#ALTERNATE_CORE = attiny-#F_CPU          = 16000000L-#ARDUINO_DIR    = /where/you/installed/arduino-1.6.5-#include /usr/share/arduino/Arduino.mk--# --- teensy3-#BOARD_TAG 	 = teensy31-#ARDUINO_DIR = /where/you/installed/the/patched/teensy/arduino-1.0.6-#include /usr/share/arduino/Teensy.mk--# --- mighty 1284p-#BOARD_TAG         = mighty_opt-#BOARDS_TXT        = $(HOME)/arduino/hardware/mighty-1284p/boards.txt-#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/mighty-1284p/bootloaders-#BOOTLOADER_PATH   = optiboot-#BOOTLOADER_FILE   = optiboot_atmega1284p.hex-#ISP_PROG     	   = usbasp-#AVRDUDE_OPTS 	   = -v-#include /usr/share/arduino/Arduino.mk--# --- atmega328p on breadboard-#BOARD_TAG    = atmega328bb-#ISP_PROG     = usbasp-#AVRDUDE_OPTS = -v-#BOARDS_TXT   = $(HOME)/arduino/hardware/breadboard/boards.txt-#include /usr/share/arduino/Arduino.mk
− examples/eeprom/README
@@ -1,25 +0,0 @@-This is a demo program using arduino-copilot, showing how to use EEPROMex.--This needs the Arduino-Makefile to be installed. It relies on it-to set CPPFLAGS=-D_EEPROMEX_DEBUG when building the C code.-<https://github.com/sudar/Arduino-Makefile>--The path in the `Makefile` to `Arduino.mk` may need to be adjusted (the-default is the location where on a Debian system, `apt-get install-arduino-mk` will install it).--You will also need to install the EEPROMex library to someplace where-the Arduino toolchain can find it.-<https://github.com/thijse/Arduino-EEPROMEx/>--First, run this to build and upload a sketch that zeros out some values of-the EEPROM.--	ZERO=y runghc demo.hs-	ZERO=y make upload--Then, you can build and upload the sketch that actually does something-interesting.--	runghc demo.hs-	make upload
− examples/eeprom/demo.hs
@@ -1,78 +0,0 @@-{-# LANGUAGE RebindableSyntax #-}--import Copilot.Arduino.Uno-import qualified Copilot.Arduino.Library.EEPROMex as EEPROM-import qualified Copilot.Arduino.Library.Serial as Serial-import System.Posix.Env-import qualified Prelude--main :: IO ()-main = do-	z <- getEnvDefault "ZERO" ""-	arduino $ case z of-		"y" -> mainZero-		_ -> mainReal---- Zero out the EEPROM, in preparation for mainReal.-mainZero :: Sketch ()-mainZero = do-	EEPROM.maxAllowedWrites 10--	(_, eepromloc) <- EEPROM.alloc' (20 :: ADC)-	eepromloc =: constant (0 :: ADC) @: firstIteration--	(_, uptimeloc) <- EEPROM.alloc' (0 :: Word32)-	uptimeloc =: constant (0 :: Word32) @: firstIteration--	Serial.baud 9600-	Serial.device =: [ Serial.str "EEPROM zeroed" ] @: firstIteration--mainReal :: Sketch ()-mainReal = do-	-- Store the maximum value read from a1 in the EEPROM.-	-- There are only 1024 possible values, so this can only possibly-	-- write new values that many times, so no delay is needed in this-	-- program. Just in case though, limit the total number of writes:-	EEPROM.maxAllowedWrites 2048-	(bootval, eepromloc) <- EEPROM.alloc' (20 :: ADC)-	currval <- input' a1 [10, 11, 25, 100, 99, 0, 0, 0, 0, 0]-	let maxval = if currval > bootval then currval else bootval-	-- Note that using maxBound here means it will never write-	-- on the first iteration, even if a1 is then larger than bootval.-	-- Any better way to write this that avoids the problem?-	let newmax = currval > ([maxBound] ++ maxval)-	eepromloc =: currval @: newmax--	-- Store the maximum MilliSeconds this program has been left running-	-- in the EEPROM too.-	(bootuptime, uptimeloc) <- EEPROM.alloc' (0 :: Word32)-	uptime <- input' millis (dummyclockinput [1, 1, 1, 2, 2, 2, 3, 3, 3])-	-- micros overflows after ~70 minutes; detect that and use it to-	-- trigger a periodic write of the uptime to EEPROM.-	hourlyish <- microsOverFlowed-	let maxuptime = if uptime > bootuptime then uptime else bootuptime-	uptimeloc =: maxuptime @: hourlyish-	-	Serial.baud 9600-	Serial.device =:-		[ Serial.str "max a1 seen: "-		-- This is not quite right, because maxval resets to-		-- bootval when this is displayed at hourlyish.-		-- Interpreting shows the problem:-		--    --              (3)             (20,3)-		-- How to fix this?-		, Serial.show maxval-		, Serial.str " max uptime: "-		, Serial.show maxuptime-		, Serial.char '\n'-		]-		@: (firstIteration || newmax || hourlyish)--microsOverFlowed :: Sketch (Behavior Bool)-microsOverFlowed = do-	t <- input' micros (dummyclockinput [1, 2, 3])-	let oldt = [0] ++ t-	return (t < oldt)--dummyclockinput :: [Word32] -> [Word32]-dummyclockinput = Prelude.cycle
− examples/eeprom/pre-build-hook.sh
@@ -1,2 +0,0 @@-#!/bin/sh-exec runghc demo.hs
− examples/eepromrange/Makefile
@@ -1,129 +0,0 @@-# Arduino Make file. Refer to https://github.com/sudar/Arduino-Makefile-BOARD_TAG    = uno-ARDUINO_LIBS = EEPROMEx-CPPFLAGS     = -D_EEPROMEX_DEBUG-include /usr/share/arduino/Arduino.mk--# --- leonardo (or pro micro w/leo bootloader)-#BOARD_TAG    = leonardo-#MONITOR_PORT = /dev/ttyACM0-#include /usr/share/arduino/Arduino.mk--# --- mega2560 ide 1.0-#BOARD_TAG    = mega2560-#ARDUINO_PORT = /dev/ttyACM0-#include /usr/share/arduino/Arduino.mk--# --- mega2560 ide 1.6-#BOARD_TAG    = mega-#BOARD_SUB    = atmega2560-#MONITOR_PORT = /dev/ttyACM0-#ARDUINO_DIR  = /where/you/installed/arduino-1.6.5-#include /usr/share/arduino/Arduino.mk--# --- nano ide 1.0-#BOARD_TAG    = nano328-#MONITOR_PORT = /dev/ttyUSB0-#include /usr/share/arduino/Arduino.mk--# --- nano ide 1.6-#BOARD_TAG   = nano-#BOARD_SUB   = atmega328-#ARDUINO_DIR = /where/you/installed/arduino-1.6.5-#include /usr/share/arduino/Arduino.mk--# --- pro mini-#BOARD_TAG    = pro5v328-#MONITOR_PORT = /dev/ttyUSB0-#include /usr/share/arduino/Arduino.mk--# --- sparkfun pro micro-#BOARD_TAG         = promicro16-#ALTERNATE_CORE    = promicro-#BOARDS_TXT        = $(HOME)/arduino/hardware/promicro/boards.txt-#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/promicro/bootloaders-#BOOTLOADER_PATH   = caterina-#BOOTLOADER_FILE   = Caterina-promicro16.hex-#ISP_PROG     	   = usbasp-#AVRDUDE_OPTS 	   = -v-#include /usr/share/arduino/Arduino.mk--# --- chipkit-#BOARD_TAG = mega_pic32-#MPIDE_DIR = /where/you/installed/mpide-0023-linux64-20130817-test-#include /usr/share/arduino/chipKIT.mk--# --- pinoccio-#BOARD_TAG         = pinoccio256-#ALTERNATE_CORE    = pinoccio-#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/pinoccio/bootloaders-#BOOTLOADER_PATH   = STK500RFR2/release_0.51-#BOOTLOADER_FILE   = boot_pinoccio.hex-#CFLAGS_STD        = -std=gnu99-#CXXFLAGS_STD      = -std=gnu++11-#include /usr/share/arduino/Arduino.mk--# --- fio-#BOARD_TAG = fio-#include /usr/share/arduino/Arduino.mk--# --- atmega-ng ide 1.6-#BOARD_TAG    = atmegang-#BOARD_SUB    = atmega168-#MONITOR_PORT = /dev/ttyACM0-#ARDUINO_DIR  = /where/you/installed/arduino-1.6.5-#include /usr/share/arduino/Arduino.mk--# --- arduino-tiny ide 1.0-#ISP_PROG     	    = usbasp-#BOARD_TAG          = attiny85at8-#ALTERNATE_CORE     = tiny-#ARDUINO_VAR_PATH   = $(HOME)/arduino/hardware/tiny/cores/tiny-#ARDUINO_CORE_PATH  = $(HOME)/arduino/hardware/tiny/cores/tiny-#AVRDUDE_OPTS 	    = -v-#include /usr/share/arduino/Arduino.mk--# --- arduino-tiny ide 1.6-#ISP_PROG       = usbasp-#BOARD_TAG      = attiny85at8-#ALTERNATE_CORE = tiny-#ARDUINO_DIR    = /where/you/installed/arduino-1.6.5-#include /usr/share/arduino/Arduino.mk--# --- damellis attiny ide 1.0-#ISP_PROG       = usbasp-#BOARD_TAG      = attiny85-#ALTERNATE_CORE = attiny-master-#AVRDUDE_OPTS   = -v-#include /usr/share/arduino/Arduino.mk--# --- damellis attiny ide 1.6-#ISP_PROG       = usbasp-#BOARD_TAG      = attiny-#BOARD_SUB      = attiny85-#ALTERNATE_CORE = attiny-#F_CPU          = 16000000L-#ARDUINO_DIR    = /where/you/installed/arduino-1.6.5-#include /usr/share/arduino/Arduino.mk--# --- teensy3-#BOARD_TAG 	 = teensy31-#ARDUINO_DIR = /where/you/installed/the/patched/teensy/arduino-1.0.6-#include /usr/share/arduino/Teensy.mk--# --- mighty 1284p-#BOARD_TAG         = mighty_opt-#BOARDS_TXT        = $(HOME)/arduino/hardware/mighty-1284p/boards.txt-#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/mighty-1284p/bootloaders-#BOOTLOADER_PATH   = optiboot-#BOOTLOADER_FILE   = optiboot_atmega1284p.hex-#ISP_PROG     	   = usbasp-#AVRDUDE_OPTS 	   = -v-#include /usr/share/arduino/Arduino.mk--# --- atmega328p on breadboard-#BOARD_TAG    = atmega328bb-#ISP_PROG     = usbasp-#AVRDUDE_OPTS = -v-#BOARDS_TXT   = $(HOME)/arduino/hardware/breadboard/boards.txt-#include /usr/share/arduino/Arduino.mk
− examples/eepromrange/README
@@ -1,26 +0,0 @@-This is a demo program using arduino-copilot, showing how to use EEPROMex-with ranges.--This needs the Arduino-Makefile to be installed. It relies on it-to set CPPFLAGS=-D_EEPROMEX_DEBUG when building the C code.-<https://github.com/sudar/Arduino-Makefile>--The path in the `Makefile` to `Arduino.mk` may need to be adjusted (the-default is the location where on a Debian system, `apt-get install-arduino-mk` will install it).--You will also need to install the EEPROMex library to someplace where-the Arduino toolchain can find it.-<https://github.com/thijse/Arduino-EEPROMEx/>--First, run this to build and upload a sketch that zeros out the entire-EEPROM.--	ZERO=y runghc demo.hs-	ZERO=y make upload--Then, you can build and upload the sketch that actually does something-interesting.--	runghc demo.hs-	make upload
− examples/eepromrange/demo.hs
@@ -1,47 +0,0 @@-{-# LANGUAGE RebindableSyntax #-}--import Copilot.Arduino.Uno-import qualified Copilot.Arduino.Library.EEPROMex as EEPROM-import qualified Copilot.Arduino.Library.Serial as Serial-import System.Posix.Env---- Change this to use a smaller part of the EEPROM.-sz :: Word16-sz = sizeOfEEPROM--main :: IO ()-main = do-	z <- getEnvDefault "ZERO" ""-	arduino $ case z of-		"y" -> mainZero-		_ -> mainReal---- Zero out the EEPROM, in preparation for mainReal.-mainZero :: Sketch ()-mainZero = do-	EEPROM.maxAllowedWrites sz--	range <- EEPROM.allocRange sz :: Sketch (EEPROM.Range Word8)-	range =: EEPROM.sweepRange 0 (constant (0 :: Word8))-	-	Serial.baud 9600-	Serial.device =: [ Serial.str "EEPROM zeroing started" ]-		@: firstIteration--mainReal :: Sketch ()-mainReal = do-	EEPROM.maxAllowedWrites (sz * 10)-	range <- EEPROM.allocRange sz :: Sketch (EEPROM.Range ADC)-	v <- input' a1 ([10, 20..] :: [ADC])-	range =: EEPROM.sweepRange 0 v @: frequency 3-	oldv <- input' (EEPROM.scanRange range 1) [11..] :: Sketch (Behavior ADC)-	led =: frequency 3-	Serial.device =:-		[ Serial.str "a1:"-		, Serial.show v-		, Serial.str " old EEPROM value:"-		, Serial.show oldv-		, Serial.char '\n'-		]-	delay =: MilliSeconds (constant 10000)-	Serial.baud 9600
− examples/eepromrange/pre-build-hook.sh
@@ -1,2 +0,0 @@-#!/bin/sh-exec runghc demo.hs
− examples/robot/Makefile
@@ -1,127 +0,0 @@-# Arduino Make file. Refer to https://github.com/sudar/Arduino-Makefile-BOARD_TAG    = uno-include /usr/share/arduino/Arduino.mk--# --- leonardo (or pro micro w/leo bootloader)-#BOARD_TAG    = leonardo-#MONITOR_PORT = /dev/ttyACM0-#include /usr/share/arduino/Arduino.mk--# --- mega2560 ide 1.0-#BOARD_TAG    = mega2560-#ARDUINO_PORT = /dev/ttyACM0-#include /usr/share/arduino/Arduino.mk--# --- mega2560 ide 1.6-#BOARD_TAG    = mega-#BOARD_SUB    = atmega2560-#MONITOR_PORT = /dev/ttyACM0-#ARDUINO_DIR  = /where/you/installed/arduino-1.6.5-#include /usr/share/arduino/Arduino.mk--# --- nano ide 1.0-#BOARD_TAG    = nano328-#MONITOR_PORT = /dev/ttyUSB0-#include /usr/share/arduino/Arduino.mk--# --- nano ide 1.6-#BOARD_TAG   = nano-#BOARD_SUB   = atmega328-#ARDUINO_DIR = /where/you/installed/arduino-1.6.5-#include /usr/share/arduino/Arduino.mk--# --- pro mini-#BOARD_TAG    = pro5v328-#MONITOR_PORT = /dev/ttyUSB0-#include /usr/share/arduino/Arduino.mk--# --- sparkfun pro micro-#BOARD_TAG         = promicro16-#ALTERNATE_CORE    = promicro-#BOARDS_TXT        = $(HOME)/arduino/hardware/promicro/boards.txt-#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/promicro/bootloaders-#BOOTLOADER_PATH   = caterina-#BOOTLOADER_FILE   = Caterina-promicro16.hex-#ISP_PROG     	   = usbasp-#AVRDUDE_OPTS 	   = -v-#include /usr/share/arduino/Arduino.mk--# --- chipkit-#BOARD_TAG = mega_pic32-#MPIDE_DIR = /where/you/installed/mpide-0023-linux64-20130817-test-#include /usr/share/arduino/chipKIT.mk--# --- pinoccio-#BOARD_TAG         = pinoccio256-#ALTERNATE_CORE    = pinoccio-#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/pinoccio/bootloaders-#BOOTLOADER_PATH   = STK500RFR2/release_0.51-#BOOTLOADER_FILE   = boot_pinoccio.hex-#CFLAGS_STD        = -std=gnu99-#CXXFLAGS_STD      = -std=gnu++11-#include /usr/share/arduino/Arduino.mk--# --- fio-#BOARD_TAG = fio-#include /usr/share/arduino/Arduino.mk--# --- atmega-ng ide 1.6-#BOARD_TAG    = atmegang-#BOARD_SUB    = atmega168-#MONITOR_PORT = /dev/ttyACM0-#ARDUINO_DIR  = /where/you/installed/arduino-1.6.5-#include /usr/share/arduino/Arduino.mk--# --- arduino-tiny ide 1.0-#ISP_PROG     	    = usbasp-#BOARD_TAG          = attiny85at8-#ALTERNATE_CORE     = tiny-#ARDUINO_VAR_PATH   = $(HOME)/arduino/hardware/tiny/cores/tiny-#ARDUINO_CORE_PATH  = $(HOME)/arduino/hardware/tiny/cores/tiny-#AVRDUDE_OPTS 	    = -v-#include /usr/share/arduino/Arduino.mk--# --- arduino-tiny ide 1.6-#ISP_PROG       = usbasp-#BOARD_TAG      = attiny85at8-#ALTERNATE_CORE = tiny-#ARDUINO_DIR    = /where/you/installed/arduino-1.6.5-#include /usr/share/arduino/Arduino.mk--# --- damellis attiny ide 1.0-#ISP_PROG       = usbasp-#BOARD_TAG      = attiny85-#ALTERNATE_CORE = attiny-master-#AVRDUDE_OPTS   = -v-#include /usr/share/arduino/Arduino.mk--# --- damellis attiny ide 1.6-#ISP_PROG       = usbasp-#BOARD_TAG      = attiny-#BOARD_SUB      = attiny85-#ALTERNATE_CORE = attiny-#F_CPU          = 16000000L-#ARDUINO_DIR    = /where/you/installed/arduino-1.6.5-#include /usr/share/arduino/Arduino.mk--# --- teensy3-#BOARD_TAG 	 = teensy31-#ARDUINO_DIR = /where/you/installed/the/patched/teensy/arduino-1.0.6-#include /usr/share/arduino/Teensy.mk--# --- mighty 1284p-#BOARD_TAG         = mighty_opt-#BOARDS_TXT        = $(HOME)/arduino/hardware/mighty-1284p/boards.txt-#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/mighty-1284p/bootloaders-#BOOTLOADER_PATH   = optiboot-#BOOTLOADER_FILE   = optiboot_atmega1284p.hex-#ISP_PROG     	   = usbasp-#AVRDUDE_OPTS 	   = -v-#include /usr/share/arduino/Arduino.mk--# --- atmega328p on breadboard-#BOARD_TAG    = atmega328bb-#ISP_PROG     = usbasp-#AVRDUDE_OPTS = -v-#BOARDS_TXT   = $(HOME)/arduino/hardware/breadboard/boards.txt-#include /usr/share/arduino/Arduino.mk
− examples/robot/README
@@ -1,24 +0,0 @@-This is a demo program using arduino-copilot. --To build the C code:--	runghc demo.hs--The resulting `.ino` sketch can be loaded into the Arduino IDE and flashed-to an Arduino Uno board using the IDE.--## Arduino-Makefile integration--The `Makefile` and `pre-build-hook.sh` show how to integrate arduino-copilot-with <https://github.com/sudar/Arduino-Makefile>. This automates generating-the C code, compiling that, and flashing it onto an Arduino Uno board,-with a single command--	make upload--Note that you will need to manually build the C code once, as shown above-, since the Arduino-Makefile expects to find a `.ino` file.--The path in the `Makefile` to `Arduino.mk` may need to be adjusted (the-default is the location where on a Debian system, `apt-get install-arduino-mk` will install it).
− examples/robot/demo.hs
@@ -1,90 +0,0 @@-{- A simple line-following robot.- -- - This is not the most efficient or best way to implement it- - (it compiles to around 500 lines of C code), but- - it is a good example of building up a Sketch by combining- - simpler Sketches.- -}--{-# LANGUAGE RebindableSyntax #-}--import Copilot.Arduino.Uno-import qualified Copilot.Arduino.Library.Serial.XBee as XBee--main :: IO ()-main = arduino $ do-	XBee.configure pin2 pin3 (XBee.Baud 9600)-	emergencystop <- input pin4-	if emergencystop-		then stop-		else do-			ll <- leftLineSensed-			rl <- rightLineSensed-			if ll && rl-				then stop-				else if ll-					then turnLeft-					else if rl-						then turnRight-						else goForward--stop :: Sketch ()-stop = do-	led =: true-	XBee.device =: [XBee.str "stopped\n"]-	rightWheelMotor true (constant 0)-	leftWheelMotor true (constant 0)--goForward :: Sketch ()-goForward = do-	led =: false-	XBee.device =: [XBee.str "forward\n"]-	leftWheelMotor true (constant 255)-	rightWheelMotor true (constant 255)--turnLeft :: Sketch ()-turnLeft = do-	led =: blinking-	XBee.device =: [XBee.str "turn left\n"]-	rightWheelMotor true (constant 128)-	leftWheelMotor false (constant 128)--turnRight :: Sketch ()-turnRight = do-	led =: blinking-	XBee.device =: [XBee.str "turn right\n"]-	rightWheelMotor false (constant 128)-	leftWheelMotor true (constant 128)--leftLineSensed :: Sketch (Behavior Bool)-leftLineSensed = lineSensed a1 "left"--rightLineSensed :: Sketch (Behavior Bool)-rightLineSensed = lineSensed a2 "right"--lineSensed :: IsAnalogInputPin t => Pin t -> [Char] -> Sketch (Stream Bool)-lineSensed pin desc = do-	v <- input pin :: Sketch (Behavior ADC)-	XBee.device =: -		[ XBee.str (desc <> " line sensor:")-		, XBee.show v-		, XBee.char '\n'-		]-	return (v > 50)--leftWheelMotor :: Behavior Bool -> Behavior Word8 -> Sketch ()-leftWheelMotor = wheelMotor pin5 pin6--rightWheelMotor :: Behavior Bool -> Behavior Word8 -> Sketch ()-rightWheelMotor = wheelMotor pin9 pin10--wheelMotor-	:: (IsPWMPin t1, IsPWMPin t2)-	=> Pin t1 -- ^ pin to drive motor forward-	-> Pin t2 -- ^ pin to drive motor backward-	-> Behavior Bool -- ^ True when driving forward-	-> Behavior Word8 -- ^ How hard to drive the motor.-	-> Sketch ()-wheelMotor forwardpin backwardpin forward power = do-	forwardpin =: pwm (if forward then power else constant 0)-	backwardpin =: pwm (if forward then constant 0 else power)
− examples/robot/pre-build-hook.sh
@@ -1,2 +0,0 @@-#!/bin/sh-exec runghc demo.hs
− examples/serialport/Makefile
@@ -1,127 +0,0 @@-# Arduino Make file. Refer to https://github.com/sudar/Arduino-Makefile-BOARD_TAG    = uno-include /usr/share/arduino/Arduino.mk--# --- leonardo (or pro micro w/leo bootloader)-#BOARD_TAG    = leonardo-#MONITOR_PORT = /dev/ttyACM0-#include /usr/share/arduino/Arduino.mk--# --- mega2560 ide 1.0-#BOARD_TAG    = mega2560-#ARDUINO_PORT = /dev/ttyACM0-#include /usr/share/arduino/Arduino.mk--# --- mega2560 ide 1.6-#BOARD_TAG    = mega-#BOARD_SUB    = atmega2560-#MONITOR_PORT = /dev/ttyACM0-#ARDUINO_DIR  = /where/you/installed/arduino-1.6.5-#include /usr/share/arduino/Arduino.mk--# --- nano ide 1.0-#BOARD_TAG    = nano328-#MONITOR_PORT = /dev/ttyUSB0-#include /usr/share/arduino/Arduino.mk--# --- nano ide 1.6-#BOARD_TAG   = nano-#BOARD_SUB   = atmega328-#ARDUINO_DIR = /where/you/installed/arduino-1.6.5-#include /usr/share/arduino/Arduino.mk--# --- pro mini-#BOARD_TAG    = pro5v328-#MONITOR_PORT = /dev/ttyUSB0-#include /usr/share/arduino/Arduino.mk--# --- sparkfun pro micro-#BOARD_TAG         = promicro16-#ALTERNATE_CORE    = promicro-#BOARDS_TXT        = $(HOME)/arduino/hardware/promicro/boards.txt-#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/promicro/bootloaders-#BOOTLOADER_PATH   = caterina-#BOOTLOADER_FILE   = Caterina-promicro16.hex-#ISP_PROG     	   = usbasp-#AVRDUDE_OPTS 	   = -v-#include /usr/share/arduino/Arduino.mk--# --- chipkit-#BOARD_TAG = mega_pic32-#MPIDE_DIR = /where/you/installed/mpide-0023-linux64-20130817-test-#include /usr/share/arduino/chipKIT.mk--# --- pinoccio-#BOARD_TAG         = pinoccio256-#ALTERNATE_CORE    = pinoccio-#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/pinoccio/bootloaders-#BOOTLOADER_PATH   = STK500RFR2/release_0.51-#BOOTLOADER_FILE   = boot_pinoccio.hex-#CFLAGS_STD        = -std=gnu99-#CXXFLAGS_STD      = -std=gnu++11-#include /usr/share/arduino/Arduino.mk--# --- fio-#BOARD_TAG = fio-#include /usr/share/arduino/Arduino.mk--# --- atmega-ng ide 1.6-#BOARD_TAG    = atmegang-#BOARD_SUB    = atmega168-#MONITOR_PORT = /dev/ttyACM0-#ARDUINO_DIR  = /where/you/installed/arduino-1.6.5-#include /usr/share/arduino/Arduino.mk--# --- arduino-tiny ide 1.0-#ISP_PROG     	    = usbasp-#BOARD_TAG          = attiny85at8-#ALTERNATE_CORE     = tiny-#ARDUINO_VAR_PATH   = $(HOME)/arduino/hardware/tiny/cores/tiny-#ARDUINO_CORE_PATH  = $(HOME)/arduino/hardware/tiny/cores/tiny-#AVRDUDE_OPTS 	    = -v-#include /usr/share/arduino/Arduino.mk--# --- arduino-tiny ide 1.6-#ISP_PROG       = usbasp-#BOARD_TAG      = attiny85at8-#ALTERNATE_CORE = tiny-#ARDUINO_DIR    = /where/you/installed/arduino-1.6.5-#include /usr/share/arduino/Arduino.mk--# --- damellis attiny ide 1.0-#ISP_PROG       = usbasp-#BOARD_TAG      = attiny85-#ALTERNATE_CORE = attiny-master-#AVRDUDE_OPTS   = -v-#include /usr/share/arduino/Arduino.mk--# --- damellis attiny ide 1.6-#ISP_PROG       = usbasp-#BOARD_TAG      = attiny-#BOARD_SUB      = attiny85-#ALTERNATE_CORE = attiny-#F_CPU          = 16000000L-#ARDUINO_DIR    = /where/you/installed/arduino-1.6.5-#include /usr/share/arduino/Arduino.mk--# --- teensy3-#BOARD_TAG 	 = teensy31-#ARDUINO_DIR = /where/you/installed/the/patched/teensy/arduino-1.0.6-#include /usr/share/arduino/Teensy.mk--# --- mighty 1284p-#BOARD_TAG         = mighty_opt-#BOARDS_TXT        = $(HOME)/arduino/hardware/mighty-1284p/boards.txt-#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/mighty-1284p/bootloaders-#BOOTLOADER_PATH   = optiboot-#BOOTLOADER_FILE   = optiboot_atmega1284p.hex-#ISP_PROG     	   = usbasp-#AVRDUDE_OPTS 	   = -v-#include /usr/share/arduino/Arduino.mk--# --- atmega328p on breadboard-#BOARD_TAG    = atmega328bb-#ISP_PROG     = usbasp-#AVRDUDE_OPTS = -v-#BOARDS_TXT   = $(HOME)/arduino/hardware/breadboard/boards.txt-#include /usr/share/arduino/Arduino.mk
− examples/serialport/README
@@ -1,24 +0,0 @@-This is a demo program using arduino-copilot. --To build the C code:--	runghc demo.hs--The resulting `.ino` sketch can be loaded into the Arduino IDE and flashed-to an Arduino Uno board using the IDE.--## Arduino-Makefile integration--The `Makefile` and `pre-build-hook.sh` show how to integrate arduino-copilot-with <https://github.com/sudar/Arduino-Makefile>. This automates generating-the C code, compiling that, and flashing it onto an Arduino Uno board,-with a single command--	make upload--Note that you will need to manually build the C code once, as shown above-, since the Arduino-Makefile expects to find a `.ino` file.--The path in the `Makefile` to `Arduino.mk` may need to be adjusted (the-default is the location where on a Debian system, `apt-get install-arduino-mk` will install it).
− examples/serialport/demo.hs
@@ -1,52 +0,0 @@-{-# LANGUAGE RebindableSyntax #-}-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE FlexibleContexts #-}--import Copilot.Arduino.Uno-import qualified Copilot.Arduino.Library.Serial as Serial-import qualified Copilot.Arduino.Library.Serial.XBee as XBee-import Control.Monad---- Should it use the onboard serial port?-useSerial :: Bool-useSerial = True---- Should it use the XBee wireless serial port?--- (it can use more than one serial port at the same time.)-useXBee :: Bool-useXBee = True--userIsTyping :: Behavior Int8 -> Behavior Bool-userIsTyping userinput = userinput /= constant Serial.noInput--getSerial :: Input o Int8 => Bool -> o -> Sketch (Behavior Int8)-getSerial True i = input' i (repeat Serial.noInput)-getSerial False _ = return (constant Serial.noInput)--main :: IO ()-main = arduino $ do-	when useSerial $ Serial.baud 9600-	when useXBee $ XBee.configure pin2 pin3 (XBee.Baud 9600)--	-- Measure the an analog input, and display it to the-	-- serial port. This is a handy demo because with nothing connected-	-- to a0, just moving your hand close to the arduino will probably-	-- cause some noise to be read.-	n <- input' a0 [1, 50, 11, 99, 120] :: Sketch (Behavior ADC)-	c <- input' millis [20, 60, 80, 100] :: Sketch (Behavior Word32)-	let msg = -		[ Serial.str "analog input:"-		, Serial.showFormatted n Serial.HEX-		, Serial.str " millis:"-		, Serial.show c-		, Serial.char '\n'-		]-	when useSerial $ Serial.device =: msg-	when useXBee $ XBee.device =: msg--	-- Light the led whenever the user types on the serial port.-	userinput <- getSerial useSerial Serial.device-	userinputxbee <- getSerial useXBee XBee.device-	led =: userIsTyping userinput || userIsTyping userinputxbee--	delay =: MilliSeconds (constant 100)
− examples/serialport/pre-build-hook.sh
@@ -1,2 +0,0 @@-#!/bin/sh-exec runghc demo.hs
− examples/waterheater/Makefile
@@ -1,127 +0,0 @@-# Arduino Make file. Refer to https://github.com/sudar/Arduino-Makefile-BOARD_TAG    = uno-include /usr/share/arduino/Arduino.mk--# --- leonardo (or pro micro w/leo bootloader)-#BOARD_TAG    = leonardo-#MONITOR_PORT = /dev/ttyACM0-#include /usr/share/arduino/Arduino.mk--# --- mega2560 ide 1.0-#BOARD_TAG    = mega2560-#ARDUINO_PORT = /dev/ttyACM0-#include /usr/share/arduino/Arduino.mk--# --- mega2560 ide 1.6-#BOARD_TAG    = mega-#BOARD_SUB    = atmega2560-#MONITOR_PORT = /dev/ttyACM0-#ARDUINO_DIR  = /where/you/installed/arduino-1.6.5-#include /usr/share/arduino/Arduino.mk--# --- nano ide 1.0-#BOARD_TAG    = nano328-#MONITOR_PORT = /dev/ttyUSB0-#include /usr/share/arduino/Arduino.mk--# --- nano ide 1.6-#BOARD_TAG   = nano-#BOARD_SUB   = atmega328-#ARDUINO_DIR = /where/you/installed/arduino-1.6.5-#include /usr/share/arduino/Arduino.mk--# --- pro mini-#BOARD_TAG    = pro5v328-#MONITOR_PORT = /dev/ttyUSB0-#include /usr/share/arduino/Arduino.mk--# --- sparkfun pro micro-#BOARD_TAG         = promicro16-#ALTERNATE_CORE    = promicro-#BOARDS_TXT        = $(HOME)/arduino/hardware/promicro/boards.txt-#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/promicro/bootloaders-#BOOTLOADER_PATH   = caterina-#BOOTLOADER_FILE   = Caterina-promicro16.hex-#ISP_PROG     	   = usbasp-#AVRDUDE_OPTS 	   = -v-#include /usr/share/arduino/Arduino.mk--# --- chipkit-#BOARD_TAG = mega_pic32-#MPIDE_DIR = /where/you/installed/mpide-0023-linux64-20130817-test-#include /usr/share/arduino/chipKIT.mk--# --- pinoccio-#BOARD_TAG         = pinoccio256-#ALTERNATE_CORE    = pinoccio-#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/pinoccio/bootloaders-#BOOTLOADER_PATH   = STK500RFR2/release_0.51-#BOOTLOADER_FILE   = boot_pinoccio.hex-#CFLAGS_STD        = -std=gnu99-#CXXFLAGS_STD      = -std=gnu++11-#include /usr/share/arduino/Arduino.mk--# --- fio-#BOARD_TAG = fio-#include /usr/share/arduino/Arduino.mk--# --- atmega-ng ide 1.6-#BOARD_TAG    = atmegang-#BOARD_SUB    = atmega168-#MONITOR_PORT = /dev/ttyACM0-#ARDUINO_DIR  = /where/you/installed/arduino-1.6.5-#include /usr/share/arduino/Arduino.mk--# --- arduino-tiny ide 1.0-#ISP_PROG     	    = usbasp-#BOARD_TAG          = attiny85at8-#ALTERNATE_CORE     = tiny-#ARDUINO_VAR_PATH   = $(HOME)/arduino/hardware/tiny/cores/tiny-#ARDUINO_CORE_PATH  = $(HOME)/arduino/hardware/tiny/cores/tiny-#AVRDUDE_OPTS 	    = -v-#include /usr/share/arduino/Arduino.mk--# --- arduino-tiny ide 1.6-#ISP_PROG       = usbasp-#BOARD_TAG      = attiny85at8-#ALTERNATE_CORE = tiny-#ARDUINO_DIR    = /where/you/installed/arduino-1.6.5-#include /usr/share/arduino/Arduino.mk--# --- damellis attiny ide 1.0-#ISP_PROG       = usbasp-#BOARD_TAG      = attiny85-#ALTERNATE_CORE = attiny-master-#AVRDUDE_OPTS   = -v-#include /usr/share/arduino/Arduino.mk--# --- damellis attiny ide 1.6-#ISP_PROG       = usbasp-#BOARD_TAG      = attiny-#BOARD_SUB      = attiny85-#ALTERNATE_CORE = attiny-#F_CPU          = 16000000L-#ARDUINO_DIR    = /where/you/installed/arduino-1.6.5-#include /usr/share/arduino/Arduino.mk--# --- teensy3-#BOARD_TAG 	 = teensy31-#ARDUINO_DIR = /where/you/installed/the/patched/teensy/arduino-1.0.6-#include /usr/share/arduino/Teensy.mk--# --- mighty 1284p-#BOARD_TAG         = mighty_opt-#BOARDS_TXT        = $(HOME)/arduino/hardware/mighty-1284p/boards.txt-#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/mighty-1284p/bootloaders-#BOOTLOADER_PATH   = optiboot-#BOOTLOADER_FILE   = optiboot_atmega1284p.hex-#ISP_PROG     	   = usbasp-#AVRDUDE_OPTS 	   = -v-#include /usr/share/arduino/Arduino.mk--# --- atmega328p on breadboard-#BOARD_TAG    = atmega328bb-#ISP_PROG     = usbasp-#AVRDUDE_OPTS = -v-#BOARDS_TXT   = $(HOME)/arduino/hardware/breadboard/boards.txt-#include /usr/share/arduino/Arduino.mk
− examples/waterheater/README
@@ -1,24 +0,0 @@-This is a demo program using arduino-copilot. --To build the C code:--	runghc demo.hs--The resulting `.ino` sketch can be loaded into the Arduino IDE and flashed-to an Arduino Uno board using the IDE.--## Arduino-Makefile integration--The `Makefile` and `pre-build-hook.sh` show how to integrate arduino-copilot-with <https://github.com/sudar/Arduino-Makefile>. This automates generating-the C code, compiling that, and flashing it onto an Arduino Uno board,-with a single command--	make upload--Note that you will need to manually build the C code once, as shown above-, since the Arduino-Makefile expects to find a `.ino` file.--The path in the `Makefile` to `Arduino.mk` may need to be adjusted (the-default is the location where on a Debian system, `apt-get install-arduino-mk` will install it).
− examples/waterheater/demo.hs
@@ -1,68 +0,0 @@-{- Controlling a hot water heater.- -- - This shows how additional types can be used to eg, keep track of units- - of measurement, while using the Copilot DSL.- -}--{-# LANGUAGE RebindableSyntax #-}--import Copilot.Arduino.Uno-import Data.List.NonEmpty (NonEmpty(..))-import qualified Data.List.NonEmpty as L---- For use as phantom types in TypedBehavior-data PSI-data Celsius--maxSafePSI :: TypedBehavior PSI Float-maxSafePSI = TypedBehavior (constant 45)--maxWaterTemp :: TypedBehavior Celsius Float-maxWaterTemp = TypedBehavior (constant 35)--warmWaterTemp :: TypedBehavior Celsius Float-warmWaterTemp = TypedBehavior (constant 30)--isSafeTemp :: TypedBehavior Celsius Float -> Behavior Bool-isSafeTemp t = liftB2 (<) t maxWaterTemp--isSafePSI :: TypedBehavior PSI Float -> Behavior Bool-isSafePSI p = liftB2 (<) p maxSafePSI---- Avoid explosions and scalding water.-isSafeToHeat :: TypedBehavior PSI Float -> NonEmpty (TypedBehavior Celsius Float) -> Behavior Bool-isSafeToHeat p cs = foldl (&&) (isSafePSI p) (L.map isSafeTemp cs)---- Convert a raw value read from an ADC into a temperature in Celsius.------ Assumes the ADC value is 0 at 0F, and 1024 at 200F.-adcToCelsius :: Behavior ADC -> TypedBehavior Celsius Float-adcToCelsius v = TypedBehavior $ v' * (constant 200 / constant 1024)-  where-	v' :: Behavior Float-	v' = unsafeCast v---- Convert a raw value read from an ADC into a PSI.------ Assumes the ADCI value is 0 at 0 PSI, and 1024 at 150 PSI.-adcToPSI :: Behavior ADC -> TypedBehavior PSI Float-adcToPSI v = TypedBehavior $ v' * (constant 150 / constant 1024)-  where-	v' :: Behavior Float-	v' = unsafeCast v--main :: IO ()-main = arduino $ do-	uppertemp <- adcToCelsius <$> input a1-	lowertemp <- adcToCelsius <$> input a2-	pressure <- adcToPSI <$> input a3-	let upperheatingelement = pin4-	let lowerheatingelement = pin5-	whenB (isSafeToHeat pressure (uppertemp :| [lowertemp])) $ do-		-- Run the upper heating element if the upper water temp is-		-- low, to provide hot water on demand. Run the lower-		-- heating element only when the upper is off.-		let runupper = liftB2 (<) uppertemp warmWaterTemp-		upperheatingelement =: runupper-		lowerheatingelement =: not runupper-	delay =: MilliSeconds 1000
− examples/waterheater/pre-build-hook.sh
@@ -1,2 +0,0 @@-#!/bin/sh-exec runghc demo.hs
+ src/Copilot/Arduino/Library/Random.hs view
@@ -0,0 +1,108 @@+-- | Random value library for arduino-copilot.+--+-- Here's an example that flashes the LED randomly.+--+-- > main :: IO ()+-- > main = arduino $ do+-- >	if firstIteration+-- > 		then randomSeedPin a0+-- > 		else do+-- > 			n <- input (random 10) :: Sketch (Behavior Word32)+-- > 			led =: (n >= 5)+--+-- The use of `firstIteration` makes the RNG be seeded in the first+-- iteration, and then random numbers are generated in subsequent+-- iterations. That's a typical pattern when using this module.++{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE RebindableSyntax #-}+{-# LANGUAGE TypeApplications #-}++module Copilot.Arduino.Library.Random (+	randomSeed,+	randomSeedPin,+	RandomSeed,+	RandomInput,+	random,+	randomR,+) where++import Copilot.Arduino hiding (show)+import Copilot.Arduino.Internals+import Control.Monad.Writer+import Data.Proxy+import Prelude ()+import qualified Prelude++-- | Use this to seed the RNG.+--+-- > randomSeed =: constant (1 :: Word8)+randomSeed :: RandomSeed+randomSeed = RandomSeed++data RandomSeed = RandomSeed++instance Output RandomSeed (Event () (Stream Word8)) where+	RandomSeed =: e = randomSeedWith e++-- Seeds with the first 8 bits read from the ADC, discarding the rest.+instance Output RandomSeed (Event () (Stream ADC)) where+	RandomSeed =: e = randomSeedWith e++randomSeedWith :: Typed a => Event p (Stream a) -> Sketch ()+randomSeedWith (Event n c) = do+		(f, triggername) <- defineTriggerAlias "randomSeed" mempty+		tell [(go triggername, \_ -> f)]+	  where+		go triggername tl = +			let c' = addTriggerLimit tl c+			in trigger triggername c' [arg n]++-- | Seed the RNG by reading from an analog input pin.+--+-- If the pin is left unconnected, noise will be read from it.+randomSeedPin :: IsAnalogInputPin t => Pin t -> Sketch ()+randomSeedPin p = do+	seed <- input p :: Sketch (Behavior ADC)+	randomSeed =: seed++data RandomInput = RandomInput Word32 Word32++-- | Generate a random number, up to but exclusive of an upper bound.+--+-- > n <- input (random 10)+random :: Word32 -> RandomInput+random hi = RandomInput 0 hi++-- | Generate a random number in the range (lo, hi). The number will be +-- @>= lo@ and @< hi@+--+-- > n <- input (randomR 5 10) :: Sketch (Behavior Word32)+randomR :: (Word32, Word32) -> RandomInput+randomR (lo, hi) = RandomInput lo hi++instance Input RandomInput Word32 where+	input' (RandomInput lo hi) interpretvalues = do+		i <- getUniqueId "random"+		let varname = uniqueName "randomval" i+		let word32 = showCType (Proxy @Word32)+		mkInput $ InputSource+			{ setupInput = []+			, defineVar = mkCChunk+				[ CLine $ word32 <> " " <> varname <> ";"+				]+			, inputPinmode = mempty+			, readInput = mkCChunk+				[ CLine $ varname <> " = random"+					<> "("+						<> Prelude.show lo+						<> ", " +						<> Prelude.show hi+					<> ");"]+			, inputStream = extern varname interpretvalues'+			}+  	  where+		interpretvalues'+			| null interpretvalues = Nothing+			| otherwise = Just interpretvalues
src/Copilot/Arduino/Main.hs view
@@ -7,7 +7,7 @@ import Copilot.Arduino.Internals import System.IO import System.Directory-import System.Posix.Temp (mkdtemp)+import System.IO.Temp (withSystemTempDirectory, createTempDirectory) import System.FilePath import System.Exit import Data.List (isInfixOf)@@ -83,18 +83,17 @@ 	-- And, the .c file includes a .h file that will make it fail to 	-- build when used in the .ino file, so that include has to be 	-- filtered out.-	toptmpdir <- getTemporaryDirectory-	mytmpdir <- mkdtemp (toptmpdir </> "copilot")-	reify spec >>= compile (mytmpdir </> "copilot")-	c <- lines <$> readFile (mytmpdir </> "copilot.c")-	let c' = filter (Prelude.not . isInfixOf "#include \"") c-	-- Use a name for the ino file that will let the Arduino IDE find it.-	d <- getCurrentDirectory-	let dirbase = takeFileName d-	writeFile (addExtension dirbase "ino") $ -		unlines $ map fromCLine $-			sketchFramework framework (map CLine c')-	removeDirectoryRecursive mytmpdir+	withSystemTempDirectory "copilot" $ \toptmpdir -> do+		mytmpdir <- createTempDirectory toptmpdir "copilot"+		reify spec >>= compile (mytmpdir </> "copilot")+		c <- lines <$> readFile (mytmpdir </> "copilot.c")+		let c' = filter (Prelude.not . isInfixOf "#include \"") c+		-- Use a name for the ino file that will let the Arduino IDE find it.+		d <- getCurrentDirectory+		let dirbase = takeFileName d+		writeFile (addExtension dirbase "ino") $ +			unlines $ map fromCLine $+				sketchFramework framework (map CLine c')  -- Makes an arduino sketch, using a Framework, and a list of lines of C -- code generated by Copilot.
test.hs view
@@ -1,24 +1,88 @@-{-# LANGUAGE LambdaCase #-}+-- The examples also constitute the test suite: Make sure they all compile.  import Control.Monad-import System.FilePath+import Control.Exception import System.Directory+import System.IO+import System.IO.Temp import System.Process import System.Exit +import qualified Examples.Blink.Demo+import qualified Examples.Button.Demo+import qualified Examples.EEPROM.Demo+import qualified Examples.EEPROMrange.Demo+import qualified Examples.Random.Demo+import qualified Examples.Robot.Demo+import qualified Examples.SerialPort.Demo+import qualified Examples.WaterHeater.Demo++data TestCase = TestCase+	{ desc :: String+	, builder :: IO ()+	, compileC :: Bool+	}++tests :: [TestCase]+tests =+	[ TestCase "Blink" Examples.Blink.Demo.main True+	, TestCase "Button" Examples.Button.Demo.main True+	-- EEPROM needs an additional arduino libraries installed to+	-- compile the generated C code, so that is skipped.+	, TestCase "EEPROM" Examples.EEPROM.Demo.main False+	, TestCase "EEPROMrange" Examples.EEPROMrange.Demo.main False+	, TestCase "Random" Examples.Random.Demo.main True+	, TestCase "Robot" Examples.Robot.Demo.main True+	, TestCase "SerialPort" Examples.SerialPort.Demo.main True+	, TestCase "WaterHeater" Examples.WaterHeater.Demo.main True+	]++main :: IO () main = do-	examples <- filterM doesFileExist-		=<< (map (</> "demo.hs") . map ("examples" </>))-		<$> getDirectoryContents "examples"-	if null examples-		then error "did not find any examples to test"-		else mapM_ shouldCompile examples+	canccompile <- doesFileExist arduinoMakefile+	unless canccompile $+		putStrLn $ "Skipping C compilation tests, did not find Arduino-Makefile installed in " ++ arduinoMakefile+	forM_ tests (runtest canccompile) -shouldCompile :: FilePath -> IO ()-shouldCompile f = do-	let p = (proc "runghc" ["-Wall", "-fno-warn-tabs", takeFileName f])-		{ cwd = Just (takeDirectory f) }-	readCreateProcessWithExitCode p "" >>= \case-		(ExitSuccess, "", "") -> return ()-		v -> error $ "runghc " ++ f ++-			" produced unexpected result: " ++ show v+runtest :: Bool -> TestCase -> IO ()+runtest canccompile t = withSystemTempDirectory "arduino-copilot-test" $ \tmpdir ->+	bracket (setup tmpdir) cleanup (const copilottest)+  where+	setup tmpdir = do+		setCurrentDirectory tmpdir+	cleanup _ = return ()+	+	copilottest = do+		putStr (desc t ++ " copilot ")+		hFlush stdout+		r <- try' (builder t)+		case r of+			Right () -> do+				putStrLn "OK"+				hFlush stdout+				ccompiletest+			Left ex ->+				 putStrLn ("FAILED: " ++ show ex)++	ccompiletest = when (canccompile && compileC t) $ do+		putStr (desc t ++ " C compilation ")+		writeFile "Makefile" $ unlines+			-- All examples currently use uno.+			[ "BOARD_TAG = uno"+			, "include " ++ arduinoMakefile+			]+		r <- readCreateProcessWithExitCode (proc "make" []) ""+		case r of+			(ExitSuccess, _, _) ->+				putStrLn "OK"+			(_, _out, err) -> do+				putStrLn "FAILED"+				putStrLn err++	try' :: IO () -> IO (Either SomeException ())+	try' = try++-- This is the location it's installed to on a Debian system+-- by apt-get install arduino-mk+arduinoMakefile :: FilePath+arduinoMakefile = "/usr/share/arduino/Arduino.mk"