![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Xbee-Smart-Home-Inside RX Test
Dependencies: Si7021 mbed-rtos JPEGCamera mbed
Fork of Xbee-Smart-Home-Inside by
main.cpp
- Committer:
- pkoirala3
- Date:
- 2017-04-17
- Revision:
- 1:e9068d048f58
- Parent:
- 0:5b1386641010
- Child:
- 2:21031e885513
File content as of revision 1:e9068d048f58:
#include "mbed.h" #include "rtos.h" #include "JPEGCamera.h" AnalogIn ambient(p15); Mutex getMutex; Mutex putMutex; Thread t1; Thread t2; Serial xbee1(p9, p10); //Creates a variable for serial comunication through pin 9 and 10 JPEGCamera camera(p13, p14); // TX, RX DigitalOut rst1(p8); //Digital reset for the XBee, 200ns for reset DigitalOut myled(LED3);//Create variable for Led 3 on the mbed DigitalOut myled2(LED4);//Create variable for Led 4 on the mbed Serial pc(USBTX, USBRX);//Opens up serial communication through the USB port via the computer int main() { rst1 = 0; //Set reset pin to 0 myled = 0;//Set LED3 to 0 myled2= 0;//Set LED4 to 0 wait_ms(1);//Wait at least one millisecond rst1 = 1;//Set reset pin to 1 wait_ms(1);//Wait another millisecond while (1) {//Neverending Loop if (pc.readable()) {//Checking for serial communication myled = 0; //Turn Led 3 Off if(xbee1.putc(pc.getc()) == EOF){} //XBee write whatever the PC is sending else {myled = 1;} //Turn Led 3 on for succcessfull communication } } t1.start(callback(ambient_sensor()); } void ambinet_sensor(){ float amb_val = ambient(); // Scale to proper unit putMutex.lock(); xbee.puts(amb_val); putMutex.unlock(); } void cameraThread(){ LocalFileSystem local("local"); //save images on mbed camera.setPictureSize(JPEGCamera::SIZE160x120); while(1){ if (camera.isReady()){ char filename[32]; sprintf(filename, "/local/pict.jpg"); printf("Picture: %s ", filename); if (camera.takePicture(filename)) { while (camera.isProcessing()) { camera.processPicture(); } break; } } } }