programmable ignition for an mz ts 150. The interruptor needs to be replaced by an hall effect sensor

Dependencies:   mbed

main.cpp

Committer:
johannes_otto
Date:
2015-10-13
Revision:
1:f99510926784
Parent:
0:46797506f6f3
Child:
2:469b3daa6b98

File content as of revision 1:f99510926784:

#include "mbed.h"

InterruptIn interruptor(D2);
Timer t;
DigitalOut ignition(D3);
Timeout ignition_timer;

int round_time;
float offset=34.14f;
float def_ignition=26.13f;
int ign_delay;


int ignition_length=100;
int ignition_delay;

int get_delay(int round_time)
{
    return round_time*(offset-def_ignition)/360;
}

void ignition_off()
{
    ignition=0;
}

void ignition_on()
{
    ignition=1;
    ignition_timer.attach_us(&ignition_off,ignition_length);
}

void ignite()
{
    round_time=t.read_us();
    t.reset();
    ignition_delay=get_delay(round_time);
    ignition_timer.attach_us(&ignition_on,ignition_delay-t.read_us());
}


void setup()
{
    interruptor.mode(PullUp);
    t.reset();
    t.start();
}


int main()
{
    setup();
    while(1) {
        interruptor.rise(&ignite);
    }
}