Syntax help need

15 Apr 2012

Greetings, I'm having a tough time with this. In the function tStopFun, the if statement will not increment the second variable in the list. I have tried while loops as an alternative with no luck

#include "mbed.h"



//-----------------Declarations-----------------------------------------------------------------


Serial pc(USBTX, USBRX); // tx, rx

InterruptIn sw1(p17);

Timer t;

PwmOut Spot(p25);
PwmOut Wide(p26);
AnalogIn ADC(p16);





//---------------Variables---------------------------------------------------------------

float dimvalS (0.0);
float dimvalW (0.0);
float tval;
float ADCval;
//---------------Functions-------------------------------------------------------------------


void tStartFun() {    //function attached to interrupt
    t.start();
    wait_us(200);
}

void tStopFun() {
    t.stop();
    tval = (t.read_ms());

    if ((tval > 0.1) && (tval < 800.0 )) {
        dimvalS = dimvalS + 0.33;
        dimvalW = dimvalW + 0.33;

        t.reset();
    }



    else if (tval > 900.0)
        dimvalS = 0.0;
        dimvalW = 0.0;

         t.reset();

   

}


int main() {



// PWM period in micro seconds
    Spot.period_ms(1);// PWM pulsewidth in milliseconds (1khz)
    Wide.period_ms(1);

    sw1.rise(&tStartFun);  // attach the address of the function to the rising edge
    sw1.fall(&tStopFun);

    while (1) {


        Spot = (dimvalS);
        Wide = (dimvalW);


        ADCval = ADC;

        pc.printf ("Spot %f Wide %f ADC %f \r\n ",dimvalS,dimvalW,ADCval);
        //wait_ms(100);

        if (dimvalS > 1.0) {
            dimvalS = (0.33);
        }

        if (dimvalW > 1.0) {
            dimvalW = (0.33);
        }


    }
}

Thanks for any advice