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:
2:469b3daa6b98
Parent:
1:f99510926784
Child:
3:5efd78be4662

File content as of revision 2:469b3daa6b98:

#include "mbed.h"

InterruptIn interruptor(D2);

float offset=34.14f;
float def_ignition=26.13f;


class IgnMod
{
private:
    Timeout ignition_timer;
    Timer t;

    DigitalOut *pin;

    int ignition_length;
    int round_time;
    int ignition_delay;

    void on() {
        pin->write(1);
        ignition_timer.attach_us(this,&IgnMod::off,ignition_length);
    }
    void off() {
        pin->write(0);
    }

    int get_delay(int round_time) {
        return round_time*(offset-def_ignition)/360;
    }
public:
    IgnMod() {
        ignition_length=100;
        DigitalOut pin(D3);
        t.start();
    }
    void ignite() {
        round_time=t.read_us();
        t.reset();
        ignition_delay=get_delay(round_time);
        ignition_timer.attach_us(this,&IgnMod::on,ignition_delay-t.read_us());
    }
};

IgnMod ignition;

int main()
{
    interruptor.mode(PullUp);
    interruptor.rise(&ignition,&IgnMod::ignite);
    while(1) {        
    }
}