![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Rev 1.6 - Sample Period Work in progress
Dependencies: mbed Bitmap N5110 TMP102 Joystick
Diff: main.cpp
- Revision:
- 6:117edd5dc0a0
- Parent:
- 5:138a91e25e1c
- Child:
- 7:ef1dab708752
diff -r 138a91e25e1c -r 117edd5dc0a0 main.cpp --- a/main.cpp Tue Dec 14 14:24:31 2021 +0000 +++ b/main.cpp Thu Dec 16 15:48:12 2021 +0000 @@ -13,11 +13,15 @@ #include "mbed.h" // include the library header, ensure the library has been imported into the project #include "TMP102.h" +#include "N5110.h" +#include "Bitmap.h" // Create TMP102 object TMP102 tmp102(I2C_SDA,I2C_SCL); +N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); // UART connection for PC Serial serial(USBTX,USBRX); +AnalogIn SP(PTB2); // K64F on-board LEDs DigitalOut r_led(LED_RED); @@ -34,6 +38,7 @@ // set-up the on-board LEDs and switches void init_K64F(); + int main() { // initialise the board and serial port @@ -41,13 +46,47 @@ init_serial(); // call the sensor init method using dot syntax tmp102.init(); + lcd.init(); + + + + lcd.setContrast(0.4); while (1) { // read temperature and print over serial port float T = tmp102.get_temperature(); serial.printf("T = %f C\n",T); + // small delay - 1s to match the update rate of the sensor (1 Hz) + lcd.clear(); // clear buffer at start of every loop + // can directly print strings at specified co-ordinates (must be less than 84 pixels to fit on display) + lcd.printString("Lets Gan!",0,0); + + char buffer[14]; // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14) + // so can display a string of a maximum 14 characters in length + // or create formatted strings - ensure they aren't more than 14 characters long + // int temperature = 27; + + int length = sprintf(buffer,"T=%.2F 'C",T); // print formatted data to buffer + // it is important the format specifier ensures the length will fit in the buffer + if (length <= 14) // if string will fit on display (assuming printing at x=0) + lcd.printString(buffer,0,2); // display on screen + + float Set = 33 * SP; + length = sprintf(buffer,"SP=%.2F 'C",Set); + if (length <= 14) // if string will fit on display (assuming printing at x=0) + lcd.printString(buffer,0,4); // display on screen + serial.printf(" SP = %f", Set); + /* + float pressure = 1012.3; // same idea with floats + length = sprintf(buffer,"P = %.2f mb",pressure); + if (length <= 14) + lcd.printString(buffer,0,3); + */ + + lcd.refresh(); + wait(1.0); }