1&A      !"#$%&'()*+,-./0123456789:;<=>?@  experimentalerkokl@gmail.com Safe-InferredA3Delay (wait) for the given number of milli-seconds  NB. The B function is broken on Mac, see  /http://hackage.haskell.org/trac/ghc/ticket/7299  Until there'Ds a new GHC release that fixes this issue, we temporarily use system/sleep on Mac. CWA simple printer that can keep track of sequence numbers. Used for debugging purposes. D!Show a byte in a visible format. EShow a list of bytes F Show a number as a binary value G Turn a lo/9hi encoded Arduino string constant into a Haskell string ACDEFGACDEFGACDEFG  experimentalerkokl@gmail.comNoneoHSys-ex commands, see: http: firmata.orgwikiProtocol#Sysex_Message_Format I0x7F& MIDI Reserved for realtime messages J0x7E* MIDI Reserved for non-realtime messages K0x7A sampling interval L0x79* report name and version of the firmware M0x78D Configure special I2C settings such as power pins and delay times N0x77 I2C reply messages from an I/O board to a host O0x76* I2C request messages from a host to an I/O board P0x75 shiftOut config/data message (34 bits) Q0x71) a string message with 14-bits per char R0x70* set max angle, minPulse, maxPulse, freq S0x6F, analog write (PWM, Servo, etc) to any pin T0x6E reply with a pin's current mode and value U0x6D ask for a pin's current mode and value V0x6C, reply with supported modes and resolution W0x6B5 ask for supported modes and resolution of all pins X0x6A reply with mapping info Y0x69+ ask for mapping of analog to pin numbers Z0x00F 2nd SysEx data byte is a chip-specific command (AVR, PIC, TI, etc). [Firmata commands, see: http: firmata.orgwikiProtocol#Message_Types \ 0xFF] 0xF9^ 0xF7_ 0xF4` 0xF0a0xD0 port b0xC0 pin c0x90 port d0xE0 pin The Arduino monad. eState of the computation fCurrent debugging routine g7Clean-up and quit with a hopefully informative message h$Serial port we are communicating on i8The ID of the board (as identified by the Board itself) jCurrent state of the board k!Incoming messages from the board lCapabilities of the board mThreadId of the listener nState of the board oCapabilities of the board p Which analog pins are reporting q!Which digital pins are reporting rFor-each pin, store its data s;Semaphore list to wake-up upon receiving a digital message tLCD's attached to the board u4State of the LCD, a mere 8-bit word for the Hitachi vDisplay mode (leftrightscrolling etc.) wDisplay control (blink onoff, display on off etc.) x5Count of custom created glyphs (typically at most 8) yActual controller Hitachi LCD controller: See:  ;http://en.wikipedia.org/wiki/Hitachi_HD44780_LCD_controller. ^ We model only the 4-bit variant, with RS and EN lines only. (The most common Arduino usage.)  The data sheet can be seen at:  4http://lcd-linux.sourceforge.net/pdfdocs/hd44780.pdf.  Hitachi pin  4: Register-select  Hitachi pin  6 : Enable  Hitachi pin 11 : Data line 4  Hitachi pin 12 : Data line 5  Hitachi pin 13 : Data line 6  Hitachi pin 14 : Data line 7 *Number of rows (typically 1 or 2, upto 4) -Number of cols (typically 16 or 20, upto 40) "Set to True if 5x10 dots are used zLCD's connected to the board {Data associated with a pin |2What the board is capable of and current settings }Capabilities of a pin ~#Resolution, as referred to in http: firmata.orgwikiProtocol#Capability_Query I TODO: Not quite sure how this is used, so merely keep it as a Word8 now )A response, as returned from the Arduino *Represents messages currently unsupported Status of an analog pin Status of a port Analog pin mappings Capabilities report Firmware version (maj/min and indentifier A request, as sent to Arduino Set the sampling interval #Set the values on a port digitally "Analog report values on pin enable/disable $Digital report values on port enable/disable Set the mode on a pin !Query the mapping of analog pins $Query the capabilities of the board $Query the Firmata version installed Send system reset The mode for a pin. *I2C (Inter-Integrated-Circuit) connection Shift controller Servo Motor controller %PWM (Pulse-Width-Modulation) output  Analog input Digital output Digital input A pin on the Arduino The pin number A port (containing 8 pins) The port number *Declare a pin on the board by its number. 2On the Arduino, pins are grouped into banks of 8. @ Given a pin, this function determines which port it belongs to 2On the Arduino, pins are grouped into banks of 8. M Given a pin, this function determines which index it belongs to in its port 2Debugging only: print the given string on stdout. 6Bailing out: print the given string on stdout and die #Which modes does this pin support? Current state of the pin <Given a pin, collect the digital value corresponding to the E port it belongs to, where the new value of the current pin is given  The result is two bytes: " First lsb: pins 0-6 on the port ' * Second msb: pins 7-13 on the port HIn particular, the result is suitable to be sent with a digital message -Keep track of listeners on a digital message 'Compute the numeric value of a command $Convert a byte to a Firmata command  Convert a H to a byte Convert a byte into a H Keep track of pin-mode changes iA mode was removed from this pin, update internal state and determine any necessary actions to remove it 5Depending on a mode-set call, determine what further - actions should be executed, such as enabling disabling pinport reporting HIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxy z{|}~ {HIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxy z{|}~ %HZYXWVUTSRQPONMLKJI[ dcba`_^]\e fghijklmnopqrstuvwxy  z{|}~    experimentalerkokl@gmail.comNone.Wrap a sys-ex message to be sent to the board Construct a non sys-ex message APackage a request as a sequence of bytes to be sent to the board  using the Firmata protocol. Unpackage a SysEx response Unpackage a Non-SysEx response   experimentalerkokl@gmail.comNone.Run the Haskell program to control the board: @ The file path argument should point to the device file that is " associated with the board. (COM1 on Windows,  '/dev/cu.usbmodemfd131' on Mac, etc.) ; The boolean argument controls verbosity. It should remain  5 unless you have communication issues. The print-out D is typically less-than-useful, but it might point to the root  cause of the problem. See &System.Hardware.Arduino.Examples.Blink for a simple example. Send down a request. 4Receive a sys-ex response. This is a blocking call. VReceive a sys-ex response with time-out. This is a blocking call, and will wait until 8 either the time-out expires or the message is received VStart a thread to listen to the board and populate the channel with incoming queries. LInitialize our board, get capabilities, etc. Returns True if initialization  went OK, False if not. If !, debugging info will be printed Path to the USB port &The Haskell controller program to run   experimentalerkokl@gmail.comNone HRetrieve the Firmata firmware version running on the Arduino. The first I component is the major, second is the minor. The final value is a human / readable identifier for the particular board. 9Delay the computaton for a given number of milli-seconds .Set the mode on a particular pin on the board (Set or clear a digital pin on the board Turn on/.off internal pull-up resistor on an input pin PRead the value of a pin in digital mode; this is a non-blocking call, returning $ the current value immediately. See ' for a version that waits for a change  in the pin first. PWait for a change in the value of the digital input pin. Returns the new value. D Note that this is a blocking call. For a non-blocking version, see , which returns the current  value of a pin immediately. ^Wait for a change in any of the given pins. Once a change is detected, all the new values are  returned. Similar to >, but is useful when we are watching multiple digital inputs. \Wait for any of the given pins to go from low to high. If all of the pins are high to start d with, then we first wait for one of them to go low, and then wait for one of them to go back high.  Returns the new values. [Wait for any of the given pins to go from high to low. If all of the pins are low to start d with, then we first wait for one of them to go high, and then wait for one of them to go back low.  Returns the new values. :A utility function, waits for any change on any given pin ( and returns both old and new values. It's guaranteed that 3 at least one returned pair have differing values. !QRead the value of a pin in analog mode; this is a non-blocking call, immediately . returning the last sampled value. It returns 0 if the voltage on the pin  is 0V, and 1023$ if it is 5V, properly scaled. (See " for  sampling frequency.) "kSet the analog sampling interval, in milliseconds. Arduino uses a default of 19ms to sample analog and I2C [ signals, which is fine for many applications, but can be modified if needed. The argument  should be a number between 10 and 16384; 10: being the minumum sampling interval supported by Arduino  and 16383^ being the largest value we can represent in 14 bits that this message can handle. (Note that ! the largest value is just about 16? seconds, which is plenty infrequent for all practical needs.)  !"  !"  !" experimentalerkokl@gmail.comNone+#1An abstract symbol type for user created symbols +Various control masks for the Hitachi44780 bit 1 Controls left/right entry mode bit 0 Controls left/ right scroll bit 2 Controls whether display is on bit 1 Controls whether cursor is on bit 0 Controls whether cursor blinks Commands understood by Hitachi !Convert a command to a data-word +Initialize the LCD. Follows the data sheet  4http://lcd-linux.sourceforge.net/pdfdocs/hd44780.pdf,  page 46; figure 24. +Get the controller associated with the LCD %Send a command to the LCD controller &Send 4-bit data to the LCD controller ?By controlling the enable-pin, indicate to the controller that & the data is ready for it to process. Transmit data down to the LCD JHelper function to simplify library programming, not exposed to the user. $`Register an LCD controller. When registration is complete, the LCD will be initialized so that:  Set display ON (Use 0 / / to change.)  Set cursor OFF (Use . / - to change.)  Set blink OFF (Use , / + to change.)  Clear display (Use & to clear, % to display text.) # Set entry mode left to write (Use 1 / 2 to control.)  Set autoscrolling OFF (Use 4 / 3 to control.) ( Put the cursor into home position (Use ( or ' to move around.) %9Write a string on the LCD at the current cursor position &Clear the LCD '!Send the cursor to home position (QSet the cursor location. The pair of arguments is the new column and row numbers  respectively: W The first value is the column, the second is the row. (This is counter-intuitive, but b is in line with what the standard Arduino programmers do, so we follow the same convention.) 3 Counting starts at 0 (both for column and row no) \ If the new location is out-of-bounds of your LCD, we will put it the cursor to the closest # possible location on the LCD. )uScroll the display to the left by 1 character. Project idea: Using a tilt sensor, scroll the contents of the display  left/right depending on the tilt. */Scroll the display to the right by 1 character 3Display characteristics helper, set the new control/mode and send * appropriate commands if anything changed  Update the display control word Update the display mode word %Convert the mask value to the bit no Clear by the mask Set by the mask +Do not blink the cursor ,Blink the cursor -NHide the cursor. Note that a blinking cursor cannot be hidden, you must first  turn off blinking. .Show the cursor /NTurn the display off. Note that turning the display off does not mean you are O powering it down. It simply means that the characters will not be shown until  you turn it back on using 0. (Also, the contents will not be L forgotten when you call this function.) Therefore, this function is useful . for temporarily hiding the display contents. 0Turn the display on 1%Set writing direction: Left to Right 2%Set writing direction: Right to Left 3WTurn on auto-scrolling. In the context of the Hitachi44780 controller, this means that W each time a letter is added, all the text is moved one space to the left. This can be  confusing at first: It does not2 mean that your strings will continuously scroll: P It just means that if you write a string whose length exceeds the column-count  of your LCD, then you'Dll see the tail-end of it. (Of course, this will create a scrolling @ effect as the string is being printed character by character.) ]Having said that, it is easy to program a scrolling string program: Simply write your string  by calling %, and then use the ) and * functions 4 with appropriate delays to simulate the scrolling. 4.Turn off auto-scrolling. See the comments for 3 for details. When turned & off (which is the default), you will not4 see the characters at the end of your strings that  do not fit into the display. 5!Flash contents of the LCD screen 6@Create a custom symbol for later display. Note that controllers E have limited capability for such symbols, typically storing no more H than 8. The behavior is undefined if you create more symbols than your  LCD can handle. IThe input is a simple description of the glyph, as a list of precisely 8 G strings, each of which must have 5 characters. Any space character is L interpreted as a empty pixel, any non-space is a full pixel, corresponding K to the pixel in the 5x8 characters we have on the LCD. For instance, here's ! a happy-face glyph you can use:   [ " "  , "@ @"  , " "  , " "  , "@ @"  , " @@@ "  , " "  , " "  ]  7/Display a user created symbol on the LCD. (See 6 for details.) 8\Access an internally stored symbol, one that is not available via its ASCII equivalent. See , the Hitachi datasheet for possible values:  4http://lcd-linux.sourceforge.net/pdfdocs/hd44780.pdf, Table 4 on page 17. 0For instance, to access the symbol right-arrow: b Locate it in the above table: Right-arrow is at the second-to-last row, 7th character from left.  Check the upper/Ghigher bits as specified in the table: For Right-arrow, upper bits are 0111 and the  lower bits are 1110; which gives us the code 01111110, or 0x7E. 0 So, right-arrow can be accessed by symbol code 8 0x7E, which will give us a # value  that can be passed to the 7* function. The code would look like this: +lcdWriteSymbol lcd (lcdInternalSymbol 0x7E). 6#$%&'()*+,-./012345 Flash count  Delay amount (in milli-seconds) 678! #$%&'()*+,-./012345678! $&%'(34)*12,+.-0/#8765&# $%&'()*+,-./012345678 experimentalerkokl@gmail.comNone  !"   "! experimentalerkokl@gmail.comNone9@Read the value of an analog input line. We will print the value A on the screen, and also blink a led on the Arduino based on the 5 value. The smaller the value, the faster the blink. DThe circuit simply has a 10K potentiometer between 5V and GND, with H the wiper line connected to analog input 3. We also have a led between  pin 13 and GND.  nhttp://github.com/LeventErkok/hArduino/raw/master/System/Hardware/Arduino/SamplePrograms/Schematics/Analog.png 9999 experimentalerkokl@gmail.comNone:=Blink the led connected to port 13 on the Arduino UNO board. NNote that you do not need any other components to run this example: Just hook Q up your Arduino to the computer and make sure StandardFirmata is running on it. N However, you can connect a LED between Pin13 and GND if you want to blink an * external led as well, as depicted below:  mhttp://github.com/LeventErkok/hArduino/raw/master/System/Hardware/Arduino/SamplePrograms/Schematics/Blink.png :::: experimentalerkokl@gmail.comNone;5Read the value of a push-button (NO - normally open) ? connected to input pin 2 on the Arduino. We will continuously 4 monitor and print the value as it changes. Also, we'll turn 2 the led on pin 13 on when the switch is pressed. @The wiring is straightforward: Simply put a push-button between 5 digital input 2 and +5V, guarded by a 10K resistor:  nhttp://github.com/LeventErkok/hArduino/raw/master/System/Hardware/Arduino/SamplePrograms/Schematics/Button.png ;;;; experimentalerkokl@gmail.comNone<ITwo push-button switches, controlling a counter value. We will increment  the counter if the first one (bUp-) is pressed, and decrement the value if the  second one (bDownA) is pressed. We also have a led connected to pin 13 (either use S the internal or connect an external one), that we light up when the counter value  is 0. KWiring is very simple: Up-button connected to pin 4, Down-button connected  to pin 2, and a led on pin 13.  ohttp://github.com/LeventErkok/hArduino/raw/master/System/Hardware/Arduino/SamplePrograms/Schematics/Counter.png <<<< experimentalerkokl@gmail.comNone=,Connections for a basic hitachi controller.  See  ;http://en.wikipedia.org/wiki/Hitachi_HD44780_LCD_controller for G pin layout. For this demo, simply connect the LCD pins to the Arduino  as follows:   LCD pin 01 to GND  LCD pin 02 to +5V  LCD pin 03 to a 10K potentiometer's viper  LCD pin 04 to Arduino pin 12  LCD pin 05 to GND  LCD pin 06 to Arduino pin 11  LCD pin 11 to Arduino pin 5  LCD pin 12 to Arduino pin 4  LCD pin 13 to Arduino pin 3  LCD pin 14 to Arduino pin 2  [If backlight is needed] LCD pin 15 to +5V  [If backlight is needed] LCD pin 16 to GND via 220ohm resistor  khttp://github.com/LeventErkok/hArduino/raw/master/System/Hardware/Arduino/SamplePrograms/Schematics/LCD.png >The happy glyph. See 6( for details on how to create new ones. ?The sad glyph. See 6( for details on how to create new ones. @=Access the LCD connected to Arduino, making it show messages J we read from the user and demonstrate other LCD control features offered  by hArduino. =>?@=>?@=>?@=>?@                     ! " # $ % & ' ( ) * + , - . /0123456789:;<=>?@ABCDEFGHIJKLM%NOPQRSTU V W X Y Z [ \ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~                           s |     !    0 hArduino-0.3System.Hardware.ArduinoSystem.Hardware.Arduino.LCD-System.Hardware.Arduino.SamplePrograms.Analog,System.Hardware.Arduino.SamplePrograms.Blink-System.Hardware.Arduino.SamplePrograms.Button.System.Hardware.Arduino.SamplePrograms.Counter*System.Hardware.Arduino.SamplePrograms.LCDSystem.Hardware.Arduino.UtilsSystem.Hardware.Arduino.Data System.Hardware.Arduino.ProtocolSystem.Hardware.Arduino.CommSystem.Hardware.Arduino.FirmataArduino LCDController Hitachi44780lcdRSlcdENlcdD4lcdD5lcdD6lcdD7lcdRowslcdCols dotMode5x10PinModeI2CSHIFTSERVOPWMANALOGOUTPUTINPUTPinpin withArduino queryFirmwaredelay setPinMode digitalWritepullUpResistor digitalReadwaitForwaitAny waitAnyHigh waitAnyLow analogReadsetAnalogSamplingInterval LCDSymbol lcdRegisterlcdWritelcdClearlcdHome lcdSetCursorlcdScrollDisplayLeftlcdScrollDisplayRight lcdBlinkOff lcdBlinkOn lcdCursorOff lcdCursorOn lcdDisplayOff lcdDisplayOnlcdLeftToRightlcdRightToLeftlcdAutoScrollOnlcdAutoScrollOfflcdFlashlcdCreateSymbollcdWriteSymbollcdInternalSymbol analogValblinkbuttoncounterhitachihappysadlcdDemobase GHC.Conc.IO threadDelaymkDebugPrintershowByte showByteListshowBin getStringSysExCmdSYSEX_REALTIMESYSEX_NON_REALTIMESAMPLING_INTERVALREPORT_FIRMWARE I2C_CONFIG I2C_REPLY I2C_REQUEST SHIFT_DATA STRING_DATA SERVO_CONFIGEXTENDED_ANALOGPIN_STATE_RESPONSEPIN_STATE_QUERYCAPABILITY_RESPONSECAPABILITY_QUERYANALOG_MAPPING_RESPONSEANALOG_MAPPING_QUERYRESERVED_COMMAND FirmataCmd SYSTEM_RESETPROTOCOL_VERSION END_SYSEX SET_PIN_MODE START_SYSEXREPORT_DIGITAL_PORTREPORT_ANALOG_PINDIGITAL_MESSAGEANALOG_MESSAGE ArduinoStatemessagebailOutport firmataID boardState deviceChannel capabilities listenerTid BoardStateboardCapabilitiesanalogReportingPinsdigitalReportingPins pinStatesdigitalWakeUpQueuelcdsLCDDatalcdDisplayModelcdDisplayControl lcdGlyphCount lcdControllerLCDPinDataBoardCapabilitiesPinCapabilities ResolutionResponse Unimplemented AnalogMessageDigitalMessage AnalogMapping CapabilitiesFirmwareRequestSamplingIntervalDigitalPortWrite AnalogReport DigitalReport SetPinModeAnalogMappingQueryCapabilityQuery QueryFirmware SystemResetpinNoPortportNopinPort pinPortIndexdebugdie getPinModes getPinDatacomputePortData digitalWakeUp firmataCmdVal getFirmataCmd sysExCmdValgetSysExCommandregisterPinModegetRemovalActionsgetModeActionspinModepinValue$fShowBoardCapabilities$fShowResponse $fShowPin $fShowPortsysExnonSysExpackageunpackageSysExunpackageNonSysExgetCapabilitiesghc-prim GHC.TypesFalsesendrecv recvTimeOut setupListener initializeTrue waitGenericHitachi44780Mask LCD_ENTRYLEFTLCD_ENTRYSHIFTINCREMENT LCD_DISPLAYON LCD_CURSORON LCD_BLINKONCmd getCmdValinitLCD getControllersendCmdsendData pulseEnabletransmitwithLCDupdateDisplayDataupdateDisplayControlupdateDisplayModemaskBit clearMasksetMaskLCD_SETCGRAMADDRLCD_CURSORSHIFTLCD_SETDDRAMADDRLCD_RETURNHOMELCD_ENTRYMODESETLCD_CLEARDISPLAYLCD_DISPLAYCONTROLLCD_FUNCTIONSETLCD_INITIALIZE_ENDLCD_INITIALIZE