Last active
January 1, 2016 13:29
-
-
Save puffnfresh/8151958 to your computer and use it in GitHub Desktop.
Blink Arduino via Atom: http://hackage.haskell.org/package/atom-1.0.12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Blink (main) where | |
import Language.Atom | |
name :: Name | |
name = "blink" | |
timeout :: Int | |
timeout = 40000 | |
blink :: Atom () | |
blink = do | |
on <- bool "on" True | |
period timeout $ atom "blinkOn" $ do | |
call "avr_blink" | |
on <== not_ (value on) | |
header :: String | |
header = unlines [ | |
"int16_t ledPin = 13;", | |
"void avr_blink(void);" | |
] | |
footer :: String | |
footer = unlines [ | |
"void setup() {", | |
" pinMode(ledPin, OUTPUT);", | |
"}", | |
"", | |
"void avr_blink() {", | |
" digitalWrite(ledPin, state." ++ name ++ ".on);", | |
"}", | |
"", | |
"void loop() {", | |
" " ++ name ++ "();", | |
"}" | |
] | |
prePostCode :: [Name] -> [Name] -> [(Name, Type)] -> (String, String) | |
prePostCode _ _ _ = (header, footer) | |
main :: IO () | |
main = do | |
(schedule, _, _, _, _) <- compile name defaults { cCode = prePostCode } blink | |
putStrLn $ reportSchedule schedule |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment