Duplicates all of the functionality of the Arduino "Servo" library. Fully compatible with all existing sketches that use the Arduino "Servo" library. Based upon the Eigendreams servo library posted here a while back. Supports 8 servos as-is. Can be modified to do a heck of a lot more, but that is up to you to incorporate (at least for now -- update to come soon).
An ultrasonic rangefinder library (StellarPad, easily modifiable to work with other Energia devices):
Designed for the HC-SR04 rangefinder, about $5 on e-bay. Should also work with some other rangefinders, but I have not tested any others. That is, again, up to you (for now). Supports as many of them as you can fit on your I/O.
A data smoother library (All Energia/Arduino supported devices):
Inspired by the Arduino "smoothing" example by Tom Igoe. Allows the creation of "Smoother" objects that calculate running averages of raw data. "Smoother" is a template class and can be instantiated to work with int's, float's, long's, etc.
All three libraries have their own examples, and the following is an example that incorporates the functionality of all of them (No comments, sorry! This one is pretty self-explanatory. See the library-specific examples for more details):
#include <SonicRanger.h>
#include <Smoother.h>
#include <Servo.h>
SonicRanger sr;
Servo servo;
Smoother<int, 10> ssmoother;
boolean smoothing = false;
void setup ()
{
sr.attach(PE_1, PE_2);
servo.attach(PF_1);
pinMode(BLUE_LED, OUTPUT);
digitalWrite(BLUE_LED, LOW);
pinMode(PUSH2, INPUT);
attachInterrupt(PUSH2, buttonISR, FALLING);
}
void loop ()
{
float distance = sr.getDistance(INCHES);
int processedDistance;
if(distance > 0)
{
processedDistance = (int)(distance * 1000);
processedDistance = constrain(processedDistance, 2000, 12000);
if(smoothing)
{
ssmoother.pushValue(processedDistance);
processedDistance = ssmoother.pullValue();
}
servo.write(map(processedDistance, 2000, 12000, 0, 180));
}
delay(50);
}
void buttonISR ()
{
smoothing = !smoothing;
digitalWrite(BLUE_LED, smoothing);
}
Video demonstration of the above example sketch: