hi, I can't run the motor with acceleration (smooth speed at start) and decelerate (smooth speed when I was it stopped).. all that when I push a button (start when I push button and stop when I release it)
i have used a pwm modulation and the acceleration is given by a constant k(that constant increases until n time steps which give by Ta/T. where Ta is the time of speed increases from 0 to max speed give by duty cycle and T is 1/f , f is the pwm frequency)
this is the sketch.... and the acceleration don't run.... when I upload this sketch in Arduino... the speed is the speed is instantaneous when I push the button..help me ..I'm going crazy
int MOT = 13; //Il MOTORE è connesso al pin 12
int PULS = 2; //Il pulsante è connesso al pin 2
int val = 0;
int f=200; // espresso in Hrtz
int T=1000/f;
int D=30; //D espresso in %
int Ta = 41000;
int n=Ta/T;
int k=0;
int ton = DTk/100;
int toff = T-ton;
void setup() {
pinMode(MOT, OUTPUT); //Il pin del MOTORE è un'uscita
pinMode(PULS, INPUT); //Il pin del pulsante è un'entrata
}
void loop() {
val = digitalRead(PULS); //Lettura del pulsante
if (k==n){goto label1;}
else{
k=k+1;
ton=Dk*T/n;
toff=T-ton;
}
label1:
if (val == 1) { //Se il valore del pulsante è 1
digitalWrite(MOT, HIGH);
delay(ton);
digitalWrite(MOT,LOW);
delay(toff);
}
else { //Altrimenti:
digitalWrite(MOT, LOW); //Spegni il MOTORE
}
}
Correct. Do not use goto.
In my classes at the U. of Akron, it was an automatic fail if you used goto.
That is how strongly the coding community feels about the perils of using goto.
Just don't.
Nothing to do with feeling, goto code is unintelligible and full of bugs and hard to optimize or reason about
and lacks referential transparity. We know its bad news.
However automatically generated code from a state-machine description often uses gotos - a special case
where human fallibility is excluded and there is a natural mapping from state-transition diagram to goto
code.