Bryce Himebaugh / Mbed 2 deprecated NOAC-STEM

Dependencies:   ADXL362 TSL2561 mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 /*------------------------------------------------------------------------------
00004 Before to use this example, ensure that you an hyperterminal installed on your
00005 computer. More info here: https://developer.mbed.org/handbook/Terminals
00006 
00007 The default serial comm port uses the SERIAL_TX and SERIAL_RX pins (see their
00008 definition in the PinNames.h file).
00009 
00010 The default serial configuration in this case is 9600 bauds, 8-bit data, no parity
00011 
00012 If you want to change the baudrate for example, you have to redeclare the
00013 serial object in your code:
00014 
00015 Serial pc(SERIAL_TX, SERIAL_RX);
00016 
00017 Then, you can modify the baudrate and print like this:
00018 
00019 pc.baud(115200);
00020 pc.printf("Hello World !\n");
00021 ------------------------------------------------------------------------------*/
00022 
00023 DigitalOut led(LED1);
00024 
00025 int main()
00026 {
00027     int i = 1;
00028 
00029     printf("Hello World !\n");
00030 
00031     while(1) {
00032         wait(1); // 1 second
00033         led = !led; // Toggle LED
00034         printf("This program runs since %d seconds.\n", i++);
00035     }
00036 }
00037 
00038 
00039 /* #include "mbed.h"
00040 #include "ADXL362.h"
00041  
00042 ADXL362 adxl362(D9);
00043  
00044 int main() {
00045     
00046     adxl362.reset();
00047     wait_ms(600); // we need to wait at least 500ms after ADXL362 reset
00048     adxl362.set_mode(ADXL362::MEASUREMENT);
00049     uint8_t x,y,z; 
00050     while(1) {
00051         x=adxl362.scanx_u8();
00052         y=adxl362.scany_u8();
00053         z=adxl362.scanz_u8();
00054         printf("x = %x y = %x z = %x\r\n",x,y,z);
00055         wait_ms(100);
00056     }
00057 }
00058  
00059  #include "mbed.h"
00060 #include "TSL2561.h"
00061  
00062 Serial PC(USBTX, USBRX);
00063  
00064 #define PC_PRINTX(z,x)             if(z==1) PC.printf(x);
00065 #define PC_PRINTLNX(z,x)           if(z==1) {PC.printf(x);        PC.printf("\r\n");}
00066 #define PC_PRINTXY(z,x, y)         if(z==1) PC.printf(x, y);
00067 #define PC_PRINTLNXY(z,x, y)       if(z==1) {PC.printf(x, y);     PC.printf("\r\n");}
00068  
00069 DigitalOut myled(LED1);
00070 TSL2561 tsl2561(TSL2561_ADDR_FLOAT);
00071  
00072 Timer setuptimer;
00073 Timer executetimer;
00074  
00075 void setup(void){
00076  
00077     if (tsl2561.begin()) {    
00078         PC_PRINTLNX(1,"TSL2561 Sensor Found");        
00079     } else {    
00080         PC_PRINTLNX(1,"TSL2561 Sensor not Found");   
00081     }
00082     
00083     // You can change the gain on the fly, to adapt to brighter/dimmer tsl2561 situations
00084   tsl2561.setGain(TSL2561_GAIN_0X);         // set no gain (for bright situtations)
00085   //tsl2561.setGain(TSL2561_GAIN_16X);      // set 16x gain (for dim situations)
00086   
00087   // Changing the integration time gives you a longer time over which to sense tsl2561
00088   // longer timelines are slower, but are good in very low tsl2561 situtations!
00089   //tsl2561.setTiming(TSL2561_INTEGRATIONTIME_13MS);  // shortest integration time (bright tsl2561)
00090   //tsl2561.setTiming(TSL2561_INTEGRATIONTIME_101MS);  // medium integration time (medium tsl2561)
00091   tsl2561.setTiming(TSL2561_INTEGRATIONTIME_402MS);  // longest integration time (dim tsl2561)
00092   
00093   // Now we're ready to get readings!
00094 }
00095  
00096 int main() {  
00097     
00098     PC_PRINTLNX(1,"----------START-------------");
00099     setuptimer.start();
00100     setup();    
00101     setuptimer.stop();
00102     PC_PRINTLNXY(1,"Setup time: %f",setuptimer.read());
00103     setuptimer.reset();
00104     
00105     uint16_t x,y,z;
00106       
00107     while(1) {      
00108     
00109        
00110         // Simple data read example. Just read the infrared, fullspecrtrum diode 
00111         // or 'visible' (difference between the two) channels.
00112         // This can take 13-402 milliseconds! Uncomment whichever of the following you want to read
00113         
00114         executetimer.start();
00115         x = tsl2561.getLuminosity(TSL2561_VISIBLE);     
00116         y = tsl2561.getLuminosity(TSL2561_FULLSPECTRUM);
00117         z = tsl2561.getLuminosity(TSL2561_INFRARED);
00118         executetimer.stop();
00119         
00120         PC_PRINTLNXY(1,"Visible: %d",x);
00121         PC_PRINTLNXY(1,"Full Spectrum: %d",y);
00122         PC_PRINTLNXY(1,"Infrared: %d",z);
00123         PC_PRINTLNXY(1,"Execution Time: %f",executetimer.read());
00124         executetimer.reset();
00125         
00126         //More advanced data read example. Read 32 bits with top 16 bits IR, bottom 16 bits full spectrum
00127         //That way you can do whatever math and comparisons you want!
00128          // uint32_t lum = tsl2561.getFullLuminosity();
00129        // uint16_t ir, full;
00130       //  ir = lum >> 16;
00131       //  full = lum & 0xFFFF;
00132   
00133      //   PC_PRINTLNXY(1,"Visible: %d",full - ir);
00134      //   PC_PRINTLNXY(1,"Full Spectrum: %d",full);
00135      //   PC_PRINTLNXY(1,"Infrared: %d",ir);  
00136   
00137     //    wait(1);
00138      PC_PRINTLNX(1,"----------COMPLETE-------------");
00139     }
00140 }
00141 
00142 */ 
00143  
00144