The present code implements and checks the current temperature.
Fork of 2645_I2C_TMP102 by
main.h@2:0047b6c36b3e, 2016-05-09 (annotated)
- Committer:
- bonnyngangu
- Date:
- Mon May 09 09:17:29 2016 +0000
- Revision:
- 2:0047b6c36b3e
- Parent:
- main.cpp@1:dd5fb735acf1
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.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
eencae | 0:21a200b880d7 | 1 | /* |
bonnyngangu | 2:0047b6c36b3e | 2 | Joystick_Project |
bonnyngangu | 2:0047b6c36b3e | 3 | Bonny Ngangu |
bonnyngangu | 2:0047b6c36b3e | 4 | 6 March 2016 |
bonnyngangu | 2:0047b6c36b3e | 5 | (c) Bonny Ngangu, University of Leeds, Feb 2016 |
eencae | 0:21a200b880d7 | 6 | |
eencae | 0:21a200b880d7 | 7 | */ |
eencae | 0:21a200b880d7 | 8 | |
eencae | 0:21a200b880d7 | 9 | #include "mbed.h" |
eencae | 1:dd5fb735acf1 | 10 | // include the library header, ensure the library has been imported into the project |
eencae | 1:dd5fb735acf1 | 11 | #include "TMP102.h" |
bonnyngangu | 2:0047b6c36b3e | 12 | #include "N5110.h" |
bonnyngangu | 2:0047b6c36b3e | 13 | |
eencae | 0:21a200b880d7 | 14 | |
eencae | 1:dd5fb735acf1 | 15 | // Create TMP102 object |
eencae | 1:dd5fb735acf1 | 16 | TMP102 tmp102(I2C_SDA,I2C_SCL); |
eencae | 0:21a200b880d7 | 17 | // UART connection for PC |
eencae | 0:21a200b880d7 | 18 | Serial pc(USBTX,USBRX); |
eencae | 0:21a200b880d7 | 19 | |
eencae | 0:21a200b880d7 | 20 | // K64F on-board LEDs |
eencae | 0:21a200b880d7 | 21 | DigitalOut r_led(LED_RED); |
eencae | 0:21a200b880d7 | 22 | DigitalOut g_led(LED_GREEN); |
eencae | 0:21a200b880d7 | 23 | DigitalOut b_led(LED_BLUE); |
bonnyngangu | 2:0047b6c36b3e | 24 | |
eencae | 0:21a200b880d7 | 25 | // K64F on-board switches |
eencae | 0:21a200b880d7 | 26 | InterruptIn sw2(SW2); |
eencae | 0:21a200b880d7 | 27 | InterruptIn sw3(SW3); |
eencae | 0:21a200b880d7 | 28 | |
eencae | 0:21a200b880d7 | 29 | // error function hangs flashing an LED |
eencae | 0:21a200b880d7 | 30 | void error(); |
eencae | 0:21a200b880d7 | 31 | // setup serial port |
eencae | 0:21a200b880d7 | 32 | void init_serial(); |
eencae | 0:21a200b880d7 | 33 | // set-up the on-board LEDs and switches |
eencae | 0:21a200b880d7 | 34 | void init_K64F(); |
bonnyngangu | 2:0047b6c36b3e | 35 | void printString(); |
eencae | 0:21a200b880d7 | 36 | |
eencae | 0:21a200b880d7 | 37 | void init_serial() { |
eencae | 0:21a200b880d7 | 38 | // set to highest baud - ensure terminal software matches |
eencae | 0:21a200b880d7 | 39 | pc.baud(115200); |
eencae | 0:21a200b880d7 | 40 | } |
eencae | 0:21a200b880d7 | 41 | |
eencae | 0:21a200b880d7 | 42 | void init_K64F() |
eencae | 0:21a200b880d7 | 43 | { |
eencae | 0:21a200b880d7 | 44 | // on-board LEDs are active-low, so set pin high to turn them off. |
eencae | 0:21a200b880d7 | 45 | r_led = 1; |
eencae | 0:21a200b880d7 | 46 | g_led = 1; |
eencae | 0:21a200b880d7 | 47 | b_led = 1; |
eencae | 0:21a200b880d7 | 48 | |
eencae | 0:21a200b880d7 | 49 | // since the on-board switches have external pull-ups, we should disable the internal pull-down |
eencae | 0:21a200b880d7 | 50 | // resistors that are enabled by default using InterruptIn |
eencae | 0:21a200b880d7 | 51 | sw2.mode(PullNone); |
eencae | 0:21a200b880d7 | 52 | sw3.mode(PullNone); |
bonnyngangu | 2:0047b6c36b3e | 53 | } |