![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Mini Project 10: Displaying stuff from day 7
Dependencies: DmTouch_UniGraphic UniGraphic mbed
main.cpp@9:0f4c86e7218a, 2017-01-17 (annotated)
- Committer:
- swescott17
- Date:
- Tue Jan 17 20:14:51 2017 +0000
- Revision:
- 9:0f4c86e7218a
- Parent:
- 8:bbe3e332fe94
- Child:
- 10:ee5708e7a36a
UI is finished
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 | 4:cb3a18844abc | 17 | char orient=3; |
swescott17 | 0:1ebe73e062a7 | 18 | Serial pc(USBTX, USBRX); |
swescott17 | 0:1ebe73e062a7 | 19 | I2C i2c_port(p9, p10); // configures pins 9,10 for I2C communication with external sensors |
swescott17 | 0:1ebe73e062a7 | 20 | float temp2; |
swescott17 | 0:1ebe73e062a7 | 21 | int avg; |
swescott17 | 9:0f4c86e7218a | 22 | int choice = 0; //choice for the buttons on the touch screen |
swescott17 | 4:cb3a18844abc | 23 | //const int addr1 = 0x53<<1; |
swescott17 | 0:1ebe73e062a7 | 24 | DigitalOut led1(LED1); // configures mbed internal LED 1 |
swescott17 | 0:1ebe73e062a7 | 25 | DigitalOut led2(LED2); // configures mbed internal LED 2 |
swescott17 | 1:20661421fa4e | 26 | DigitalIn interupt(p20); // sets accelerometer interupt as digital input at pin 20; |
ezimmerman17 | 3:dbb843b8d2f4 | 27 | Timer sensor_timer; |
swescott17 | 1:20661421fa4e | 28 | DmTouch touch(DmTouch::DM_TFT24_104, p5, p6, p7, p8, p9); |
swescott17 | 1:20661421fa4e | 29 | PinName dataBus[]= {p30, p29, p28, p27, p26, p25, p24, p23}; |
swescott17 | 1:20661421fa4e | 30 | 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 | 9:0f4c86e7218a | 31 | bool down, lastDown; |
swescott17 | 9:0f4c86e7218a | 32 | uint16_t tx, ty; |
swescott17 | 9:0f4c86e7218a | 33 | Timer t; |
swescott17 | 9:0f4c86e7218a | 34 | |
swescott17 | 9:0f4c86e7218a | 35 | void UI() |
swescott17 | 9:0f4c86e7218a | 36 | { |
swescott17 | 9:0f4c86e7218a | 37 | myLCD.set_font((unsigned char*) Arial24x23); |
swescott17 | 4:cb3a18844abc | 38 | myLCD.locate(60, 100); |
swescott17 | 4:cb3a18844abc | 39 | myLCD.printf("A"); |
swescott17 | 4:cb3a18844abc | 40 | myLCD.circle(60,100,30,Blue); |
swescott17 | 4:cb3a18844abc | 41 | myLCD.locate(160, 100); |
swescott17 | 4:cb3a18844abc | 42 | myLCD.printf("C"); |
swescott17 | 4:cb3a18844abc | 43 | myLCD.circle(160,100,30,Green); |
swescott17 | 4:cb3a18844abc | 44 | myLCD.locate(260, 100); |
swescott17 | 4:cb3a18844abc | 45 | myLCD.printf("T"); |
swescott17 | 4:cb3a18844abc | 46 | myLCD.circle(260,100,30,Red); |
swescott17 | 9:0f4c86e7218a | 47 | } |
swescott17 | 9:0f4c86e7218a | 48 | |
swescott17 | 9:0f4c86e7218a | 49 | int main() { |
swescott17 | 9:0f4c86e7218a | 50 | myLCD.set_orientation(orient); |
swescott17 | 9:0f4c86e7218a | 51 | myLCD.set_font((unsigned char*) Arial24x23); |
swescott17 | 9:0f4c86e7218a | 52 | touch.setOrientation(orient); |
swescott17 | 9:0f4c86e7218a | 53 | down = false; |
swescott17 | 9:0f4c86e7218a | 54 | lastDown = false; |
swescott17 | 9:0f4c86e7218a | 55 | tx = (uint16_t)0; |
swescott17 | 9:0f4c86e7218a | 56 | ty = (uint16_t)0; |
swescott17 | 9:0f4c86e7218a | 57 | //char sensorData[1]; |
swescott17 | 9:0f4c86e7218a | 58 | led1 = 0; |
swescott17 | 9:0f4c86e7218a | 59 | led2 = 0; |
swescott17 | 9:0f4c86e7218a | 60 | UI(); |
swescott17 | 9:0f4c86e7218a | 61 | touch.init(); |
swescott17 | 9:0f4c86e7218a | 62 | t.start(); |
swescott17 | 9:0f4c86e7218a | 63 | //avg = compass_config(); |
swescott17 | 9:0f4c86e7218a | 64 | //temperature_config(); |
swescott17 | 9:0f4c86e7218a | 65 | //configure_acceleration(); |
swescott17 | 9:0f4c86e7218a | 66 | while(1){ |
swescott17 | 9:0f4c86e7218a | 67 | //myLCD.foreground(Black); |
swescott17 | 9:0f4c86e7218a | 68 | //myLCD.background(White); |
swescott17 | 9:0f4c86e7218a | 69 | t.reset(); |
swescott17 | 9:0f4c86e7218a | 70 | while (t.read()<10) |
swescott17 | 9:0f4c86e7218a | 71 | { |
swescott17 | 9:0f4c86e7218a | 72 | touch.readTouchData(tx, ty, down); |
swescott17 | 9:0f4c86e7218a | 73 | if (down) |
swescott17 | 9:0f4c86e7218a | 74 | { |
swescott17 | 9:0f4c86e7218a | 75 | if(tx >= 30 && tx <= 90 && ty >= 70 && ty <= 130) |
swescott17 | 9:0f4c86e7218a | 76 | { |
swescott17 | 9:0f4c86e7218a | 77 | if (choice == 2 || choice == 3) |
swescott17 | 9:0f4c86e7218a | 78 | { |
swescott17 | 9:0f4c86e7218a | 79 | myLCD.cls(); |
swescott17 | 9:0f4c86e7218a | 80 | UI(); |
swescott17 | 9:0f4c86e7218a | 81 | } |
swescott17 | 9:0f4c86e7218a | 82 | myLCD.fillcircle(60,100,30,Blue); |
swescott17 | 9:0f4c86e7218a | 83 | myLCD.locate(60, 100); |
swescott17 | 9:0f4c86e7218a | 84 | myLCD.printf("A"); |
swescott17 | 9:0f4c86e7218a | 85 | choice = 1; |
swescott17 | 9:0f4c86e7218a | 86 | } |
swescott17 | 9:0f4c86e7218a | 87 | if(tx >= 130 && tx <= 190 && ty >= 70 && ty <= 130) |
swescott17 | 9:0f4c86e7218a | 88 | { |
swescott17 | 9:0f4c86e7218a | 89 | if (choice == 1 || choice == 3) |
swescott17 | 9:0f4c86e7218a | 90 | { |
swescott17 | 9:0f4c86e7218a | 91 | myLCD.cls(); |
swescott17 | 9:0f4c86e7218a | 92 | UI(); |
swescott17 | 9:0f4c86e7218a | 93 | } |
swescott17 | 9:0f4c86e7218a | 94 | myLCD.fillcircle(160,100,30,Green); |
swescott17 | 9:0f4c86e7218a | 95 | myLCD.locate(160, 100); |
swescott17 | 9:0f4c86e7218a | 96 | myLCD.printf("C"); |
swescott17 | 9:0f4c86e7218a | 97 | choice = 2; |
swescott17 | 9:0f4c86e7218a | 98 | |
swescott17 | 9:0f4c86e7218a | 99 | } |
swescott17 | 9:0f4c86e7218a | 100 | if(tx >= 230 && tx <= 290 && ty >= 70 && ty <= 130) |
swescott17 | 9:0f4c86e7218a | 101 | { |
swescott17 | 9:0f4c86e7218a | 102 | if (choice == 1 || choice == 2) |
swescott17 | 9:0f4c86e7218a | 103 | { |
swescott17 | 9:0f4c86e7218a | 104 | myLCD.cls(); |
swescott17 | 9:0f4c86e7218a | 105 | UI(); |
swescott17 | 9:0f4c86e7218a | 106 | } |
swescott17 | 9:0f4c86e7218a | 107 | myLCD.fillcircle(260,100,30,Red); |
swescott17 | 9:0f4c86e7218a | 108 | myLCD.locate(260, 100); |
swescott17 | 9:0f4c86e7218a | 109 | myLCD.printf("T"); |
swescott17 | 9:0f4c86e7218a | 110 | choice = 3; |
swescott17 | 9:0f4c86e7218a | 111 | } |
swescott17 | 9:0f4c86e7218a | 112 | } |
swescott17 | 9:0f4c86e7218a | 113 | else if (lastDown) |
swescott17 | 9:0f4c86e7218a | 114 | { |
swescott17 | 9:0f4c86e7218a | 115 | if (choice == 1) |
swescott17 | 9:0f4c86e7218a | 116 | { |
swescott17 | 9:0f4c86e7218a | 117 | myLCD.locate(60, 100); |
swescott17 | 9:0f4c86e7218a | 118 | myLCD.printf("A"); |
swescott17 | 9:0f4c86e7218a | 119 | myLCD.fillcircle(60,100,30,Blue); |
swescott17 | 9:0f4c86e7218a | 120 | } |
swescott17 | 9:0f4c86e7218a | 121 | if (choice == 2) |
swescott17 | 9:0f4c86e7218a | 122 | { |
swescott17 | 9:0f4c86e7218a | 123 | myLCD.locate(160, 100); |
swescott17 | 9:0f4c86e7218a | 124 | myLCD.printf("C"); |
swescott17 | 9:0f4c86e7218a | 125 | myLCD.fillcircle(160,100,30,Green); |
swescott17 | 9:0f4c86e7218a | 126 | } |
swescott17 | 9:0f4c86e7218a | 127 | if (choice == 3) |
swescott17 | 9:0f4c86e7218a | 128 | { |
swescott17 | 9:0f4c86e7218a | 129 | myLCD.locate(260, 100); |
swescott17 | 9:0f4c86e7218a | 130 | myLCD.printf("T"); |
swescott17 | 9:0f4c86e7218a | 131 | myLCD.fillcircle(260,100,30,Red); |
swescott17 | 9:0f4c86e7218a | 132 | } |
swescott17 | 9:0f4c86e7218a | 133 | } |
swescott17 | 9:0f4c86e7218a | 134 | wait(0.040); |
swescott17 | 9:0f4c86e7218a | 135 | lastDown = down; |
swescott17 | 9:0f4c86e7218a | 136 | } |
swescott17 | 9:0f4c86e7218a | 137 | } |
swescott17 | 9:0f4c86e7218a | 138 | //getacceleration(); |
swescott17 | 1:20661421fa4e | 139 | /*wait(1); |
swescott17 | 0:1ebe73e062a7 | 140 | i2c_port.start(); // forces start condition |
swescott17 | 0:1ebe73e062a7 | 141 | if (interupt == 1){ |
swescott17 | 0:1ebe73e062a7 | 142 | i2c_port.start(); |
swescott17 | 0:1ebe73e062a7 | 143 | i2c_port.write(addr1); |
swescott17 | 0:1ebe73e062a7 | 144 | i2c_port.write(0x30|0x80); |
swescott17 | 0:1ebe73e062a7 | 145 | i2c_port.stop(); |
swescott17 | 0:1ebe73e062a7 | 146 | i2c_port.read(addr1,sensorData,1); |
swescott17 | 0:1ebe73e062a7 | 147 | wait(1); //checks for interupt signal from accelerometer |
swescott17 | 0:1ebe73e062a7 | 148 | if (sensorData[0] & 0x40){ //if one tap |
swescott17 | 0:1ebe73e062a7 | 149 | led1 = 1; |
swescott17 | 0:1ebe73e062a7 | 150 | temp2 = temperature(); |
swescott17 | 0:1ebe73e062a7 | 151 | pc.printf("%f", temp2); |
swescott17 | 0:1ebe73e062a7 | 152 | } |
swescott17 | 0:1ebe73e062a7 | 153 | if (sensorData[0] & 0x20) { //if two taps |
swescott17 | 0:1ebe73e062a7 | 154 | led2 = 1; |
swescott17 | 0:1ebe73e062a7 | 155 | compass_n(avg); |
swescott17 | 1:20661421fa4e | 156 | }*/ |
swescott17 | 0:1ebe73e062a7 | 157 | } |