version2...

Dependencies:   mbed

main.cpp

Committer:
tsillen
Date:
2015-04-16
Revision:
3:d015f636e4e3
Parent:
1:4a28329e243f

File content as of revision 3:d015f636e4e3:

#include "mbed.h"
//#include "iostream"
#include "stdio.h"
#include "stdlib.h"

using namespace std;

Serial xbee1(PA_2, PA_3);
//DigitalOut rst1(p11);
DigitalOut myled(LED1);
DigitalIn mybutton(USER_BUTTON);

int counter = 0;
void sendsignal();
void receivesignal(int bericht);

int main()
{
    while(1) {
        if(xbee1.readable()) {
            int message = xbee1.getc(); //XBee read
            receivesignal(message);
        }
        if (mybutton == 0) { //if button pressed
            sendsignal();
        }
    }
}

void sendsignal()
{
    if(counter == 0) {
        xbee1.putc(counter); //XBee write
    }
    if (counter == 1) {
        xbee1.putc(counter);
        counter = 0;
    }
}

void receivesignal(int  bericht)
{
    if (bericht == 0) {
        //make button signal x
        myled = 1; // LED is ON
        wait(0.1); // 200 ms
        myled = 0; // LED is OFF
        wait(0.1); // 1 sec
        myled = 1;
        wait(0.1);
        myled = 0;
        wait(0.4);
    }
    if (bericht == 1) {
        myled = 1; // LED is ON
        wait(1.0); // 200 ms
        myled = 0; // LED is OFF
        wait(1.0); // 1 sec
    }
}