Hi, arduino noob programmer here,
I have a question:
How can i make a delay(x); from beginning of a function and not just a delay itself?
example:
>> "" beginn of delay"" -> stepper.step(123); ""delay continues till next argument"" <<
you mean delaying the whole function or what?
Silly Apoo. Instead of programming timing function, just take apart a clock to keep track of time for you.
I want a delay simultaneously starting with a function
about this way:
--------------------------------------->
^0 ^1 ^2
0_delay and function begins here
1_function ends before delay ends
2_delay ends
Or more precise sorry,
I want to play music with a stepper motor
I've already read out the notes with the diffrent speeds of the motor
so it already plays music.
To make sure that the notes are in sync I've adjusted the steps lenght of every note,
it works somehow but not great thats why i want every note have a timing so that every note is precisly timed
and so i could make exact music playbacks with the stepper motor.
for example:void c0 ()
{
myStepper.setSpeed(80);
myStepper.step(18);
delay( 25);
}
void cis0 ()
{
myStepper.setSpeed(85);
myStepper.step(20);
delay( 25);
}
void d0 ()
{
myStepper.setSpeed(90);
myStepper.step(22);
delay( 25);
}
any idea?
ty in advantage
>>58557937
Want the low level implementation?
Make hw interrupt where you increment a counter.
Then in your main, check if this value is more than 0, if it is, decrement it.
This will give you a way to control that your functions are run once per X seconds where X is the timer delay.
Then you make dispatcher functions where you call the right functions based on the current state.
Then you just make a state diagram on a piece of paper, write up the code and you are done.
Use millis() instead of delay.
>>58558905
ty for your answer
but dont understand it fully
where do i make hw interrupt?
the stepper uses 4 pins and i controll it with the stepper library
can you please write a little code so i can understand it better
this is basicly what i have now:#include <Stepper.h>
Stepper myStepper(75, 6, 7, 8, 9);
void setup()
{
Serial.begin(9600);
}
void loop()
{
c0();
d0();
e0();
f0();
g0();
a0();
h0();
pause();
}
void pause ()
{
delay(200);
}
void c0 ()
{
myStepper.setSpeed(80);
myStepper.step(18);
delay( 25);
}
void d0 ()
{
myStepper.setSpeed(90);
myStepper.step(22);
delay( 25);
}
void e0 ()
{
myStepper.setSpeed(100);
myStepper.step(24);
delay( 25);
}
void f0 ()
{
myStepper.setSpeed(105);
myStepper.step(25);
delay( 25);
}
void g0 ()
{
myStepper.setSpeed(120);
myStepper.step(27);
delay( 25);
}
void a0 ()
{
myStepper.setSpeed(133);
myStepper.step(28);
delay( 25);
}
void h0 ()
{
myStepper.setSpeed(150);
myStepper.step(29);
delay(25);
}
>>58558243
take a look at sporadic/non-periodic scheduling maybe