Viewing single post of blog Analogue….Digital

I have spent about 4 days programming both with the Arduino IDE and also Processing

My aim has been to use the measurement of time passing as the basis for creating acceleration and deceleration of the motors.

Motor speeds up between 0 and 8 secs
Motor slows down between 8 and 16 secs and so on

If you look at this processing example of Easing
https://processing.org/examples/easing.html you can see the element slowing down. The code works on the present position of the element to determine its speed.

I have been using the amount of time that has passed to do the same thing:

int val1, myPos1,myPos2,speed1,speed1a,speed2,testSpeed,xInt;
int count=0;
int timeExtent1 = 10000;
int timeExtent2 = 18000;
int timeExtent3 = 18000;
int timeExtent4 = 26000;
int timeExtent5 = 27000;
int timeExtent6 = 35000;
int timeExtent7 = 35000;
int timeExtent8 = 43000;
float easing = 0.05;

unsigned long startTime,currTime,ratioTime,targetX,dx,x,sensVal;
#include <SoftwareSerial.h>
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
startTime = millis();
currTime=millis();
speed1 = 0;
}

void loop() {

while(currTime>=startTime + timeExtent1 && currTime<=startTime + timeExtent2){
currTime=millis();

ratioTime= int(currTime-timeExtent1);
targetX = timeExtent2;
dx = targetX-currTime;
x += dx;
xInt = int (x);
// Serial.println(“doing it 1”);
// Serial.println(ratioTime);
// sensVal = constrain(x, 0, 36000);
sensVal = map(dx,0,8000,0,127);
// put your main code here, to run repeatedly:
speed1 += (sensVal)*easing;

//speed1 = (testSpeed*easing)+127;
speed1a = map(speed1,0,4200,0,127)+127;
Serial.println(speed1a);

}
currTime=millis();
}


0 Comments