-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | Control your Arduino board from Haskell.
--
-- Control Arduino from Haskell, using the Firmata protocol.
--
-- The hArduino library allows construction of Haskell programs that
-- control Arduino boards that are running the (freely available) Firmata
-- program. Note that hArduino does not allow you to run arbitrary
-- Haskell code on the Arduino! It simply allows you to control a board
-- from Haskell, where you can exchange information with the board,
-- send/receive commands from other peripherals connected, etc.
--
-- A short (4m29s) video of the blinking example:
-- http://www.youtube.com/watch?v=PPa3im44t2g
--
-- hArduino is work-in-progress. Comments, bug-reports, and patches are
-- welcome.
@package hArduino
@version 0.3
-- | LCD (Liquid Crystal Display) parts supported by hArduino. The Haskell
-- code below has partly been implemented following the Arduino
-- LiquidCrystal project source code:
-- http://code.google.com/p/arduino/source/browse/trunk/libraries/LiquidCrystal/
--
-- The Hitachi44780 data sheet is at:
-- http://lcd-linux.sourceforge.net/pdfdocs/hd44780.pdf
--
-- For an example program using this library, see
-- System.Hardware.Arduino.SamplePrograms.LCD.
module System.Hardware.Arduino.LCD
-- | 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:
-- http://lcd-linux.sourceforge.net/pdfdocs/hd44780.pdf.
data LCDController
Hitachi44780 :: Pin -> Pin -> Pin -> Pin -> Pin -> Pin -> Int -> Int -> Bool -> LCDController
-- | Hitachi pin 4: Register-select
lcdRS :: LCDController -> Pin
-- | Hitachi pin 6: Enable
lcdEN :: LCDController -> Pin
-- | Hitachi pin 11: Data line 4
lcdD4 :: LCDController -> Pin
-- | Hitachi pin 12: Data line 5
lcdD5 :: LCDController -> Pin
-- | Hitachi pin 13: Data line 6
lcdD6 :: LCDController -> Pin
-- | Hitachi pin 14: Data line 7
lcdD7 :: LCDController -> Pin
-- | Number of rows (typically 1 or 2, upto 4)
lcdRows :: LCDController -> Int
-- | Number of cols (typically 16 or 20, upto 40)
lcdCols :: LCDController -> Int
-- | Set to True if 5x10 dots are used
dotMode5x10 :: LCDController -> Bool
-- | Register an LCD controller. When registration is complete, the LCD
-- will be initialized so that:
--
--
lcdRegister :: LCDController -> Arduino LCD
-- | Clear the LCD
lcdClear :: LCD -> Arduino ()
-- | Write a string on the LCD at the current cursor position
lcdWrite :: LCD -> String -> Arduino ()
-- | Send the cursor to home position
lcdHome :: LCD -> Arduino ()
-- | Set the cursor location. The pair of arguments is the new column and
-- row numbers respectively:
--
--
-- - The first value is the column, the second is the row. (This is
-- counter-intuitive, but is in line with what the standard Arduino
-- programmers do, so we follow the same convention.)
-- - 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.
--
lcdSetCursor :: LCD -> (Int, Int) -> Arduino ()
-- | Turn on auto-scrolling. In the context of the Hitachi44780 controller,
-- this means that each time a letter is added, all the text is moved one
-- space to the left. This can be confusing at first: It does not
-- mean that your strings will continuously scroll: It just means that if
-- you write a string whose length exceeds the column-count of your LCD,
-- then you'll 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 lcdWrite, and then use the
-- lcdScrollDisplayLeft and lcdScrollDisplayRight functions
-- with appropriate delays to simulate the scrolling.
lcdAutoScrollOn :: LCD -> Arduino ()
-- | Turn off auto-scrolling. See the comments for lcdAutoScrollOn
-- for details. When turned off (which is the default), you will
-- not see the characters at the end of your strings that do not
-- fit into the display.
lcdAutoScrollOff :: LCD -> Arduino ()
-- | Scroll 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.
lcdScrollDisplayLeft :: LCD -> Arduino ()
-- | Scroll the display to the right by 1 character
lcdScrollDisplayRight :: LCD -> Arduino ()
-- | Set writing direction: Left to Right
lcdLeftToRight :: LCD -> Arduino ()
-- | Set writing direction: Right to Left
lcdRightToLeft :: LCD -> Arduino ()
-- | Blink the cursor
lcdBlinkOn :: LCD -> Arduino ()
-- | Do not blink the cursor
lcdBlinkOff :: LCD -> Arduino ()
-- | Show the cursor
lcdCursorOn :: LCD -> Arduino ()
-- | Hide the cursor. Note that a blinking cursor cannot be hidden, you
-- must first turn off blinking.
lcdCursorOff :: LCD -> Arduino ()
-- | Turn the display on
lcdDisplayOn :: LCD -> Arduino ()
-- | Turn the display off. Note that turning the display off does not mean
-- you are powering it down. It simply means that the characters will not
-- be shown until you turn it back on using lcdDisplayOn. (Also,
-- the contents will not be forgotten when you call this
-- function.) Therefore, this function is useful for temporarily hiding
-- the display contents.
lcdDisplayOff :: LCD -> Arduino ()
-- | An abstract symbol type for user created symbols
data LCDSymbol
-- | Access an internally stored symbol, one that is not available via its
-- ASCII equivalent. See the Hitachi datasheet for possible values:
-- http://lcd-linux.sourceforge.net/pdfdocs/hd44780.pdf, Table 4
-- on page 17.
--
-- For instance, to access the symbol right-arrow:
--
--
-- - Locate it in the above table: Right-arrow is at the second-to-last
-- row, 7th character from left.
-- - Check the upper/higher 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.
-- - So, right-arrow can be accessed by symbol code
-- lcdInternalSymbol 0x7E, which will give us a
-- LCDSymbol value that can be passed to the lcdWriteSymbol
-- function. The code would look like this: lcdWriteSymbol lcd
-- (lcdInternalSymbol 0x7E).
--
lcdInternalSymbol :: Word8 -> LCDSymbol
-- | Display a user created symbol on the LCD. (See lcdCreateSymbol
-- for details.)
lcdWriteSymbol :: LCD -> LCDSymbol -> Arduino ()
-- | Create a custom symbol for later display. Note that controllers have
-- limited capability for such symbols, typically storing no more than 8.
-- The behavior is undefined if you create more symbols than your LCD can
-- handle.
--
-- The input is a simple description of the glyph, as a list of precisely
-- 8 strings, each of which must have 5 characters. Any space character
-- is interpreted as a empty pixel, any non-space is a full pixel,
-- corresponding to the pixel in the 5x8 characters we have on the LCD.
-- For instance, here's a happy-face glyph you can use:
--
--
-- [ " "
-- , "@ @"
-- , " "
-- , " "
-- , "@ @"
-- , " @@@ "
-- , " "
-- , " "
-- ]
--
lcdCreateSymbol :: LCD -> [String] -> Arduino LCDSymbol
-- | Flash contents of the LCD screen
lcdFlash :: LCD -> Int -> Int -> Arduino ()
-- | (The hArduino library is hosted at
-- http://leventerkok.github.com/hArduino/. Comments, bug reports,
-- and patches are always welcome.)
--
-- hArduino: Control Arduino from Haskell, using the Firmata protocol.
--
-- The hArduino library allows construction of Haskell programs that
-- control Arduino boards that are running the (freely available) Firmata
-- program. Note that hArduino does not allow you to run arbitrary
-- Haskell code on the Arduino! It simply allows you to control a board
-- from Haskell, where you can exchange information with the board,
-- send/receive commands from other peripherals connected, etc.
--
-- See http://www.youtube.com/watch?v=PPa3im44t2g for a short
-- video (4m29s) of the blink example.
module System.Hardware.Arduino
-- | 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
-- False unless you have communication issues. The print-out 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.
withArduino :: Bool -> FilePath -> Arduino () -> IO ()
-- | The Arduino monad.
data Arduino a
-- | Retrieve the Firmata firmware version running on the Arduino. The
-- first component is the major, second is the minor. The final value is
-- a human readable identifier for the particular board.
queryFirmware :: Arduino (Word8, Word8, String)
-- | Declare a pin on the board by its number.
pin :: Word8 -> Pin
-- | A pin on the Arduino
data Pin
-- | The mode for a pin.
data PinMode
-- | Digital input
INPUT :: PinMode
-- | Digital output
OUTPUT :: PinMode
-- | Analog input
ANALOG :: PinMode
-- | PWM (Pulse-Width-Modulation) output
PWM :: PinMode
-- | Servo Motor controller
SERVO :: PinMode
-- | Shift controller
SHIFT :: PinMode
-- | I2C (Inter-Integrated-Circuit) connection
I2C :: PinMode
-- | Set the mode on a particular pin on the board
setPinMode :: Pin -> PinMode -> Arduino ()
-- | Set or clear a digital pin on the board
digitalWrite :: Pin -> Bool -> Arduino ()
-- | Read the value of a pin in digital mode; this is a non-blocking call,
-- returning the current value immediately. See waitFor for a
-- version that waits for a change in the pin first.
digitalRead :: Pin -> Arduino Bool
-- | Turn on/off internal pull-up resistor on an input pin
pullUpResistor :: Pin -> Bool -> Arduino ()
-- | Wait for a change in the value of the digital input pin. Returns the
-- new value. Note that this is a blocking call. For a non-blocking
-- version, see digitalRead, which returns the current value of a
-- pin immediately.
waitFor :: Pin -> Arduino Bool
-- | Wait for a change in any of the given pins. Once a change is detected,
-- all the new values are returned. Similar to waitFor, but is
-- useful when we are watching multiple digital inputs.
waitAny :: [Pin] -> Arduino [Bool]
-- | Wait for any of the given pins to go from low to high. If all of the
-- pins are high to start 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.
waitAnyHigh :: [Pin] -> Arduino [Bool]
-- | Wait for any of the given pins to go from high to low. If all of the
-- pins are low to start 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.
waitAnyLow :: [Pin] -> Arduino [Bool]
-- | Set 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.)
setAnalogSamplingInterval :: Int -> Arduino ()
-- | Read 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 setAnalogSamplingInterval for sampling frequency.)
analogRead :: Pin -> Arduino Int
-- | Delay the computaton for a given number of milli-seconds
delay :: Int -> Arduino ()
-- | Reads the value of an analog input, controlled by a 10K potentiometer.
module System.Hardware.Arduino.SamplePrograms.Analog
-- | Read the value of an analog input line. We will print the value on the
-- screen, and also blink a led on the Arduino based on the value. The
-- smaller the value, the faster the blink.
--
-- The circuit simply has a 10K potentiometer between 5V and GND, with
-- the wiper line connected to analog input 3. We also have a led between
-- pin 13 and GND.
--
analogVal :: IO ()
-- | The hello world of the arduino world, blinking the led.
module System.Hardware.Arduino.SamplePrograms.Blink
-- | Blink the led connected to port 13 on the Arduino UNO board.
--
-- Note that you do not need any other components to run this example:
-- Just hook up your Arduino to the computer and make sure
-- StandardFirmata is running on it. However, you can connect a LED
-- between Pin13 and GND if you want to blink an external led as well, as
-- depicted below:
--
blink :: IO ()
-- | Reads the value of a push-button and displays it's status continuously
-- on the computer screen and by lighting a led on the Arduino as long as
-- the button is pressed.
module System.Hardware.Arduino.SamplePrograms.Button
-- | Read the value of a push-button (NO - normally open) connected to
-- input pin 2 on the Arduino. We will continuously monitor and print the
-- value as it changes. Also, we'll turn the led on pin 13 on when the
-- switch is pressed.
--
-- The wiring is straightforward: Simply put a push-button between
-- digital input 2 and +5V, guarded by a 10K resistor:
--
button :: IO ()
-- | Demonstrates using two push-buttons to count up and down.
module System.Hardware.Arduino.SamplePrograms.Counter
-- | Two 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 (bDown) is pressed. We
-- also have a led connected to pin 13 (either use the internal or
-- connect an external one), that we light up when the counter value is
-- 0.
--
-- Wiring is very simple: Up-button connected to pin 4, Down-button
-- connected to pin 2, and a led on pin 13.
--
counter :: IO ()
-- | Basic demo of an Hitachi HD44780 LCD
module System.Hardware.Arduino.SamplePrograms.LCD
-- | Connections for a basic hitachi controller. See
-- http://en.wikipedia.org/wiki/Hitachi_HD44780_LCD_controller for
-- 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
--
--
hitachi :: LCDController
-- | The happy glyph. See lcdCreateSymbol for details on how to
-- create new ones.
happy :: [String]
-- | The sad glyph. See lcdCreateSymbol for details on how to create
-- new ones.
sad :: [String]
-- | Access the LCD connected to Arduino, making it show messages we read
-- from the user and demonstrate other LCD control features offered by
-- hArduino.
lcdDemo :: IO ()