Working Menu, additions to be made

Dependencies:   mbed

Committer:
jackmcgarley
Date:
Fri Jan 28 09:37:53 2022 +0000
Revision:
4:143487eef742
Parent:
3:d1e1de4a712e
Child:
5:bec67fb2b2f9
Temperature-based smart device health monitoring V1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jackmcgarley 4:143487eef742 1 /*
jackmcgarley 4:143487eef742 2 * Author - Jack McGarley - 18689007
jackmcgarley 4:143487eef742 3 * Date - January 2022
jackmcgarley 4:143487eef742 4 * Acknowledgements
jackmcgarley 4:143487eef742 5 * Craig A. Evans, University of Leeds, TMP102 Library, Feb 2016
jackmcgarley 4:143487eef742 6 * Dr Edmond Nurellari, University of Lincoln, Joystick & N5110 Libraries
jackmcgarley 4:143487eef742 7 */
25574069 1:a87075699085 8
jackmcgarley 4:143487eef742 9 #include "mbed.h" // include the library header, ensure the library has been imported into the project
jackmcgarley 4:143487eef742 10 #include "Joystick.h"
25574069 2:d3676e11e2c6 11 #include "TMP102.h"
jackmcgarley 4:143487eef742 12 #include "N5110.h"
25574069 0:d4d7e882c87d 13
jackmcgarley 4:143487eef742 14 DigitalOut grn_led1(PTA1); // Designating LEDs from left to right
jackmcgarley 4:143487eef742 15 DigitalOut grn_led2(PTA2);
jackmcgarley 4:143487eef742 16 DigitalOut grn_led3(PTC2);
jackmcgarley 4:143487eef742 17 DigitalOut red_led1(PTC3);
jackmcgarley 4:143487eef742 18 DigitalOut red_led2(PTC4);
jackmcgarley 4:143487eef742 19 DigitalOut red_led3(PTD3);
jackmcgarley 4:143487eef742 20
25574069 0:d4d7e882c87d 21
jackmcgarley 4:143487eef742 22 DigitalIn button_A(PTB9); // Designating Buttons
jackmcgarley 4:143487eef742 23 DigitalIn button_B(PTD0);
jackmcgarley 4:143487eef742 24 DigitalIn button_X(PTC17);
jackmcgarley 4:143487eef742 25 DigitalIn button_Y(PTC12);
jackmcgarley 4:143487eef742 26 DigitalIn button_L(PTB18);
jackmcgarley 4:143487eef742 27 DigitalIn button_R(PTB3);
jackmcgarley 4:143487eef742 28 DigitalIn button_back(PTB19);
jackmcgarley 4:143487eef742 29 DigitalIn button_start(PTC5);
jackmcgarley 4:143487eef742 30
jackmcgarley 4:143487eef742 31 TMP102 tmp102(I2C_SDA,I2C_SCL); // Create TMP102 object
jackmcgarley 4:143487eef742 32
25574069 0:d4d7e882c87d 33
jackmcgarley 4:143487eef742 34 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); //Designating N5110 Display
jackmcgarley 4:143487eef742 35
jackmcgarley 4:143487eef742 36 Joystick joystick(PTB10,PTB11,PTC16); //Designating Joystick
25574069 0:d4d7e882c87d 37
jackmcgarley 4:143487eef742 38 Serial pc(USBTX,USBRX); // UART connection for PC
jackmcgarley 4:143487eef742 39
jackmcgarley 4:143487eef742 40 InterruptIn sw2(SW2); // K64F on-board switches
jackmcgarley 4:143487eef742 41 InterruptIn sw3(SW3);
jackmcgarley 4:143487eef742 42
jackmcgarley 4:143487eef742 43 DigitalOut r_led(LED_RED); // K64F on-board LEDs
jackmcgarley 4:143487eef742 44 DigitalOut g_led(LED_GRN);
jackmcgarley 4:143487eef742 45 DigitalOut b_led(LED_BLUE);
jackmcgarley 4:143487eef742 46
25574069 0:d4d7e882c87d 47
jackmcgarley 4:143487eef742 48 void error(); // error function hangs flashing an LED
jackmcgarley 4:143487eef742 49
jackmcgarley 4:143487eef742 50 void init_serial(); // Setting up the serial port
25574069 0:d4d7e882c87d 51
jackmcgarley 4:143487eef742 52 void init_K64F(); // Setting up the on-board LEDs and switches
25574069 0:d4d7e882c87d 53
jackmcgarley 4:143487eef742 54 void init_leds(); //Setting up the LEDs
jackmcgarley 4:143487eef742 55 int main()
jackmcgarley 4:143487eef742 56 {
25574069 0:d4d7e882c87d 57
jackmcgarley 4:143487eef742 58 init_K64F(); // Initialising the board, serial port, LED'S and joystick
jackmcgarley 4:143487eef742 59 init_serial();
jackmcgarley 4:143487eef742 60 init_leds();
jackmcgarley 4:143487eef742 61 joystick.init();
jackmcgarley 4:143487eef742 62
jackmcgarley 4:143487eef742 63 tmp102.init(); // call the sensor init method using dot syntax
jackmcgarley 4:143487eef742 64
jackmcgarley 4:143487eef742 65
jackmcgarley 4:143487eef742 66 lcd.init(); // initialise display
25574069 2:d3676e11e2c6 67
jackmcgarley 4:143487eef742 68
jackmcgarley 4:143487eef742 69 lcd.setContrast(0.5); // Sets contrast to 0.5
25574069 0:d4d7e882c87d 70
jackmcgarley 4:143487eef742 71 while (1) {
jackmcgarley 4:143487eef742 72
jackmcgarley 4:143487eef742 73 // these are settings that I have adjusted
jackmcgarley 4:143487eef742 74 lcd.normalMode(); // normal colour mode
jackmcgarley 4:143487eef742 75 lcd.setBrightness(0.75); // put LED backlight on 75%
jackmcgarley 4:143487eef742 76
25574069 0:d4d7e882c87d 77
jackmcgarley 4:143487eef742 78 float T = tmp102.get_temperature(); // read temperature and print over serial port
jackmcgarley 4:143487eef742 79 pc.printf("T = %.1f K\n",T);
jackmcgarley 4:143487eef742 80
jackmcgarley 4:143487eef742 81 if (T > 37.2) {
jackmcgarley 4:143487eef742 82 red_led1.write(0); // LED 1 will flash when you're in High Temp
jackmcgarley 4:143487eef742 83 pc.printf("High Temperature \n"); // Printing to the LCD
jackmcgarley 4:143487eef742 84 }
jackmcgarley 4:143487eef742 85
jackmcgarley 4:143487eef742 86 else if (T < 36.1) {
jackmcgarley 4:143487eef742 87 red_led2.write(0); // LED 2 will flash when you're in Low Temp
jackmcgarley 4:143487eef742 88 printf("Low Temperature \n"); // Printing to the LCD
jackmcgarley 4:143487eef742 89 }
jackmcgarley 4:143487eef742 90 else if (T > 38) {
jackmcgarley 4:143487eef742 91 red_led3.write(0); // LED 3 will flash when you're beyond high temperature
jackmcgarley 4:143487eef742 92 printf("Call Your GP \n"); // Printing to the LCD
jackmcgarley 4:143487eef742 93 }
jackmcgarley 4:143487eef742 94
jackmcgarley 4:143487eef742 95 }
jackmcgarley 4:143487eef742 96 }
jackmcgarley 4:143487eef742 97 void init_serial() {
jackmcgarley 4:143487eef742 98 pc.baud(9600); // set to highest baud - ensure terminal software matches
25574069 0:d4d7e882c87d 99 }
jackmcgarley 4:143487eef742 100
jackmcgarley 4:143487eef742 101 void init_K64F()
25574069 0:d4d7e882c87d 102 {
jackmcgarley 4:143487eef742 103 r_led = 1; // on-board LEDs are active-low, so set pin high to turn them off.
jackmcgarley 4:143487eef742 104 g_led = 1;
jackmcgarley 4:143487eef742 105 b_led = 1;
jackmcgarley 4:143487eef742 106
jackmcgarley 4:143487eef742 107 // since the on-board switches have external pull-ups, we should disable the internal pull-down
jackmcgarley 4:143487eef742 108 // resistors that are enabled by default using InterruptIn
jackmcgarley 4:143487eef742 109 sw2.mode(PullNone);
jackmcgarley 4:143487eef742 110 sw3.mode(PullNone);
jackmcgarley 4:143487eef742 111
25574069 0:d4d7e882c87d 112 }
jackmcgarley 4:143487eef742 113 void init_leds()
jackmcgarley 4:143487eef742 114 {
jackmcgarley 4:143487eef742 115 red_led1.write(1); // LEDs are common anode (active-low) so writing a 1 will turn them off
jackmcgarley 4:143487eef742 116 red_led2.write(1);
jackmcgarley 4:143487eef742 117 red_led3.write(1);
jackmcgarley 4:143487eef742 118 grn_led1.write(1);
jackmcgarley 4:143487eef742 119 grn_led2.write(1);
jackmcgarley 4:143487eef742 120 grn_led3.write(0); // LED on to show the board is on
jackmcgarley 4:143487eef742 121 }