Hey,
When I just check the RAW values from the sensors,
jitter seems pretty minimal now.
I added an extra capacitor, adding even more
does not seem to improve the situation.
The sensor response is still not ideal however.
I do a time-averaged read of the sensors,
but improvements are possible.
I guess some smarter filtering could help.
(Analog pin 0 and 1 are connected to the IR rangers)
(The flex sensors a quite stable now)
/* PuppetMaster V5 Code */
/* Jim Bollansée | jim@jimboproductions.be */
/* Creative Commons Attribution ShareAlike */
/* GameHUB 2011 */
unsigned long previousMillis;
unsigned long currentMillis;
int numberOfSteps = 0;
int sensorValue[6];
long sensorValueTotal[6];
float tempFloat;
// Set calibrate to 255 to disable calibration
int calibrate = 255;
int sensorTop[] = {25500, 27000, 510, 530, 530, 480};
int sensorBottom[] = {3500, 3500, 610, 650, 630, 600};
byte dataStart = 0xFF;
void setup()
{
Serial.begin(9600);
}
void loop()
{
numberOfSteps ++;
currentMillis = millis();
for (int i = 0; i < 6; i++)
{
sensorValueTotal[i] = sensorValueTotal[i] + analogRead(i);
}
if (currentMillis - previousMillis > 40)
{
if (calibrate == 255) Serial.print(dataStart);
for (int i = 0; i < 6; i++)
{
tempFloat = (float) sensorValueTotal[i];
tempFloat = tempFloat / numberOfSteps;
sensorValue[i] = (int) tempFloat;
sensorValueTotal[i] = 0;
// IR Ranger specifics
if (i < 2)
{
tempFloat = (float) sensorValue[i];
tempFloat = (2914 / (tempFloat + 5)) - 1;
tempFloat = tempFloat * 1000;
sensorValue[i] = (int) tempFloat;
}
if (calibrate == i) Serial.println(sensorValue[i]);
if (calibrate == 255)
{
/// Only map to 254 because 255 is start byte!
sensorValue[i] = map(sensorValue[i], sensorBottom[i], sensorTop[i], 0, 254);
sensorValue[i] = constrain(sensorValue[i], 0, 254);
Serial.print((byte)sensorValue[i]);
}
}
numberOfSteps = 0;
previousMillis = millis();
}
}