![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Mini Project 10: Displaying stuff from day 7
Dependencies: DmTouch_UniGraphic UniGraphic mbed
main.cpp@1:20661421fa4e, 2017-01-17 (annotated)
- Committer:
- swescott17
- Date:
- Tue Jan 17 18:36:46 2017 +0000
- Revision:
- 1:20661421fa4e
- Parent:
- 0:1ebe73e062a7
- Child:
- 2:1119063eb8f2
- Child:
- 4:cb3a18844abc
Began working on the UI
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
swescott17 | 0:1ebe73e062a7 | 1 | //MiniProject Day 7 |
swescott17 | 0:1ebe73e062a7 | 2 | //If tapped, the mbed will either read from a temperature sensor or the compass |
swescott17 | 1:20661421fa4e | 3 | #include "stdio.h" |
swescott17 | 1:20661421fa4e | 4 | #include "mbed.h" |
swescott17 | 1:20661421fa4e | 5 | #include "string" |
swescott17 | 1:20661421fa4e | 6 | #include "ILI932x.h" |
swescott17 | 1:20661421fa4e | 7 | #include "DmTouch.h" |
swescott17 | 0:1ebe73e062a7 | 8 | |
swescott17 | 1:20661421fa4e | 9 | |
swescott17 | 1:20661421fa4e | 10 | #include "Arial12x12.h" |
swescott17 | 1:20661421fa4e | 11 | #include "Arial24x23.h" |
swescott17 | 1:20661421fa4e | 12 | //#include "pavement_48x34.h" |
swescott17 | 0:1ebe73e062a7 | 13 | #include "mbed.h" |
swescott17 | 0:1ebe73e062a7 | 14 | #include "compass_sensor.h" |
swescott17 | 0:1ebe73e062a7 | 15 | #include "temp_sensor.h" |
swescott17 | 0:1ebe73e062a7 | 16 | #include "acceler_sensor.h" |
swescott17 | 0:1ebe73e062a7 | 17 | Serial pc(USBTX, USBRX); |
swescott17 | 0:1ebe73e062a7 | 18 | I2C i2c_port(p9, p10); // configures pins 9,10 for I2C communication with external sensors |
swescott17 | 0:1ebe73e062a7 | 19 | float temp2; |
swescott17 | 0:1ebe73e062a7 | 20 | int avg; |
swescott17 | 0:1ebe73e062a7 | 21 | const int addr1 = 0x53<<1; |
swescott17 | 0:1ebe73e062a7 | 22 | DigitalOut led1(LED1); // configures mbed internal LED 1 |
swescott17 | 0:1ebe73e062a7 | 23 | DigitalOut led2(LED2); // configures mbed internal LED 2 |
swescott17 | 1:20661421fa4e | 24 | DigitalIn interupt(p20); // sets accelerometer interupt as digital input at pin 20; |
swescott17 | 1:20661421fa4e | 25 | DmTouch touch(DmTouch::DM_TFT24_104, p5, p6, p7, p8, p9); |
swescott17 | 1:20661421fa4e | 26 | PinName dataBus[]= {p30, p29, p28, p27, p26, p25, p24, p23}; |
swescott17 | 1:20661421fa4e | 27 | ILI932x myLCD(BUS_8, dataBus, p15, p17, p16, p14, p20, "myLCD", 240, 320); // Bus 8 bit, bus pin array, CS, RST, DC, WR, RD, name, xpixels, ypixels |
swescott17 | 1:20661421fa4e | 28 | |
swescott17 | 0:1ebe73e062a7 | 29 | int main() { |
swescott17 | 0:1ebe73e062a7 | 30 | char sensorData[1]; |
swescott17 | 0:1ebe73e062a7 | 31 | led1 = 0; |
swescott17 | 0:1ebe73e062a7 | 32 | led2 = 0; |
swescott17 | 0:1ebe73e062a7 | 33 | avg = compass_config(); |
swescott17 | 0:1ebe73e062a7 | 34 | temperature_config(); |
swescott17 | 0:1ebe73e062a7 | 35 | |
swescott17 | 0:1ebe73e062a7 | 36 | acceleration_n(); |
swescott17 | 0:1ebe73e062a7 | 37 | while(1){ |
swescott17 | 1:20661421fa4e | 38 | myLCD.set_font((unsigned char*) Arial24x23); |
swescott17 | 1:20661421fa4e | 39 | myLCD.background(White); |
swescott17 | 1:20661421fa4e | 40 | myLCD.foreground(Black); |
swescott17 | 1:20661421fa4e | 41 | myLCD.circle(100,132,30,Red); |
swescott17 | 1:20661421fa4e | 42 | myLCD.circle(150,132,30,Blue); |
swescott17 | 1:20661421fa4e | 43 | myLCD.circle(200,132,30,Green); |
swescott17 | 1:20661421fa4e | 44 | /*wait(1); |
swescott17 | 0:1ebe73e062a7 | 45 | i2c_port.start(); // forces start condition |
swescott17 | 0:1ebe73e062a7 | 46 | if (interupt == 1){ |
swescott17 | 0:1ebe73e062a7 | 47 | i2c_port.start(); |
swescott17 | 0:1ebe73e062a7 | 48 | i2c_port.write(addr1); |
swescott17 | 0:1ebe73e062a7 | 49 | i2c_port.write(0x30|0x80); |
swescott17 | 0:1ebe73e062a7 | 50 | i2c_port.stop(); |
swescott17 | 0:1ebe73e062a7 | 51 | i2c_port.read(addr1,sensorData,1); |
swescott17 | 0:1ebe73e062a7 | 52 | wait(1); //checks for interupt signal from accelerometer |
swescott17 | 0:1ebe73e062a7 | 53 | if (sensorData[0] & 0x40){ //if one tap |
swescott17 | 0:1ebe73e062a7 | 54 | led1 = 1; |
swescott17 | 0:1ebe73e062a7 | 55 | temp2 = temperature(); |
swescott17 | 0:1ebe73e062a7 | 56 | pc.printf("%f", temp2); |
swescott17 | 0:1ebe73e062a7 | 57 | } |
swescott17 | 0:1ebe73e062a7 | 58 | if (sensorData[0] & 0x20) { //if two taps |
swescott17 | 0:1ebe73e062a7 | 59 | led2 = 1; |
swescott17 | 0:1ebe73e062a7 | 60 | compass_n(avg); |
swescott17 | 1:20661421fa4e | 61 | }*/ |
swescott17 | 0:1ebe73e062a7 | 62 | } |
swescott17 | 0:1ebe73e062a7 | 63 | } |