Go Down

Topic: Stopping, Starting (Read 781 times) previous topic - next topic

TyErd

When I connect my usb and upload my sketch, it runs perfectly until my program finishes. But how do I make it run again without connecting the usb and uploading it again? Also Is there a way to stop the sketch while it is running?

AWOL

Code: [Select]
it runs perfectly until my program finishes
What program would that be?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

TyErd

I mean the sketch. When the sketch finishes, how do i make it restart again without uploading using the usb? Also I'm running two motor using transistors and If my sketch is running, say, both motors are to rotate for 15 seconds and stop, but halfway through i realise i want it to stop the sketch to save the battery or something, how do i do that without taking the batteries out. The reset button doesn't do anything.

AWOL

Quote
I mean the sketch. When the sketch finishes,

Two definite articles, but no appearance of the sketch. (that's an oblique hint for you to post code)
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

TyErd

Code: [Select]

const int transistorPin = 9;    // connected to the base of the transistors
const int transistorPin1 = 10;  // connected to the base of the transistors

void setup() {
   // set  the transistor pins as outputs:
   pinMode(transistorPin, OUTPUT);
   pinMode(transistorPin1, OUTPUT);

}

void loop()
{
   digitalWrite(transistorPin, HIGH); //turn on
   digitalWrite(transistorPin1, HIGH); //turn on


   delay(2700);

   digitalWrite(transistorPin, HIGH); //turn on
   digitalWrite(transistorPin1, LOW); //turn off


   delay(1950);
   
   digitalWrite(transistorPin, HIGH); //turn on
   digitalWrite(transistorPin1, HIGH); //turn on


   delay(5750);
   
   digitalWrite(transistorPin, HIGH); //turn on
   digitalWrite(transistorPin1, LOW); //turn off
   

   delay(1950);
   
   digitalWrite(transistorPin, HIGH); //turn on
   digitalWrite(transistorPin1, HIGH); //turn on


   delay(2000);
   
   digitalWrite(transistorPin, LOW); //turn off
   digitalWrite(transistorPin1, HIGH); //turn on


   delay(1950);
   
   digitalWrite(transistorPin, HIGH); //turn on
   digitalWrite(transistorPin1, HIGH); //turn on


   delay(5400);
   
   digitalWrite(transistorPin, LOW); //turn off
   digitalWrite(transistorPin1, HIGH); //turn on


   delay(1950);
   
   digitalWrite(transistorPin, HIGH); //turn on
   digitalWrite(transistorPin1, HIGH); //turn on


   delay(1100);
   
   digitalWrite(transistorPin, HIGH); //turn on
   digitalWrite(transistorPin1, LOW); //turn off


   delay(1950);
   
   digitalWrite(transistorPin, HIGH); //turn on
   digitalWrite(transistorPin1, HIGH); //turn on


   delay(3700);
   
   digitalWrite(transistorPin, LOW); //turn off
   digitalWrite(transistorPin1, LOW); //turn off
}

AWOL

Your code never "stops".

As soon as it hits the end of "loop", it gets called again, so every 30 seconds or so, the sketch repeats.
I can see no reason assume it stops and has to be uploaded again.

If you want to implement a pause, you'll need to get rid of the delays and use the serial.available function to check for incoming serial messages.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

cyclegadget

I have seen your posts before so, I am guessing that this is your motor/tank project.

The last 2 lines of code shown below turn of the transistors for a very short moment that you will not likely be able to see because the loop repeats and you immediately turn the transistors back on.

Code: [Select]
digitalWrite(transistorPin, LOW); //turn off
   digitalWrite(transistorPin1, LOW); //turn off


Add a delay to the very end of the sketch, after the last two lines.
Code: [Select]
digitalWrite(transistorPin, LOW); //turn off
   digitalWrite(transistorPin1, LOW); //turn off
    delay(2700);
Good links: Eagle tutorial= http://www.youtube.com/playlist?list=PLDE1858BD83D19C70
General Arduion tutorials = http://tronixstuff.wordpress.com
http://www.gammon.com.au/forum/bbshowpost.php?bbtopic_id=123

SirNickity

A simple way to implement your stop/start would be to put in a toggle switch.  If it's on, the sketch runs.  If it's off, the sketch stops.  Check the switch status in between between the movements.  (Or better yet, set up a for loop that goes through an array of movements and delay times, and check the switch as part of your for loop.)

PaulS

Code: [Select]
digitalWrite(transistorPin, LOW); //turn off
   digitalWrite(transistorPin1, LOW); //turn off

transistorPin1 and transistorPin2 would make a lot more sense.

Go Up