You are on page 1of 2

/*Program 6: PWM*/ #include "mbed.

h"

PwmOut PWM1(p21);// create a PWM output called PWM1 on pin21

int main() { PWM1.period(1); //set PWM period to 10 ms while(1) {

//PWM1.pulsewidth(5); //set PWM pulse width to 5 ms PWM1=0.5; //set duty cycle to 50%

} }

/*Program 9 Interrupt*/ #include "mbed.h"

InterruptIn button(p5); DigitalOut led(LED1); DigitalOut flash(LED4);

void ISR1(){//this is the response to the interrupt, i.e. the ISR led = !led;

int main() {

button.rise(&ISR1); // attach the address of ISR function to the interrupt rising edge while(1) {// continuous loop ready to be interrupted flash=!flash; wait(1); } }

You might also like