Sample Eddystone Beacon Switch Code (Seeed Platform)

Dependencies:   BLE_API mbed nRF51822

main.cpp

Committer:
roywant
Date:
2015-09-26
Revision:
2:fc105f4c854e
Parent:
0:fb6bbc10ffa0
Child:
3:bfd6f56605d7

File content as of revision 2:fc105f4c854e:

#include "mbed.h"
#include "BLEDevice.h"
#include "DeviceInformationService.h"


InterruptIn button1(P0_17);
InterruptIn mysw1(P0_18);
DigitalOut myled1(P0_12);
DigitalOut myled2(P0_15);
DigitalOut myled3(P0_16);
// Serial pc(USBTX,USBRX);
int count = 0;
int flag = false;

// Callback for button1
void handle_sensor() {
    count++;
    myled2 = !myled2;
}

void handle_sw1() {
    flag = !flag;
    }


void ledflasher() {
        myled1 = 1;
        wait(0.3);
        myled1 = 0;
        myled2 = 1;
        wait(0.3);
        myled2 = 0;
        myled3 = 1;
        wait(0.4);   
        myled3 = 0; 
    }

int main() {
    // Initialize button1 and pull up
    // set interrupt callback for button1    
    button1.fall(&handle_sensor);
    mysw1.fall(&handle_sw1);
    button1.mode(PullUp);
    mysw1.mode(PullUp);
    myled1 = 0;
    myled2 = 0;
    myled3 = 0;

    while(1) {
        if (flag) {
            ledflasher();
        }
        wait(0.2);
    }
    
    
    
}