Rev 1.6 - Sample Period Work in progress

Dependencies:   mbed Bitmap N5110 TMP102 Joystick

main.cpp

Committer:
louismarr
Date:
2021-12-04
Revision:
1:5cdfc8d78097
Parent:
0:f8a8c6a8a5c3
Child:
2:94cc00f20883

File content as of revision 1:5cdfc8d78097:

/*
@Acknowledgements to Craig A.Evans for TMP102 Library reading temperatures

*/ 
/*============================ Libraries =====================================*/
#include "mbed.h"                                                               // Including Mbed OS Header File Libraries
#include "TMP102.h"                                                             // Including Tmp102 Header File Libraries


/*============================ Variables =====================================*/
//Serial
TMP102 Tmp_I2C(PTE25,PTE24);                                                    //Establishing TMP102 I2C Sensor (I2C_SDA(PTE25),I2C_SCL(PTE24)
Serial serial(USBTX,USBRX);                                                     //Serial Port 

//Outputs                                                                                
DigitalOut Red_DO(LED_RED);                                                     // K64F on-board LEDs 
DigitalOut Grn_DO(LED_GREEN);
DigitalOut Blue_DO(LED_BLUE);
//Inputs
InterruptIn Sw2_DI(SW2);                                                        // K64F on-board switches
InterruptIn Sw3_DI(SW3);

/*=========================== Void Functions =================================*/

void error();                                                                   // error function flashing blue LED from TMP102.cpp and prints Error State to CoolTerm

void init_serial();                                                             // Serial port setup

void init_K64FSetup();                                                          // Disabling on-board LEDs and switches

/*============================ Main Code =====================================*/
int main()
{
    serial.baud(9600);

    init_K64FSetup();                                                           // Initiliasing the Void Functions into the main code
    init_serial(); 
    error();
    
    Tmp_I2C.init();                                                             // I2C Sensor Initialising
    
    while (1) {
        
        float T = Tmp_I2C.get_temperature();                                    // Read Temp from I2C Sensor
        serial.printf("T = %f C\n",T);                                          // Print Value over CoolTerm
        
        wait(1.0);                                                              // small delay - 1s to match the update rate of the sensor (1 Hz)
        
    }
}

/*=============================== Void Setup =================================*/

void init_serial() {
    // set to highest baud - ensure terminal software matches
    serial.baud(9600); 
}

void init_K64FSetup() 
{
                                                                                
    Red_DO = 1;                                                                 // on-board LEDs are active-low, so set pin high to turn them off.
    Grn_DO = 1;
    Blue_DO = 1;   
                                                                                                                                                                    
    Sw2_DI.mode(PullNone);                                                      // since the on-board switches have external pull-ups, we should disable the internal pull-down
    Sw3_DI.mode(PullNone);                                                      // resistors that are enabled by default using InterruptIn

}
void error(){
    serial.baud(9600);                                                          // Serial Baud Rate
    serial.printf("Error State");                                               // Error Print Message
}