![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Rev 1.6 - Sample Period Work in progress
Dependencies: mbed Bitmap N5110 TMP102 Joystick
main.cpp
- Committer:
- louismarr
- Date:
- 2021-12-04
- Revision:
- 0:f8a8c6a8a5c3
- Child:
- 1:5cdfc8d78097
File content as of revision 0:f8a8c6a8a5c3:
/* 2645_I2C_TMP102_Library Sample code from ELEC2645 Week 17 Lab Demonstrates how to re-factor the TMP102 code into a library (c) Craig A. Evans, University of Leeds, Feb 2016 */ #include "mbed.h" // include the library header, ensure the library has been imported into the project #include "TMP102.h" // Create TMP102 object TMP102 Tmp_I2C(I2C_SDA,I2C_SCL); // UART connection for PC Serial pc(USBTX,USBRX); // K64F on-board LEDs DigitalOut Red_DO(LED_RED); DigitalOut Grn_DO(LED_GREEN); DigitalOut Blue_DO(LED_BLUE); // K64F on-board switches InterruptIn Sw2_DI(SW2); InterruptIn Sw3_DI(SW3); // error function hangs flashing an LED void error(); // setup serial port void init_serial(); // set-up the on-board LEDs and switches void init_K64F(); int main() { // initialise the board and serial port init_K64F(); init_serial(); // call the sensor init method using dot syntax Tmp_I2C.init(); while (1) { // read temperature and print over serial port float T = Tmp_I2C.get_temperature(); pc.printf("T = %f K\n",T); // small delay - 1s to match the update rate of the sensor (1 Hz) wait(1.0); } } void init_serial() { // set to highest baud - ensure terminal software matches pc.baud(115200); } void init_K64F() { // on-board LEDs are active-low, so set pin high to turn them off. Red_DO = 1; Grn_DO = 1; Blue_DO = 1; // since the on-board switches have external pull-ups, we should disable the internal pull-down // resistors that are enabled by default using InterruptIn Sw2_DI.mode(PullNone); Sw3_DI.mode(PullNone); }