help with stopwatch, Pushbutton, FSR


hi, im playing around the stopwatch code on site.

i want frs activate , deactivate stopwatch on condition push button has been pressed 1st. (i.e standby switch)

the fsr working atm. part of code have added pushbutton has no effect.

if point me in right direction mcuh appreciated

many :)


/* stopwatch
* paul badger 2008
* demonstrates using millis(), pullup resistors,
* making 2 things happen @ once, printing fractions
*
* physical setup: momentary switch connected pin 4, other side connected ground
* led series resistor between pin 13 , ground
*/


#define ledpin  13                  // led connected digital pin 13
#define fsrpin 2                    
#define buttonpin 4                 // button on pin 4

int value = low;                    // previous value of led
int buttonstate;                    // variable store button state
int lastbuttonstate;                // variable store last button state
int fsrstate;                    // variable store button state
int lastfsrstate;  
int blinking;                       // condition blinking - timer timing
long interval = 100;                // blink interval - change suit
long previousmillis = 0;            // variable store last time led updated
long starttime ;                    // start time stop watch
long elapsedtime ;                  // elapsed time stop watch
                                   // variable used store fractional part of time
float t;


void setup()
{
  serial.begin(9600);

  pinmode(ledpin, output);         // sets digital pin output

  pinmode(fsrpin, input);       // not necessary, pins default input anyway
  analogwrite(fsrpin, high);   // turn on pullup resistors. wire button press shorts pin ground.
  pinmode(buttonpin,input);
  digitalwrite (buttonpin, high);
}

void loop()
{
   // check button press
  buttonstate = digitalread(buttonpin);                   // read button state , store
  fsrstate = analogread (fsrpin);
 
 if (buttonstate == low && lastbuttonstate == high && fsrstate == false){
    serial.print("press fsr!! ");
    delay (1000);
    lastbuttonstate = buttonstate;
 }
 else if (buttonstate == low && lastbuttonstate == high && fsrstate == true){      
    serial.print("ready!! ");
    delay (1000);
    lastbuttonstate = buttonstate;    
 }
 
  if (fsrstate == 0 && lastfsrstate >= 1  &&  blinking == false){     // check high low transition
     // if true found new button press while clock not running - start clock
     
     starttime = millis();                                   // store start time
     blinking = true;                                     // turn on blinking while timing
     delay(5);                                               // short delay debounce switch
     lastfsrstate = fsrstate;                          // store fsrstate in lastfsrstate, compare next time

}

  else if (fsrstate == 0 && lastfsrstate >= 1 && blinking == true){     // check high low transition
     // if true found new button press while clock running - stop clock , report

       elapsedtime =   millis() - starttime;              // store elapsed time
       blinking = false;                                  // turn off blinking, done timing
       lastfsrstate = fsrstate;                     // store buttonstate in lastbuttonstate, compare next time

      // routine report elapsed time
       serial.print("time: ");
       serial.print("\t");
       serial.println( (int)(elapsedtime));         // divide 1000 convert seconds - cast int print
       delay(1000);
         
 
     
      t =((elapsedtime)/2.00); // print time divided 2
      serial.print("t=");
      serial.println(t);
      delay(5);
     

  }

  else{
     lastfsrstate = fsrstate;                         // store buttonstate in lastbuttonstate, compare next time
  }

  // blink routine - blink led while timing
  // check see if it's time blink led; is, difference
  // between current time , last time blinked led larger than
  // interval @ want blink led.

  if ( (millis() - previousmillis > interval) ) {

     if (blinking == true){
        previousmillis = millis();                         // remember last time blinked led

        // if led off turn on , vice-versa.
        if (value == low)
           value = high;
        else
           value = low;
        digitalwrite(ledpin, value);
     }
     else{
        digitalwrite(ledpin, low);                         // turn off led when not blinking
     }
  }
}




now, go click on "modify", highlight code in post, click on "#" (code) button on editor toolbar.
there.
doesn't nicer?

(not sure financial status report you, though)

code: [select]
analogwrite(fsrpin, high);   // turn on pullup resistors. wire button press shorts pin ground.
explain, please?

code: [select]
fsrstate = analogread (fsrpin);

if (buttonstate == low && lastbuttonstate == high && fsrstate == false){
chances of analogread returning value 0 (false) not good, unless pin solidly grounded.


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > help with stopwatch, Pushbutton, FSR


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums