[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Hi, arduino noob programmer here, I have a question: How can

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 11
Thread images: 3

File: d4e5b9d9b928ba06831f16a26dc69c36.jpg (267KB, 1000x667px) Image search: [Google]
d4e5b9d9b928ba06831f16a26dc69c36.jpg
267KB, 1000x667px
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"" <<
>>
>>58557937
?
>>
you mean delaying the whole function or what?
>>
File: ahmedmohamedfeatured.jpg (2MB, 2500x1683px) Image search: [Google]
ahmedmohamedfeatured.jpg
2MB, 2500x1683px
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
>>
File: 1466364.jpg (94KB, 1024x768px) Image search: [Google]
1466364.jpg
94KB, 1024x768px
>>
>>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
Thread posts: 11
Thread images: 3


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.