hArduino-1.1: Control your Arduino board from Haskell.

Copyright(c) Levent Erkok
Safe HaskellNone



Demonstrates basic Servo motor control



servo :: IO () Source

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:

servoAnalog :: IO () Source

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: