homework 1 exercise 8

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 DigitalOut led(LED_RED);
00004 InterruptIn button(SW2);
00005 Serial pc(USBTX, USBRX, "YOLO");
00006 
00007 volatile int count = 1;
00008 
00009 void flash(DigitalOut out) {
00010     out.write(false);
00011     wait(0.2f);
00012     out.write(true);
00013     wait(0.5f);
00014 }
00015 
00016 void onPress() {
00017     pc.printf("Number of flashes: %d\r\n", count);
00018     for (int i = 0; i < count; i++) {
00019         flash(led);
00020     }
00021     count++;
00022 }
00023 
00024 int main()
00025 {
00026     led.write(true);
00027     
00028     pc.baud(115200);
00029     pc.printf("Hello World!\r\n");
00030     
00031     button.fall(&onPress);    
00032     
00033     while (true);
00034 }