-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Control your Arduino board from Haskell. -- -- hArduino allows Haskell programs to control Arduino boards -- (http://www.arduino.cc) and peripherals, using the Firmata -- protocol (http://firmata.org). -- -- For details, see: http://leventerkok.github.io/hArduino. @package hArduino @version 1.2 -- | 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 -- | LCD's connected to the board data 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: -- -- 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: -- -- 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 () -- | hArduino allows Haskell programs to control Arduino boards -- (http://www.arduino.cc) and peripherals, using the Firmata -- protocol (http://firmata.org). -- -- For details, see: http://leventerkok.github.com/hArduino. module System.Hardware.Arduino -- | Run the Haskell program to control the board: -- -- -- -- See System.Hardware.Arduino.Examples.Blink for a simple -- example. withArduino :: Bool -> FilePath -> Arduino () -> IO () -- | The Arduino monad. data Arduino a -- | 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 -- | NB. No explicit support ONEWIRE :: PinMode -- | NB. No explicit support STEPPER :: PinMode -- | NB. No explicit support ENCODER :: PinMode -- | NB. No explicit support SERIAL :: PinMode -- | NB. No explicit support PULLUP :: PinMode -- | A mode we do not understand or support UNSUPPORTED :: PinMode -- | Set the mode on a particular pin on the board setPinMode :: Pin -> PinMode -> 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 -- | Write a PWM analog value to a pin. The argument is an Int, -- indicating the duty cycle. 0 means off; 255 means -- always on. Intermediate values will create a square wave on that pin -- with the given duty-cycle analogWrite :: Pin -> Int -> 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 -- | 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] -- | 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: -- -- -- -- Time-out parameter is used as follows: -- -- -- -- 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) -- | 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 () -- | 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 () -- | Turn on/off internal pull-up resistor on an input pin pullUpResistor :: Pin -> Bool -> Arduino () -- | 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) -- | 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) -- | Demonstrates pulseIn_hostTiming and pulseOut_hostTiming -- functions, sending and receiving pulses to/from the board. module System.Hardware.Arduino.SamplePrograms.Pulse -- | 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: -- pulseInDemo :: IO () -- | 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: -- pulseOutDemo :: IO () -- | Simple number guessing game on the OSEPP Keyboard shield. -- -- Thanks to David Palmer for lending me his OSEPP shield to play -- with! module System.Hardware.Arduino.SamplePrograms.NumGuess -- | The OSepp LCD Shield is a 16x2 LCD using a Hitachi Controller -- Furthermore, it has backlight, and 5 buttons. The hook-up is quite -- straightforward, using our existing Hitachi44780 controller as an -- example. More information on this shield can be found at: -- -- -- http://osepp.com/products/shield-arduino-compatible/16x2-lcd-display-keypad-shield/ osepp :: LCDController -- | There are 5 keys on the OSepp shield. data Key KeyRight :: Key KeyLeft :: Key KeyUp :: Key KeyDown :: Key KeySelect :: Key -- | Initialize the shield. This is essentially simply registering the lcd -- with the HArduino library. In addition, we return two values to the -- user: -- -- initOSepp :: Arduino (LCD, Bool -> Arduino (), Arduino (Maybe Key)) -- | Number guessing game, as a simple LCD demo. User thinks of a number -- between 0 and 1000, and the Arduino guesses it. numGuess :: LCD -> (Bool -> Arduino ()) -> Arduino (Maybe Key) -> Arduino () -- | Entry to the classing number guessing game. Simply initialize the -- shield and call our game function. guessGame :: IO () -- | Morse code blinker. Original by Antoine R. Dumont, modified to -- simplify and fit into the existing examples structure. module System.Hardware.Arduino.SamplePrograms.Morse -- | A dit or a dah is all we need for Morse: A dit is a dot; and -- a dah is a dash in the Morsian world. We use LBreak -- and WBreak to indicate a letter and a word break so we can -- insert some delay between letters and words as we transmit. data Morse Dit :: Morse Dah :: Morse LBreak :: Morse WBreak :: Morse -- | Morse code dictionary dict :: [(Char, [Morse])] -- | Given a sentence, decode it. We simply drop any letters that we do not -- have a mapping for. decode :: String -> [Morse] -- | Given a morsified sentence, compute the delay times. A Left -- value means turn the led on that long, a Right value means turn -- it off that long. morsify :: [Morse] -> [Either Int Int] -- | Finally, turn a full sentence into a sequence of blink on/off codes transmit :: Pin -> String -> Arduino () -- | A simple demo driver. To run this example, you only need the Arduino -- connected to your computer, no other hardware is needed. We use the -- internal led on pin 13. Of course, you can attach a led to pin 13 as -- well, for artistic effect. -- morseDemo :: IO () instance GHC.Show.Show System.Hardware.Arduino.SamplePrograms.Morse.Morse -- | 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: -- -- -- 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 () -- | 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 second -- (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 5 centimeters, indicating an impending crash! -- distance :: 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 () -- | 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 () -- | 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 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 () -- | 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 -- | Capacity size :: ShiftRegister a => a -> Int -- | Display name name :: ShiftRegister a => a -> String -- | Data sheet (typically a URL) dataSheet :: ShiftRegister a => a -> String -- | Initialize the shift-register initialize :: ShiftRegister a => a -> Arduino () -- | Disable the output, putting it into high-impedance state disable :: ShiftRegister a => a -> Arduino () -- | Enable the output, getting it out of the high-impedance state enable :: ShiftRegister a => a -> Arduino () -- | Clear the contents clear :: ShiftRegister a => a -> Arduino () -- | Push a single bit down the shift-register push :: ShiftRegister a => a -> Bool -> Arduino () -- | Store the pushed-in values in the storage register store :: ShiftRegister a => a -> Arduino () -- | Read the current value stored 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 System.Hardware.Arduino.Parts.ShiftRegisters.ShiftRegister System.Hardware.Arduino.Parts.ShiftRegisters.SR_74HC595 -- | 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 mbBits 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: -- -- -- sevenSegment :: IO () -- | 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 () -- | 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: -- -- -- -- 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 () -- | Abstractions for piezo speakers. module System.Hardware.Arduino.Parts.Piezo -- | A piezo speaker. Note that this type is abstract, use speaker -- to create an instance. data Piezo -- | Create a piezo speaker instance. speaker :: Int -> Pin -> Arduino Piezo -- | Musical notes, notes around middle-C data Note A :: Note B :: Note C :: Note D :: Note E :: Note F :: Note G :: Note R :: Note -- | Beat counts data Duration Whole :: Duration Half :: Duration Quarter :: Duration Eight :: Duration -- | Play the given note for the duration playNote :: Piezo -> (Note, Duration) -> Arduino () -- | Rest for a given duration: rest :: Piezo -> Duration -> Arduino () -- | Turn the speaker off silence :: Piezo -> Arduino () -- | Play a sequence of notes with given durations: playNotes :: Piezo -> [(Note, Duration)] -> Arduino () instance GHC.Show.Show System.Hardware.Arduino.Parts.Piezo.Note instance GHC.Classes.Eq System.Hardware.Arduino.Parts.Piezo.Note instance GHC.Show.Show System.Hardware.Arduino.Parts.Piezo.Duration instance GHC.Classes.Eq System.Hardware.Arduino.Parts.Piezo.Duration -- | A (pretty bad!) rendering of Jingle Bells on a piezo speaker module System.Hardware.Arduino.SamplePrograms.JingleBells -- | Notes for jingle-bells. Expecting a nice rendering from this encoding -- on a piezo speaker would be naive.. However, it's still recognizable! jingleBells :: [(Note, Duration)] -- | Play the jingle-bells on a PWM line, attached to pin 3. We use a tempo -- of 75; which is fairly fast. For a slower rendring try -- 150 or higher values. -- -- The circuit simple has a piezo speaker attached to pin 3. -- main :: IO () -- | Models of various Hardware components module System.Hardware.Arduino.Parts