Miha Bokan / Mbed 2 deprecated FRDM-KL46Z-LAB2_C

Dependencies:   MMA8451Q USBDevice mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main_lab1.cpp Source File

main_lab1.cpp

00001 //USB Academy - Lab1 rev 01
00002 //_____________________________________________________________//
00003 //======== INCLUDES ===========================================//
00004 //¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯//
00005 #include "mbed.h"
00006 #include "USBSerial.h"
00007 #include "MMA8451Q.h" 
00008 
00009 //_____________________________________________________________//
00010 //======== DEFINES & VARIABLES ================================//
00011 //¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯//
00012 USBSerial serial;
00013 
00014 #define MMA8451_I2C_ADDRESS (0x1d<<1) 
00015 MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS);
00016 
00017 DigitalIn sw1(PTC3); // switch SW1 
00018 DigitalIn sw3(PTC12); // switch SW2
00019 
00020 #define ON  0 //switch "ON" detection; LED "ON" state 
00021 #define OFF 1 //switch "OFF" detection; LED "OFF" state 
00022 
00023 //======== Data Structure ====================================//
00024 struct KL46_SENSOR_DATA {
00025     int   sw1State;
00026     int   sw3State;
00027     float   accValX;
00028     float   accValY;
00029     float   accValZ;
00030 } sensorData;
00031 #define sD sensorData
00032 
00033 //_____________________________________________________________//
00034 //======== MAIN() =============================================//
00035 //¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯// 
00036 int main(void)
00037 {
00038   //====== MAIN/Initialisation ================================//
00039   
00040   sw1.mode(PullUp); sw3.mode(PullUp);
00041   
00042   while (1)
00043   {
00044     //====== MAIN/While loop/Sensing data =====================//
00045 
00046     sD.sw1State = sw1; 
00047     sD.sw3State = sw3;
00048     sD.accValX = acc.getAccX(); //accX[-1..1]
00049     sD.accValY = acc.getAccY(); //accY[-1..1]
00050     sD.accValZ = acc.getAccZ(); //accZ[-1..1]
00051      
00052      //====== MAIN/While loop/Data sending =====================//
00053      
00054      
00055      wait(0.05); // wait 50ms
00056   }
00057 }