The present code implements a single player squash game, using joystick to move paddle right or left. And checks the current temperature inside the device.
Dependencies: 2645_I2C_TMP102 2645_Physics_Engine_Example Paddle mbed
Diff: main.cpp
- Revision:
- 2:c1b442f26087
- Parent:
- 1:fe4ac8f10309
- Child:
- 4:1d38d6b09e84
--- a/main.cpp Sun May 08 22:16:03 2016 +0000 +++ b/main.cpp Mon May 09 09:17:47 2016 +0000 @@ -1,7 +1,8 @@ #include "mbed.h" #include "N5110.h" #include "game.h" -#include "SDFileSystem.h" +#include "main.h" + #define BALLRADIUS 2 @@ -19,9 +20,6 @@ AnalogIn xPot(PTB2); AnalogIn yPot(PTB3); -// Connections to SD card holder on K64F (SPI interface) -SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); // MOSI, MISO, SCK, CS - void delete_file(char filename[]); // function prototypes @@ -36,7 +34,7 @@ void PaddleMove(); void updateJoystick(); void drawCircle(int x0,int y0,int radius,int fill); - +void Temp_reading(); // Can give better performance due to current limitation from GPIO pin Ticker game_timer; @@ -84,7 +82,12 @@ buzzer.pulsewidth_ms(1.9); getPaddle(); wait(3.0); - + lcd.clear(); + + // checking the heat on the regulator + Temp_reading(); + wait(3.0); + init_ball(); // setup ticker @@ -124,7 +127,7 @@ wait(0.05); lcd.clear(); } - + BallMove(); } } @@ -277,6 +280,48 @@ printFlag = 1; } +void Temp_reading() +{ + //lcd.init(); // initialising the display + // initialise the board and serial port + init_K64F(); + init_serial(); + // call the sensor init method using dot syntax + tmp102.init(); + + + // can directly print strings at specified co-ordinates + lcd.printString("Current Temp",0,0); + + // read temperature and print over serial port + float T = tmp102.get_temperature(); + pc.printf("T = %f K\n",T); + + 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 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 + lcd.printString(buffer,0,2); + + // small delay - 1s to match the update rate of the sensor (1 Hz) + wait(1.0); + + if(T<27){ + + g_led = 0; + lcd.printString("Fan OFF",0,4); + } + + if (T>=30){ + + r_led = 0; + lcd.printString("Fan ON ",0,4); + } +} + + void game_timer_isr() { g_timer_flag = 1;