Possible (small) issue with tIcker function (attach/attach_us)

18 Apr 2014

If I run the following code, led 1 blinks at 10Hz.

#include "mbed.h"

DigitalOut led1(LED1);
void tickerfunction();

int main() {
    Ticker t;
    t.attach(&tickerfunction, 0.1);
    while(1) {
        wait(1);
    }
}

void tickerfunction(){
    led1=!led1;
}

If I change the code (t.attach(&tickerfunction, 1/10)), the led stops blinking.

#include "mbed.h"

DigitalOut led1(LED1);
void tickerfunction();

int main() {
    Ticker t;
    t.attach(&tickerfunction, 1/10);
    while(1) {
        wait(1);
    }
}

void tickerfunction(){
    led1=!led1;
}

Anything I'm not fully understanding that can cause this?

18 Apr 2014

Allright, hah.. Quick solution here. An integer divided by an integer equals an integer. Changing from 1/10 to 1.0/10 fixed my "issue".

#include "mbed.h"
 
DigitalOut led1(LED1);
void tickerfunction();
 
int main() {
    Ticker t;
    t.attach(&tickerfunction, 1.0/10);
    while(1) {
        wait(1);
    }
}
 
void tickerfunction(){
    led1=!led1;
}