We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, I'm completely new to all this and am now lost on how to 'average' my sequence. I have a sequence in png format of the horizon, arduino and an IR sensor. When you walk closer to the sensor the horizon should get bigger and walk away it should eventually just be a thin white line. My problem is that as you walk towards it, the sequence starts to flicker and it also is not completing the sequence. It only goes to about 60% of the walk even though I am standing right in front of it. How do I smooth it out so it transitions from image to image? Thanks for any advice at all you may have :)
CODE:
import processing.serial.*;
import cc.arduino.*;
Arduino arduino;
PImage img[] = new PImage[225];
void setup() { size(1280, 800); smooth(2);
// Prints out the available serial ports. println(Arduino.list());
arduino = new Arduino(this, "COM6", 1500);
for (int i = 0; i < img.length; i++) {
String sa = nf(i, 3);
img[i] = loadImage("horizon_00"+sa+".png");
} }
void draw() { int sensorValue = arduino.analogRead(0);
if (sensorValue > 260 && sensorValue < 630) { int keyFrame = int(map(sensorValue, 260, 630, 0, 224));
println(sensorValue + " " + keyFrame );
image(img[keyFrame], 0, 0);
} }
Answers
this line
gives you probably a fast change of images.
Instead try to check if the sensorValue is higher or lower than the last one and if so just change keyFrame by 1.
If the
abs
of the difference is higher 5 or so (test it) (this makes it more calm), just say keyFrame++; or keyFrame--; (this makes it more calm as well, because keyFrame can't jump)maybe you could allow for a new image only every 3rd frame or 100 millis?
Great, thanks for your reply! I'll check it and see how it works out
try the above first
but you could also average the sensorValue over the last 5 frames or 15 frames and only then use
keyFrame = int(map(sensorValueAverage, 260, 630, 0, 224));