Pages: [1]   Go Down
Author Topic: Stopping, Starting  (Read 717 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 299
Posts: 26195
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
it runs perfectly until my program finishes
What program would that be?
Logged

"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.

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 299
Posts: 26195
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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)
Logged

"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.

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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
 }
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 299
Posts: 26195
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

"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.

Greenville, IL
Offline Offline
Edison Member
*
Karma: 15
Posts: 1330
Warning Novice on board! 0 to 1 chance of errors!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 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:
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:
digitalWrite(transistorPin, LOW); //turn off
   digitalWrite(transistorPin1, LOW); //turn off
    delay(2700);
Logged


Anchorage, AK
Offline Offline
Edison Member
*
Karma: 42
Posts: 1176
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.)
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 49034
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
digitalWrite(transistorPin, LOW); //turn off
   digitalWrite(transistorPin1, LOW); //turn off
transistorPin1 and transistorPin2 would make a lot more sense.
Logged

Pages: [1]   Go Up
Jump to: