AtomLED.hs

 

– Blink a LED on the Arduino Duemilanove using IDE libs from Atom/Haskell.– June 2010– By Lee Pike (remove spaces)– BSD3module

 Main

whereimport

 Language

.

Atom

import

 Data

.

Word

atomName=“AtomLED”– | Invoke the Atom compiler.main::

 IO ()

main=do(

schedule

,_,_,_,_)<-

 compile atomName defaults

{

cCode

=

 prePostCode

}

 blink
  putStrLn

$

 reportSchedule schedule

– | Takes a type and a variable name and initializes it.varInit::

 Type

->

 String

->

 String

->

 String

varInit

 t var val

=

 cType t

++” “++

 var

++” = “++

 val

++“;”prePostCode::[

Name

]->[

Name

]->[(

Name

,

 Type

)]->(

String

,

 String

)prePostCode___=(

unlines

[(

varInit Int16

"ledPin""13"),"void avr_blink(void);"],

 unlines

["void setup() {"," // initialize the digital pin as an output:"," pinMode(ledPin, OUTPUT);","}","","// set the LED on or off","void avr_blink() { digitalWrite(ledPin, state.AtomLED.on); }","","void loop() {"," "++

 atomName

++"();","}"])– How many cycles is a phase?ph::

 Int

ph=40000– Simple Atom to toggle an LED, leaving it on 8 times as long as it’s off.blink::

 Atom ()

blink=do

  on

<-

 bool

“on”

 True

  period ph

$

 phase

0$

 atom

“blinkOn”$do

    call

“avr_blink”

    on

<==

 not_

(

value on

)

  period ph

$

 phase

(

quot ph

8)$

 atom

“blinkOff”$do

    call

“avr_blink”

    on

<==

 not_

(

value on

)

One Response to “AtomLED.hs”

  1. Twinkle Twinkle Little Haskell « A Critical Systems Blog Says:

    [...] AtomLED.hs [...]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.

%d bloggers like this: