Can someone write a sketch for us?

I am not a programmer or tech guru by a long shot and my 7 year old kiddo needs help with a school project and we have not had any luck as of yet. We need to combine the "blink" example with one of the stepper motor sketches to slowly turn a stepper motor and blink two leds on a foam airplane he built. Can someone write a sketch that will do this? It would be greatly appreciated.

Try "Gig's and Collaborations" down the hall.

millphoto:
I am not a programmer or tech guru by a long shot and my 7 year old kiddo needs help with a school project and we have not had any luck as of yet. We need to combine the "blink" example with one of the stepper motor sketches to slowly turn a stepper motor and blink two leds on a foam airplane he built. Can someone write a sketch that will do this? It would be greatly appreciated.

Read your PM

Neat project for your 7 year old. Is the purpose of the project to teach him something or just fill some time with other peoples' work?

Vaclav:
Read your PM

Thank you. Can't wait to get home and give it a go.

Vaclav, why did you send your reply (which I assume was a solution for millphoto) as a PM instead of just posting in the forum so others can learn from it?

If everyone just PM'd or emailed answers, the entire community doesn't grow as a group.

Not sure a whole lot of learning for either the kid or Dad's going to happen here if someone sends (sent?) a turnkey solution.

millphoto:
I am not a programmer or tech guru by a long shot and my 7 year old kiddo needs help with a school project and we have not had any luck as of yet. We need to combine the "blink" example with one of the stepper motor sketches to slowly turn a stepper motor and blink two leds on a foam airplane he built. Can someone write a sketch that will do this? It would be greatly appreciated.

"Programming an Arduino" sounds like nothing a 7 year old child should be able to do.
I really don't know how somebody could came up with that.

But what you want sounds like a simple programming exercise.
Please send more information about the hardware you are planning to use, the desired "blink" and "stepper motor sketch" and I'll give it a try.

todbot:
Vaclav, why did you send your reply (which I assume was a solution for millphoto) as a PM instead of just posting in the forum so others can learn from it?

If everyone just PM'd or emailed answers, the entire community doesn't grow as a group.

I have a bad attitude

jurs:
"Programming an Arduino" sounds like nothing a 7 year old child should be able to do.

Shouldn't that read
Programming an Arduino" sounds like something a 7 year old child should be able to do

...R

Vaclav:
I have a bad attitude

That is not funny.
And it is definitely not in the spirit of the Forum or of Open Source Software.

...R

Robin2:
That is not funny.
And it is definitely not in the spirit of the Forum or of Open Source Software.

...R

OT

Not my fault as I am tired of being pushed around, but I admit I was too upset , OK pissed off , by defender of purity of posts on different thread.

I'll be happy to explain in detail ( via PM) why I reacted that way , but definitely not here in public, because such explanation would not help the OP as first few replies did not either.
It is called "passing the buck" and lecturing OP about the request was not cool either.

PS Read this quick, the post may became invisible soon.

OT

Vaclav:
OT

Not my fault as I am tired of being pushed around, but I admit I was too upset , OK pissed off , by defender of purity of posts on different thread.

I'll be happy to explain in detail ( via PM) why I reacted that way , but definitely not here in public, because such explanation would not help the OP as first few replies did not either.
It is called "passing the buck" and lecturing OP about the request was not cool either.

PS Read this quick, the post may became invisible soon.

OT

Just in case it becomes invisible - now there are two copies.

...R

Robin2:
now there are two copies.

Well no not really: only one of them's a copy 8)

Spam
The following are considered spam:

Very short posts that do not add value to the current discussion.

Double posts. If a member posted something and you realized they made a mistake, use the edit/delete option.

Off topic posts will be either removed or moved to the appropriate place, depending on moderator.

Posts that obviously serve no purpose other than uping one's post counts.

What to choose, what to choose . . .

OT, by admission, I think.

JimboZA:
Not sure a whole lot of learning for either the kid or Dad's going to happen here if someone sends (sent?) a turnkey solution.

Not entirely.

Sonny will be in on the wiring and installation as well as see that there does need to be the program and how it gets put in the chip as well as get to wow about the result.

It won't be quite the magic box he gets no clue of the workings even though he won't know coding.

With any luck, he will be motivated to learn more and have a geek side before 7th grade.

GoForSmoke:
Not entirely.

I did say "not a whole lot"..... I didn't say that no learning would take place.

I think that it will be a whole lot for the kid.
He's in second grade.
He will be learning about himself and his Dad, and how to work together.
This may be a whole new world for him.

We get 3rd and 4th year engineering students that are know-nothings.
"Help! My final year project is due next week and I've barely started!"

You can try something like this, if you're still reading. This hasn't actually been tested, but it does compile.
It contains my favorite little function for simplifying the whole "implement delays without using delay()" thing

#include <Stepper.h>

/*
 * Pins where our hardware lives
 */
#define LED1_PIN 2
#define LED2_PIN 3
#define MOT_PIN1 4
#define MOT_PIN2 5

/*
 * define our stepper motor
 * See http://arduino.cc/en/reference/stepper
 */
const int stepsPerRevolution = 24;  // change this to fit the number of steps per revolution
// for your motor (this can vary a lot.  24 happens to match a cheap stepper that I saw for
// sale (15 degrees/step:
// http://www.allelectronics.com/make-a-store/item/smt-375/airpax-stepper-motor/1.html )

// initialize the stepper library on pins.
Stepper myStepper(stepsPerRevolution, MOT_PIN1, MOT_PIN2);

/*
 * THese are variables used to do the actual timing of intervals for
 * the different objects we're trying to control.
 */
unsigned long led1_timer, led2_timer, step_timer;

/*
 * These variables are use to save the LED states, so we know whether to turn
 * them on, or off, when the delay expires.  Initialized as show, they'll alternate
 */
 byte led1_state = false, led2_state = true;


/*
 * And these are the constants for how long we'll delay
 */
#define LED1_TIME 500  /* 0.5 s */
#define LED2_TIME 500  /* 0.5 s also */
#define STEP_TIME 50   /* 20 steps/second should be pretty slow */
 
/*
 * Support function for delaying separate events without interfering
 * with other events.
 */
boolean delay_without_delaying(unsigned long &since, unsigned long time) {
  // return false if we're still "delaying", true if time ms has passed.
  // this should look a lot like "blink without delay"
  unsigned long currentmillis = millis();
  if (currentmillis - since >= time) {
    since = currentmillis;
    return true;
  }
  return false;
}

void setup() {
  pinMode(LED1_PIN, OUTPUT);
  pinMode(LED2_PIN, OUTPUT);
}

void loop() {
  // Check first LED
  if (delay_without_delaying(led1_timer, LED1_TIME)) {
    led1_state = ! led1_state;  // toggle
    digitalWrite(LED1_PIN, led1_state);
  }
  // Check second LED
  if (delay_without_delaying(led2_timer, LED2_TIME)) {
    led2_state = ! led2_state;  // toggle
    digitalWrite(LED2_PIN, led2_state);
  }
  // Check if time to step the motor
  if (delay_without_delaying(step_timer, STEP_TIME)) {
    myStepper.step(1);
  }
}

Nice little routine, as a novice I found the '&' the most useful learning point :slight_smile:

However, wont this routine always return a boolean false? Seems its missing an 'else' statement...

boolean delay_without_delaying(unsigned long &since, unsigned long time) {
  // return false if we're still "delaying", true if time ms has passed.
  // this should look a lot like "blink without delay"
  unsigned long currentmillis = millis();
  if (currentmillis - since >= time) {
    since = currentmillis;
    return true;
  }
  return false;
}