-- 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.4
-- | Character to 7-segment display conversion.
module System.Hardware.Arduino.Parts.SevenSegmentCodes
-- | Convert a character to a bit-pattern, suitable for display on a
-- seven-segment display. Note that most characters are just not
-- representable in a 7-segment display, in which case we map it to
-- Nothing. However, some substitutions are done, for instance '('
-- is displayed the same as '['.
--
-- The return value is a Word8, although only 7-bits are used; the
-- least significant bit will always be 0. With the traditional coding,
-- the bits correspond to segments ABCDEFG0, i.e., most-significant-bit
-- will be for segment A, next for segment B, and so on.
char2SS :: Char -> Maybe Word8
-- | 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.Parts.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 an analog pin on the board. For instance, to refer to analog
-- pin no 0 simply use analog 0.
--
-- Note that analog 0 on an Arduino UNO will be
-- appropriately adjusted internally to refer to pin 14, since UNO has 13
-- digital pins, while on an Arduino MEGA, it will refer to internal pin
-- 55, since MEGA has 54 digital pins; and similarly for other boards
-- depending on their capabilities. (Also see the note on pin for
-- pin mappings.)
analog :: Word8 -> Pin
-- | Declare an digital pin on the board. For instance, to refer to digital
-- pin no 12 use digital 12.
digital :: Word8 -> Pin
-- | Declare a pin by its index. For maximum portability, prefer
-- digital and analog functions, which will adjust pin
-- indexes properly based on which board the program is running on at
-- run-time, as Arduino boards differ in their pin numbers. This function
-- is provided for cases where a pin is used in mixed-mode, i.e., both
-- for digital and analog purposes, as Arduino does not really
-- distinguish pin usage. In these cases, the user has the proof
-- obligation to make sure that the index used is supported on the board
-- with appropriate capabilities.
pin :: Word8 -> Pin
-- | A pin on the Arduino, as specified by the user via pin,
-- digital, and analog functions.
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]
-- | A hostOnly version of pulse-in on a digital-pin. Use this
-- function only for cases where the precision required only matters for
-- the host, not for the board. That is, due to the inherent delays
-- involved in Firmata communication, the timing will not be
-- accurate, and should not be expected to work uniformly over different
-- boards. Similar comments apply for pulseOut_hostTiming as well.
-- See the function pulse for a more accurate version.
pulseIn_hostTiming :: Pin -> Bool -> Maybe Int -> Arduino (Maybe Int)
-- | A hostOnly version of pulse-out on a digital-pin. Use this
-- function only for cases where the precision required only matters for
-- the host, not for the board. That is, due to the inherent delays
-- involved in Firmata communication, the timing will not be
-- accurate, and should not be expected to work uniformly over different
-- boards. Similar comments apply for pulseIn_hostTiming as well.
-- See the function pulse for a more accurate version.
pulseOut_hostTiming :: Pin -> Bool -> Int -> Int -> Arduino ()
-- | Send down a pulse, and measure how long the pin reports a
-- corresponding pulse, with a potential time-out. The call pulse p v
-- duration mbTimeOut does the following:
--
--
-- - Set the pin to value v for duration
-- microseconds.
-- - Waits 2 microseconds
-- - Waits until pin p has value not v.
-- - Returns, in micro-seconds, the duration the pin stayed v,
-- counting from the 2 microsecond wait.
--
--
-- Time-out parameter is used as follows:
--
--
-- - If mbTimeOut is Nothing, then pulse will
-- wait until the pin attains the value required and so long as it holds
-- it. Note that very-long time-out values are unlikely to be
-- accurate.
-- - If mbTimeOut is Just t then, pulse will
-- stop if the above procedure does not complete within the given
-- micro-seconds. In this case, the overall return value is
-- Nothing.
--
--
-- NB. Both the time-out value and the return value are given in
-- micro-seconds.
--
-- NB. As of March 2 2013; StandardFirmata that's distributed with the
-- Arduino-App does not support the Pulse-In command. However,
-- there is a patch to add this command; see:
-- http://github.com/rwldrn/johnny-five/issues/18 for details. If
-- you want to use hArduino's pulseIn command, then you
-- have to install the above patch. Also see the function
-- pulseIn_hostOnly, which works with the distributed
-- StandardFirmata: It implements a version that is not as accurate in
-- its timing, but might be sufficient if high precision is not required.
pulse :: Pin -> Bool -> Int -> Maybe Int -> Arduino (Maybe Int)
-- | 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 ()
-- | Time a given action, result is measured in micro-seconds.
time :: Arduino a -> Arduino (Int, a)
-- | Time-out a given action. Time-out amount is in micro-seconds.
timeOut :: Int -> Arduino a -> Arduino (Maybe a)
-- | Abstractions for shift-register IC parts.
module System.Hardware.Arduino.Parts.ShiftRegisters
-- | A shift-register class as supported by the hArduino library.
class ShiftRegister a
size :: ShiftRegister a => a -> Int
name :: ShiftRegister a => a -> String
dataSheet :: ShiftRegister a => a -> String
initialize :: ShiftRegister a => a -> Arduino ()
disable :: ShiftRegister a => a -> Arduino ()
enable :: ShiftRegister a => a -> Arduino ()
clear :: ShiftRegister a => a -> Arduino ()
push :: ShiftRegister a => a -> Bool -> Arduino ()
store :: ShiftRegister a => a -> Arduino ()
read :: ShiftRegister a => a -> Arduino [Bool]
-- | The Texas-Instruments 74HC595 8-bit shift register with 3-state
-- outputs. Data sheet:
-- http://www.ti.com/lit/ds/symlink/sn74hc595.pdf.
--
-- This is a versatile 8-bit shift-register with separate serial and
-- register clocks, allowing shifting to be done while the output remains
-- untouched. We model all control pins provided. Note that the enable
-- and clear lines are negated.
data SR_74HC595
SR_74HC595 :: Pin -> Pin -> Pin -> Pin -> Pin -> Maybe [Pin] -> SR_74HC595
-- | Chip Pin: 14: Serial input
serial :: SR_74HC595 -> Pin
-- | Chip Pin: 13: Negated output-enable
nEnable :: SR_74HC595 -> Pin
-- | Chip Pin: 12: Register clock, positive triggered
rClock :: SR_74HC595 -> Pin
-- | Chip Pin: 11: Serial clock, positive triggered
sClock :: SR_74HC595 -> Pin
-- | Chip Pin: 10: Negated clear-data
nClear :: SR_74HC595 -> Pin
-- | Chip Pins: 15, 1-7, and 8: Sequence of output bits, connect only if
-- reading is necessary
mbBits :: SR_74HC595 -> Maybe [Pin]
instance ShiftRegister SR_74HC595
-- | Abstractions for servo motors. See
-- System.Hardware.Arduino.SamplePrograms.Servo for example uses.
module System.Hardware.Arduino.Parts.Servo
-- | A servo motor. Note that this type is abstract, use attach to
-- create an instance.
data Servo
-- | Create a servo motor instance. The default values for the min/max
-- angle pulse-widths, while typical, may need to be adjusted based on
-- the specs of the actual servo motor. Check the data-sheet for your
-- servo to find the proper values. The default values of 544
-- and 2400 microseconds are typical, so you might want to start
-- by passing Nothing for both parameters and adjusting as
-- necessary.
attach :: Pin -> Maybe Int -> Maybe Int -> Arduino Servo
-- | Set the angle of the servo. The argument should be a number between 0
-- and 180, indicating the desired angle setting in degrees.
setAngle :: Servo -> Int -> Arduino ()
-- | Models of various Hardware components
module System.Hardware.Arduino.Parts
-- | 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 ()
-- | Measuring distance using a HC-SR04 sensor. (Data sheet:
-- http://www.micropik.com/PDF/HCSR04.pdf.)
--
-- NB. As of March 2 2013; StandardFirmata that's distributed with the
-- Arduino-App does not support the high accuracy pulse-in
-- command, which is needed for this sketch. However, there is a patch to
-- add this command; see:
-- http://github.com/rwldrn/johnny-five/issues/18 for details on
-- how to install it. You should have this patched version of
-- Firmata running on your board for this sketch to function properly.
--
-- Accuracy: Keep in mind that measurements on a platform like Arduino is
-- always subject to various errors. Relying on this program for precise
-- distance measurements would be a mistake. The results here should be
-- accurate to within about half-a-centimeter, provided you stay within
-- the range of HC-SR04, which is between 2 to 400 cm. For anything more
-- precise than this, you'll need to use a much more sensitive sensor.
module System.Hardware.Arduino.SamplePrograms.Distance
-- | Sound travels 343.2 meters per seconds
-- (http://en.wikipedia.org/wiki/Speed_of_sound). The echo time is
-- round-trip, from the sensor to the object and back. Thus, if echo is
-- high for d microseconds, then the distance in centimeters is:
--
--
-- d * 10^-6 * 343.2 * 10^2 / 2
-- = 1.716e-2 * d
--
microSecondsToCentimeters :: Int -> Float
-- | Measure and display the distance continuously, as reported by an
-- HC-SR04 sensor.
--
-- Wiring: Simply connect VCC and GND of HC-SR04 to Arduino as usual. The
-- Echo line on the sensor is connected to Arduino pin 2. The
-- Trig line is connected on the board to the Echo
-- line, i.e., they both connect to the same pin on the Arduino. We also
-- have a led on pin 13 that we will light-up if the distance detected is
-- less than 2 centimeters, indicating an impending crash!
--
distance :: 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 ()
-- | Computes the time a button is held pressed, demonstrating the use of
-- the pulseIn_hostOnly function with a time-out.
module System.Hardware.Arduino.SamplePrograms.PulseIn
-- | Computes the amount of time a push-button is connected to input pin 2
-- on the Arduino. We will wait for at most 5 seconds, as a further
-- demonstration of the time-out facility. Note that the timing is done
-- on the host side, so this measurement is inherently inaccurate.
--
-- The wiring is straightforward: Simply put a push-button between
-- digital input 2 and +5V, guarded by a 10K resistor:
--
pulseDemo :: IO ()
-- | Demonstrates the use of pulseOut
module System.Hardware.Arduino.SamplePrograms.PulseOut
-- | Send pulses on a led as requested by the user. Note that the timing is
-- computed on the host side, thus the duration of the pulse is subject
-- to some error due to the Firmata communication overhead.
--
-- Wiring: Simply a led on pin 13:
--
pulseDemo :: IO ()
-- | Control a single seven-segment display, echoing user's key presses on
-- it verbatim. We use a shift-register to reduce the number of pins we
-- need on the Arduino to control the display.
module System.Hardware.Arduino.SamplePrograms.SevenSegment
-- | Connections for the Texas Instruments 74HC595 shift-register.
-- Datasheet: http://www.ti.com/lit/ds/symlink/sn74hc595.pdf. In
-- our circuit, we merely use pins 8 thru 12 on the Arduino to control
-- the serial, enable, rClock, sClock, and
-- nClear lines, respectively. Since we do not need to read the
-- output of the shift-register, we leave the bits field
-- unconnected.
sr :: SR_74HC595
-- | Seven-segment display demo. For each key-press, we display an
-- equivalent pattern on the connected 7-segment-display. Note that most
-- characters are not-mappable, so we use approximations if available. We
-- use a shift-register to reduce the pin requirements on the Arduino,
-- setting the bits serially.
--
-- Parts:
--
--
-- - The seven-segment digit we use is a common-cathode single-digit
-- display, such as TDSG5150
-- (http://www.vishay.com/docs/83126/83126.pdf), or Microvity's
-- IS121, but almost any such digit would do. Just pay attention to the
-- line-connections, and do not forget the limiting resistors: 220 ohm's
-- should do nicely.
-- - The shift-register is Texas-Instruments 74HC595:
-- http://www.ti.com/lit/ds/symlink/sn74hc595.pdf. Make sure to
-- connect the register output lines to the seven-segment displays with
-- the corresponding letters. That is, shift-registers Q_A
-- (Chip-pin 15) should connect to segment A; Q_B
-- (Chip-pin 1) to segment B, and so on. We do not use the
-- shift-register Q_H' (Chip-pin 9) in this design.
--
--
sevenSegment :: IO ()
-- | Demonstrates basic Servo motor control
module System.Hardware.Arduino.SamplePrograms.Servo
-- | Control a servo, by executing user requests of blade movement. We
-- allow 3 user commands:
--
--
-- - l to swipe from angle-0 to 180;
-- - r to swipe from angle-180 to 0;
-- - Or any number between 0 to 180, which puts the
-- servo to the desired position.
--
--
-- Almost any servo motor would work with this example, though you should
-- make sure to adjust min/max pulse durations in the attach
-- command to match the datasheet of the servo you have. In this example,
-- we have used the HS-55 feather servo
-- (http://www.servocity.com/html/hs-55_sub-micro.html), which has
-- the values 600 to 2400 micro-seconds.
--
-- To connect the servo to the Arduino, simply connect the VCC (red) and
-- the GND (black) appropriately, and the signal line (white) to any
-- SERVO capable pin, in this example we're using pin number 9:
--
servo :: IO ()
-- | Control a servo, as guided by the input read from a potentiometer. The
-- set-up is similar to the servo example above, except instead of
-- querying the user for the angle, we use the readings from a
-- potentiometer connected to analog input number 2. We used a 10 KOhm
-- potentiometer, but other pots would work just as well too:
--
servoAnalog :: IO ()