Pages: [1]   Go Down
Author Topic: Timing how long a variable is not zero  (Read 532 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have created a sketch which contain an array of 6 values that change based upon serial input, 0 is the default value for all the slices in the array. When a value in the array is not 0 I need to be able to count how long this is true and reset the value to 0 after a predetermined amount of time.

Does anyone know of a good jumping off point for me? I'm looking at the debounce tutorial to help me but I'm not quite there yet, any pointers you might be able to offer me?
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16523
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I'm looking at the debounce tutorial

\
Debouncing has to do with dealing with physical switch contacts that 'bounce' and the problems that they can cause. What would that have to do with incoming serial characters and timing there values in your storage array?


Lefty
Logged

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

Im using debounce to get a grip on how how to compare times as this is the first time I have dealt with time based functions in arduino. Thanks for the pointers ill see what i can do.
« Last Edit: June 20, 2011, 12:23:16 pm by acrossell » Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 170
Posts: 12465
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

create an array of stopwatches ... - http://www.arduino.cc/playground/Code/StopWatchClass -
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

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

thanks rob ill have a look at that.


Ive tried this but dont have my board to hand to test it. Im only trying to change one of the index's at the minute but am i steering in the right direction?

Code:
while (Serial.available() == 0)  {
    array1[0] = 0;
    array1[1] = 0;
    array1[2] = 0;
    array1[3] = 0;
    array1[4] = 0;
    array1[5] = 0; //all motors off if serial not available, prevents startup errors
  }                            
 
    
  if (Serial.available() >= 6)  {
   for ( int i = 0; i < 6; i++)
   array1[i]= Serial.read() ;   //send serial values to array 1
    }
  
  while (array1[0] != 0); {
   start = millis(); //take the start time of motor on array1[0]
  }
  
  if ((millis() - start) > maxtime); {
   array1[0] = 0;
  }
« Last Edit: June 20, 2011, 02:44:07 pm by acrossell » Logged

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

thanks thats great, but just for my own learning would my very basic attempt work? If not, why not?
Logged

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

Thanks for your help. Ive looked over your suggested code and I can see how that works. Thanks  smiley
Logged

Pages: [1]   Go Up
Jump to: