Working Menu, additions to be made

Dependencies:   mbed

Committer:
jackmcgarley
Date:
Fri Jan 28 13:22:05 2022 +0000
Revision:
5:bec67fb2b2f9
Parent:
4:143487eef742
Child:
6:e6e7b99198fd
Added Welcome Screen

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 5:bec67fb2b2f9 44 DigitalOut g_led(LED_GREEN);
jackmcgarley 4:143487eef742 45 DigitalOut b_led(LED_BLUE);
jackmcgarley 4:143487eef742 46
jackmcgarley 5:bec67fb2b2f9 47 // DECLARE VOIDS BEING USED IN CODE
25574069 0:d4d7e882c87d 48
jackmcgarley 4:143487eef742 49 void error(); // error function hangs flashing an LED
jackmcgarley 4:143487eef742 50
jackmcgarley 4:143487eef742 51 void init_serial(); // Setting up the serial port
25574069 0:d4d7e882c87d 52
jackmcgarley 4:143487eef742 53 void init_K64F(); // Setting up the on-board LEDs and switches
25574069 0:d4d7e882c87d 54
jackmcgarley 4:143487eef742 55 void init_leds(); //Setting up the LEDs
jackmcgarley 5:bec67fb2b2f9 56
jackmcgarley 5:bec67fb2b2f9 57 void startup();
jackmcgarley 5:bec67fb2b2f9 58
jackmcgarley 4:143487eef742 59 int main()
jackmcgarley 4:143487eef742 60 {
25574069 0:d4d7e882c87d 61
jackmcgarley 5:bec67fb2b2f9 62 init_K64F(); // Initialising the board, serial port, LED'S and joystick
jackmcgarley 5:bec67fb2b2f9 63 init_serial();
jackmcgarley 5:bec67fb2b2f9 64 init_leds();
jackmcgarley 5:bec67fb2b2f9 65 joystick.init();
jackmcgarley 4:143487eef742 66
jackmcgarley 5:bec67fb2b2f9 67 tmp102.init(); // call the sensor init method using dot syntax
jackmcgarley 4:143487eef742 68
jackmcgarley 4:143487eef742 69
jackmcgarley 5:bec67fb2b2f9 70 lcd.init(); // initialise display
25574069 2:d3676e11e2c6 71
jackmcgarley 4:143487eef742 72
jackmcgarley 5:bec67fb2b2f9 73 lcd.setContrast(0.5); // Sets contrast to 0.5
25574069 0:d4d7e882c87d 74
jackmcgarley 5:bec67fb2b2f9 75 while (1) {
jackmcgarley 4:143487eef742 76
jackmcgarley 5:bec67fb2b2f9 77 // these are settings that I have adjusted
jackmcgarley 5:bec67fb2b2f9 78 lcd.normalMode(); // normal colour mode
jackmcgarley 5:bec67fb2b2f9 79 lcd.setBrightness(0.75); // put LED backlight on 75%
jackmcgarley 4:143487eef742 80
jackmcgarley 5:bec67fb2b2f9 81 startup(); // USE VOID NOW
25574069 0:d4d7e882c87d 82
jackmcgarley 5:bec67fb2b2f9 83 float T = tmp102.get_temperature(); // read temperature and print over serial port
jackmcgarley 5:bec67fb2b2f9 84 pc.printf("T = %.1f K\n",T);
jackmcgarley 4:143487eef742 85
jackmcgarley 5:bec67fb2b2f9 86 if (T > 37.2f) {
jackmcgarley 5:bec67fb2b2f9 87 red_led1.write(0); // LED 1 will flash when you're in High Temp
jackmcgarley 5:bec67fb2b2f9 88 pc.printf("High Temperature \n"); // Printing to the LCD
jackmcgarley 5:bec67fb2b2f9 89 }
jackmcgarley 4:143487eef742 90
jackmcgarley 5:bec67fb2b2f9 91 else if (T < 36.1f) {
jackmcgarley 5:bec67fb2b2f9 92 red_led2.write(0); // LED 2 will flash when you're in Low Temp
jackmcgarley 5:bec67fb2b2f9 93 printf("Low Temperature \n"); // Printing to the LCD
jackmcgarley 5:bec67fb2b2f9 94 }
jackmcgarley 5:bec67fb2b2f9 95 else if (T > 38) {
jackmcgarley 5:bec67fb2b2f9 96 red_led3.write(0); // LED 3 will flash when you're beyond high temperature
jackmcgarley 5:bec67fb2b2f9 97 printf("Call Your GP \n"); // Printing to the LCD
jackmcgarley 5:bec67fb2b2f9 98 }
jackmcgarley 4:143487eef742 99
jackmcgarley 4:143487eef742 100 }
jackmcgarley 4:143487eef742 101 }
jackmcgarley 4:143487eef742 102 void init_serial() {
jackmcgarley 4:143487eef742 103 pc.baud(9600); // set to highest baud - ensure terminal software matches
25574069 0:d4d7e882c87d 104 }
jackmcgarley 4:143487eef742 105
jackmcgarley 4:143487eef742 106 void init_K64F()
25574069 0:d4d7e882c87d 107 {
jackmcgarley 4:143487eef742 108 r_led = 1; // on-board LEDs are active-low, so set pin high to turn them off.
jackmcgarley 4:143487eef742 109 g_led = 1;
jackmcgarley 4:143487eef742 110 b_led = 1;
jackmcgarley 4:143487eef742 111
jackmcgarley 4:143487eef742 112 // since the on-board switches have external pull-ups, we should disable the internal pull-down
jackmcgarley 4:143487eef742 113 // resistors that are enabled by default using InterruptIn
jackmcgarley 4:143487eef742 114 sw2.mode(PullNone);
jackmcgarley 4:143487eef742 115 sw3.mode(PullNone);
jackmcgarley 4:143487eef742 116
25574069 0:d4d7e882c87d 117 }
jackmcgarley 4:143487eef742 118 void init_leds()
jackmcgarley 4:143487eef742 119 {
jackmcgarley 4:143487eef742 120 red_led1.write(1); // LEDs are common anode (active-low) so writing a 1 will turn them off
jackmcgarley 4:143487eef742 121 red_led2.write(1);
jackmcgarley 4:143487eef742 122 red_led3.write(1);
jackmcgarley 4:143487eef742 123 grn_led1.write(1);
jackmcgarley 4:143487eef742 124 grn_led2.write(1);
jackmcgarley 4:143487eef742 125 grn_led3.write(0); // LED on to show the board is on
jackmcgarley 5:bec67fb2b2f9 126 }
jackmcgarley 5:bec67fb2b2f9 127 void lcd_sett()
jackmcgarley 5:bec67fb2b2f9 128 {
jackmcgarley 5:bec67fb2b2f9 129 //LCD SET
jackmcgarley 5:bec67fb2b2f9 130 }
jackmcgarley 5:bec67fb2b2f9 131 void startup() // VOID FUNCTION SETUP
jackmcgarley 5:bec67fb2b2f9 132 {
jackmcgarley 5:bec67fb2b2f9 133 // Welcome Screen
jackmcgarley 5:bec67fb2b2f9 134 lcd.clear();
jackmcgarley 5:bec67fb2b2f9 135 lcd.printString(" Jack McGarley ", 0, 0);
jackmcgarley 5:bec67fb2b2f9 136 lcd.printString(" 1868007 ", 0, 2);
jackmcgarley 5:bec67fb2b2f9 137 lcd.printString(" Schneider ", 0, 3);
jackmcgarley 5:bec67fb2b2f9 138 lcd.printString(" Lincoln Uni", 0, 4);
jackmcgarley 5:bec67fb2b2f9 139 lcd.printString(" January 2022", 0, 5);
jackmcgarley 5:bec67fb2b2f9 140 lcd.refresh();
jackmcgarley 5:bec67fb2b2f9 141
jackmcgarley 5:bec67fb2b2f9 142 char d = joystick.get_direction();
jackmcgarley 4:143487eef742 143 }