limit switch example

Dependencies:   mbed

main.cpp

Committer:
glintligo
Date:
2018-07-17
Revision:
2:fd4ab491b054
Parent:
1:fe798c459fdb

File content as of revision 2:fd4ab491b054:

#include "mbed.h"

PwmOut mypwm0(PB_0);
PwmOut mypwm1(PB_1);
InterruptIn button(PB_3);
DigitalOut myled(LED1);
void stop();

int main() {
  //  button.rise(&stop);
    mypwm0.period_ms(10);
    mypwm0.pulsewidth_ms(8);
    mypwm1.period_ms(10);
    mypwm1.pulsewidth_ms(0);
    while(1) {
        myled = !myled;
        wait(1);
    }
}

void stop()
{   wait(0.01);
    if(button.read() == 1){
    mypwm0.write(0); 
    mypwm1.write(0);
    }  
}