how to alternate between forward and reverse of a brushed motor with ESC

so I copied and pasted a code and got my motor spinning at different directions, and at different speeds depending on the number that I applied. My task at hand is to spin this motor at a desired speed in one direction for 4 seconds----than pause for one second----than spin in the opposite direction for 4 seconds at the same speed (in both forward and reverse same speed)--- I am basically making a blender but more scientific---I want to repeat this process for about 45 minutes---how do I go about that---.Once I choose a speed through this code I used, how do I go about using/programing those speeds into arduino to operate in the timing that I would like ( the selected speed for forward and the selected speed for reverse)?? How do I alternate between these two desired speeds/ how do I program the Arduino to do that? For example Lets say I like the speed I got when I entered "70" in the serial monitor (found under tools), and I liked the speed I got in the other direction when I entered "110", how do I get "70" to spin for 4 seconds----than stop for a second----than switch to speed "110" for 4 seconds----than stop for one second---than switch back to speed "70" for 4 seconds---than stop for 1 second----than switch back to speed "110" for about 4 seconds--- I need to keep this alternating speeds going for about 45 minutes

Without knowing which motor driver you are using (ESC?) and seeing your code, only general advise can be offered. For the timing portion look in the examples in the IDE (File, Examples) for the blink without delay example. That will show how to do timing without blocking. Delay() could be used but the processor won't be able to do anything else while the delay is in effect. In some cases that is OK, but if you want to, for example, abort the process you have to wait till the delay times out before the abort (or any other code) can execute.

The other thing to look into is the state machine. You have 3 states that the program can be in, running forward, running backward and pausing.

I don't know what a motor driver is...My electronic speed control its called Axial AE-5 Forward/Reverse ESC w/ Drag brake. I am using an arduino Uno...my motor is an Axial 55T brushed electric motor, my battery is a 7.2 volt 5000mAh NiMH battery

the code which I copied and pasted is the found below...what I've done after uploading this code, and while all my devices where connected, is gone to "Serial monitor" which is found under "tools" it brought me to screen where I plugged in numbers from my computer and depending on the number I inserted it gave me a certain speed and direction; everything varied as the number changed. I don't really know much about any of this stuff, I guess my question is once I find a desired speed whats my next move, how do I do what I described in my first post, found above?

/zoomkat 7-30-10 serial servo test
//type servo position 0 to 180 in serial monitor
// Powering a servo from the arduino usually DOES NOT WORK.

String readString;
#include <Servo.h>
Servo myservo; // create servo object to control a servo

void setup() {
Serial.begin(9600);
myservo.attach(9);
Serial.println("servo-test"); // so I can keep track of what is loaded
}

void loop() {

while (Serial.available()) {
char c = Serial.read(); //gets one byte from serial buffer
readString += c; //makes the String readString
delay(2); //slow looping to allow buffer to fill with next character
}

if (readString.length() >0) {
Serial.println(readString); //so you can see the captured String
int n = readString.toInt(); //convert readString into a number
Serial.println(n); //so you can see the integer
myservo.write(n);
readString="";
}
}

btw fungus on the ground is the way to go...without giving me to much advice, what do you think is the next step I should take, what should I do/watch/read/ ...baby steps/one thing at a time...because I know nothing...I guess how do I select two speeds is the next step how would I go about programing the arduino to know two speeds, after I learn that, than I can get into timing, but before I get to timing I need to know how to select two speeds in which to jump back and forth from

It looks like the ESC takes basic servo commands. This code should do what you say. This is not the best way to do it because it uses delay(). It will use your predetermined numbers for speed. You may need to tweak the stopSpeed to get the motor to stop, but the number should be close to 90.

#include <Servo.h>
Servo motor;

byte forwardSpeed = 110;
byte backSpeed = 70;
byte stopSpeed = 90;  // change to experimenally deternmied number

unsigned long forwardInterval = 4000;
unsigned long backInterval = 4000;
unsigned long pauseInterval = 1000;

void setup()
{
    Serial.begin(9600);
    motor.attach(9);
    Serial.println("Beginnung test");
}

void loop()
{
    motor.write(forwardSpeed);
    Serial.println("run forward");
    delay(forwardInterval);
    motor.write(stopSpeed);
    Serial.println("stopped");
    delay(pauseInterval);
    motor.write(backSpeed);
    Serial.println("run reverse");
    delay(backInterval);
    motor.write(stopSpeed);
    Serial.println("stopped");
    delay(pauseInterval);
}

In this site on the learning tab you will find many tutorials and example code to study if you are so inclined. The playground has code examples and libraries for just about anything you can think of. And the forum is a great place to ask questions. I have to ask that you read the "how to use the forum" stickies so you will know the rules for posting.

thanks again buddy,
----something odd is happening, so if I turn it on it may work and it may not work, the program has gotten it to work properly, and also not properly, it spins forward than stops than spins in reverse; which is good, but it will malfunction most of the time, and this is what I mean by malfunction; it will just spin in one direction, stop for about 7 seconds than spin again in the same direction. Only two times has it worked properly, I turn off the ESC and try to restart , and it still doesn't work; out of about 8 attempts of doing that, it has worked 2 times, the other 6 times it just spun in one direction stopped for a pretty long time about 7 seconds than spun again in the same direction, and kept doing this, the 2 times that It did work, it seemed to be "in the ball park" of what I needed, it seemed to pause for about 2 seconds and 3 seconds; depending on the direction it was switching from; it took a slightly longer pause or shorter pause, roughly 2 or 3 seconds; when it was working properly and spinning in 2 directions. When it malfunctioned it repeated in the same direction and it seemed to take a 7 second pause between repeating the same direction?...I am wondering, maybe "90" is not completely neutral and that, that could have something to do with it? I don't know, What do you think?

Are all the grounds connected? ESC, battery and Arduino grounds should be together. Use Zoomkat's sketch from your previous post to home in on the value to stop the motor.

I tested the code with a servo and it worked as expected so I believe the problem is in hardware and/or the motor not stopping right like you pointed out.

What are the serial prints saying, in serial monitor.

I switched the stop speed from "90" to "92" that seemed to have corrected the issue that I was having, I want to ask you questions, but I don't know where to start I guess ill ask one question pertaining to the very beginning part of the code...everything before --"void setup"...I copied and pasted it below...

I notice that there are different colors that appear when writing a code.... in lines 3,4,5
...the phrase "byte" comes in the color blue; what is the significance of the color blue, also I notice that "forwardSpeed", "backSpeed" & "stopSpeed" is written in black; black as if the arduino didn't pick up on anything in particular? is that right?....what does "byte" do/mean...what does "unsigned long" do/mean(in lines 6,7,8), it is also blue why is that?

1)#include <Servo.h>
2)Servo motor;

3)byte forwardSpeed = 110;
4)byte backSpeed = 70;
5)byte stopSpeed = 92; // change to experimenally deternmied number

6)unsigned long forwardInterval = 4000;
7)unsigned long backInterval = 4000;
8)unsigned long pauseInterval = 1000;

Keywords are colored, I guess, to aid in programming. Data types like byte, char, int are keywords. Most commands like if, while, for, etc are also keywords. Then each library can have a file (keywords) that specifies its own set of keywords. String literals are in a different color to help them stand out, again I guess. The colors vary with different IDEs and operating systems. The data type color is orange on mine.

Byte and unsigned long are data types. The compiler needs to know how much storage (memory) to set aside for each variable so the data type (relates to size) has to be specified when the variable is declared.

Here I use byte data type because the number that the variable contains will never be over 255 or less than 0. I use 1 byte of storage for each variable.

I use unsigned long because delay() expects an unsigned long.

Seems like you could use basic programming and C++ tutorials.

I started by reading books. I studied Fortran in the early 70's in college. My first experience with microprocessors and microcontrollers was in the early 80's so no Internet. Most of the micro programming that I did before Arduino was in assembly languages. When I picked up Arduino 5 or 6 years ago I had to learn C++. Virtually all of my C++ education came from tutorials on the Net and by reading a lot on this forum and web site. So,for learning Arduino C++, I would say probably 70% from the Arduino (this) web site and the other 30% from other sources.

Anytime you have a question that you can't find the answer for ask us, that is what we are here for.