![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Working Menu, additions to be made
Dependencies: mbed
Diff: main.cpp
- Revision:
- 4:143487eef742
- Parent:
- 3:d1e1de4a712e
- Child:
- 5:bec67fb2b2f9
--- a/main.cpp Fri Jan 21 09:37:37 2022 +0000 +++ b/main.cpp Fri Jan 28 09:37:53 2022 +0000 @@ -1,100 +1,121 @@ -/* -Code for a IoT Temperature reading device. -Acknowledgements to Dr Craig A. Evans and Dr Edmond Nurellari. -**/ +/* +* Author - Jack McGarley - 18689007 +* Date - January 2022 +* Acknowledgements +* Craig A. Evans, University of Leeds, TMP102 Library, Feb 2016 +* Dr Edmond Nurellari, University of Lincoln, Joystick & N5110 Libraries +*/ -#include "mbed.h" -#include "N5110.h" -#include "Joystick.h" +#include "mbed.h" // include the library header, ensure the library has been imported into the project +#include "Joystick.h" #include "TMP102.h" +#include "N5110.h" -//Defines -AnalogIn pot(PTB2); +DigitalOut grn_led1(PTA1); // Designating LEDs from left to right +DigitalOut grn_led2(PTA2); +DigitalOut grn_led3(PTC2); +DigitalOut red_led1(PTC3); +DigitalOut red_led2(PTC4); +DigitalOut red_led3(PTD3); + -//LCD Sprite: -// rows,cols -int sprite[8][5] = { - { 0,0,1,0,0 }, - { 0,1,1,1,0 }, - { 0,0,1,0,0 }, - { 0,1,1,1,0 }, - { 1,1,1,1,1 }, - { 1,1,1,1,1 }, - { 1,1,0,1,1 }, - { 1,1,0,1,1 }, -}; +DigitalIn button_A(PTB9); // Designating Buttons +DigitalIn button_B(PTD0); +DigitalIn button_X(PTC17); +DigitalIn button_Y(PTC12); +DigitalIn button_L(PTB18); +DigitalIn button_R(PTB3); +DigitalIn button_back(PTB19); +DigitalIn button_start(PTC5); + +TMP102 tmp102(I2C_SDA,I2C_SCL); // Create TMP102 object + -//Objects -Ticker bl_ticker; +N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); //Designating N5110 Display + +Joystick joystick(PTB10,PTB11,PTC16); //Designating Joystick -// Global Volatile Interrupt flags -volatile int g_bl_timer_flag; - -// Setup interrupts -void bl_timer_isr(); - -//Data -float bright; +Serial pc(USBTX,USBRX); // UART connection for PC + +InterruptIn sw2(SW2); // K64F on-board switches +InterruptIn sw3(SW3); + +DigitalOut r_led(LED_RED); // K64F on-board LEDs +DigitalOut g_led(LED_GRN); +DigitalOut b_led(LED_BLUE); + -//Pinouts -// SCE, RST, D/C, MOSI,SCLK,LED -N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); // K64F - pwr from 3V3 -// y x button -Joystick joystick(PTB10,PTB11,PTC16); -//I2C SDA SCL -TMP102 tmp(PTE24,PTE25); +void error(); // error function hangs flashing an LED + +void init_serial(); // Setting up the serial port +void init_K64F(); // Setting up the on-board LEDs and switches -int main() { +void init_leds(); //Setting up the LEDs +int main() +{ - //Initialise devices - lcd.init(); - joystick.init(); - tmp.init(); + init_K64F(); // Initialising the board, serial port, LED'S and joystick + init_serial(); + init_leds(); + joystick.init(); + + tmp102.init(); // call the sensor init method using dot syntax + + + lcd.init(); // initialise display - lcd.setContrast(0.4); + + lcd.setContrast(0.5); // Sets contrast to 0.5 - //Set up ticker (time in seconds) - bl_ticker.attach(&bl_timer_isr,0.01); - - while (1){ + while (1) { + + // these are settings that I have adjusted + lcd.normalMode(); // normal colour mode + lcd.setBrightness(0.75); // put LED backlight on 75% + - //Read pot value and assign to variable - if(pot > 0.1f) { - bright = 0.1; - } if(pot > 0.2f) { - bright = 0.2; - } if (pot > 0.3f) { - bright = 0.3; - } if (pot > 0.4f) { - bright = 0.4; - } if (pot > 0.5f) { - bright = 0.5; - } if(pot > 0.6f) { - bright = 0.6; - } if(pot > 0.7f) { - bright = 0.7; - } if (pot > 0.8f) { - bright = 0.8; - } if (pot > 0.9f) { - bright = 0.9; - } if (pot > 1.0f) { - bright = 1.0; - } - - //Check interrupt flags: - //LCD backlight interrupt - if (g_bl_timer_flag) { - g_bl_timer_flag = 0; //if flag is set, clear - - lcd.setBrightness(bright); //set brightness based on pot value - } - - } + float T = tmp102.get_temperature(); // read temperature and print over serial port + pc.printf("T = %.1f K\n",T); + + if (T > 37.2) { + red_led1.write(0); // LED 1 will flash when you're in High Temp + pc.printf("High Temperature \n"); // Printing to the LCD + } + + else if (T < 36.1) { + red_led2.write(0); // LED 2 will flash when you're in Low Temp + printf("Low Temperature \n"); // Printing to the LCD + } + else if (T > 38) { + red_led3.write(0); // LED 3 will flash when you're beyond high temperature + printf("Call Your GP \n"); // Printing to the LCD + } + +} + } +void init_serial() { + pc.baud(9600); // set to highest baud - ensure terminal software matches } - -// time-triggered interrupt for red -void bl_timer_isr() + +void init_K64F() { - g_bl_timer_flag = 1; // set flag in ISR + r_led = 1; // on-board LEDs are active-low, so set pin high to turn them off. + g_led = 1; + b_led = 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.mode(PullNone); + sw3.mode(PullNone); + } +void init_leds() +{ + red_led1.write(1); // LEDs are common anode (active-low) so writing a 1 will turn them off + red_led2.write(1); + red_led3.write(1); + grn_led1.write(1); + grn_led2.write(1); + grn_led3.write(0); // LED on to show the board is on +} \ No newline at end of file