blablabla

Dependencies:   MAG3110 MMA8451Q SLCD- TSI USBDevice mbed

main_lab2a_begin.txt

Committer:
Osator
Date:
2014-04-16
Revision:
0:339b7abfa147

File content as of revision 0:339b7abfa147:

//USB Academy - Lab2 rev 00
//_____________________________________________________________//
//======== INCLUDES ===========================================//
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯//
#include "mbed.h"
#include "MMA8451Q.h"
//#include "MAG3110.h"
//#include "SLCD.h"
//#include "TSISensor.h"

//#include "USBMouse.h" //Lab1-Hid
//#include "USBSerial.h" //Lab2-cdc
//#include "USBHostMSD.h" //Lab3-Msd





//_____________________________________________________________//
//======== DEFINES & VARIABLES ================================//
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯//
#define LED_ON  0 //outON, pwmON
#define LED_OFF 1 //outOFF,pwmOFF
DigitalOut gLED(LED_GREEN); //PTD5

#define rLEDperiod 150      //[ms]
PwmOut rLED(LED_RED);       //PTE29

#define PRESS_ON  0
#define PRESS_OFF 1
DigitalIn  sw1(PTC3);  //if(sw1) Release else Press
DigitalIn  sw3(PTC12); //while(sw3); wait for Press

#define MMA8451_I2C_ADDRESS (0x1d<<1)
MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS);

struct KL46_SENSOR_DATA {
    int   sw1State;
    int   sw3State;
    float   accValX;
    float   accValY;
    float   accValZ;
} sensorData;
#define sD sensorData




//_____________________________________________________________//
//======== MAIN() =============================================//
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯//
int main(void)
{
    //---- MAIN/Inits -----------------------------------------//
    
    sw1.mode(PullUp);
    sw3.mode(PullUp);
    
    gLED = LED_ON; //Green LED ON to indicate running/writing
    rLED = LED_OFF; //Red LED OFF
    rLED.period(rLEDperiod); //Red LED (rLED) tsi/accZ/mag
    
    //---- MAIN/Inits (Wait4SW1) -> Start! --------------------//   
    
    //---- MAIN/Inits Interface -------------------------------//
    
    //---- MAIN/Inits Labs ------------------------------------//
    
    //---- MAIN/Inits (Wait4SW1) -> Calib. eCompass -----------//
    
    //---- MAIN/Inits Done! (Wait4SW1) -> MANI/Loop -----------//
    
    gLED = LED_OFF; //Inits are done

    //---- MAIN/Loop  -----------------------------------------//
    while (1) {
        
        // MAIN/Loop/Sensing and Storing data -----------------//
        sD.sw1State = sw1; sD.sw3State = sw3;
        sD.accValX = acc.getAccX(); //accX[-1..1]->mouse (Lab1)
        sD.accValY = acc.getAccY(); //accY[-1..1]->mouse (Lab1)
        sD.accValZ = acc.getAccZ(); //accZ[-1..1]->rLED
        
        // MAIN/Loop/Processing and Actions -------------------//
        
        //acc: z-axis 1g min-blinking//acc: z-axis 1g min-blinking
        rLED = abs(sD.accValZ);
        
        wait(0.05); //wait 50ms
    }
}





//_____________________________________________________________//
//======== FUNC() =============================================//
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯//