![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Mini Project 10: Displaying stuff from day 7
Dependencies: DmTouch_UniGraphic UniGraphic mbed
main.cpp@10:ee5708e7a36a, 2017-01-17 (annotated)
- Committer:
- swescott17
- Date:
- Tue Jan 17 20:22:49 2017 +0000
- Revision:
- 10:ee5708e7a36a
- Parent:
- 9:0f4c86e7218a
- Child:
- 11:482a9abbc448
Finished commenting UI code
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 | 10:ee5708e7a36a | 17 | char orient=3; //orientation of the LCD and touch screen |
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 | 10:ee5708e7a36a | 22 | int choice = 0; //choice for the buttons on the touch screen: 1 = acceleration, 2 = compass, 3 = temperature |
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 | 10:ee5708e7a36a | 33 | Timer t; //timer for the touch screen |
swescott17 | 9:0f4c86e7218a | 34 | |
swescott17 | 10:ee5708e7a36a | 35 | void UI() //the general UI code for the touch screen |
swescott17 | 9:0f4c86e7218a | 36 | { |
swescott17 | 9:0f4c86e7218a | 37 | myLCD.set_font((unsigned char*) Arial24x23); |
swescott17 | 4:cb3a18844abc | 38 | myLCD.locate(60, 100); |
swescott17 | 10:ee5708e7a36a | 39 | myLCD.printf("A"); //accleration label |
swescott17 | 10:ee5708e7a36a | 40 | myLCD.circle(60,100,30,Blue); //acceleration button |
swescott17 | 4:cb3a18844abc | 41 | myLCD.locate(160, 100); |
swescott17 | 10:ee5708e7a36a | 42 | myLCD.printf("C"); //compass label |
swescott17 | 10:ee5708e7a36a | 43 | myLCD.circle(160,100,30,Green); //compass button |
swescott17 | 4:cb3a18844abc | 44 | myLCD.locate(260, 100); |
swescott17 | 10:ee5708e7a36a | 45 | myLCD.printf("T"); //temp. label |
swescott17 | 10:ee5708e7a36a | 46 | myLCD.circle(260,100,30,Red); //temp. button |
swescott17 | 9:0f4c86e7218a | 47 | } |
swescott17 | 9:0f4c86e7218a | 48 | |
swescott17 | 9:0f4c86e7218a | 49 | int main() { |
swescott17 | 10:ee5708e7a36a | 50 | myLCD.set_orientation(orient); //orientation of the screen |
swescott17 | 10:ee5708e7a36a | 51 | myLCD.set_font((unsigned char*) Arial24x23); //font |
swescott17 | 10:ee5708e7a36a | 52 | touch.setOrientation(orient); //orientation of the touch screen |
swescott17 | 10:ee5708e7a36a | 53 | down = false; //down portion of the touch screen |
swescott17 | 10:ee5708e7a36a | 54 | lastDown = false; //last down -- what down was last time |
swescott17 | 10:ee5708e7a36a | 55 | tx = (uint16_t)0; //x-coordinates of the touch screen |
swescott17 | 10:ee5708e7a36a | 56 | ty = (uint16_t)0; //y-coordinates of the touch screen |
swescott17 | 9:0f4c86e7218a | 57 | //char sensorData[1]; |
swescott17 | 9:0f4c86e7218a | 58 | led1 = 0; |
swescott17 | 9:0f4c86e7218a | 59 | led2 = 0; |
swescott17 | 10:ee5708e7a36a | 60 | UI(); //sets the the UI |
swescott17 | 10:ee5708e7a36a | 61 | touch.init(); //initializes touch screen |
swescott17 | 10:ee5708e7a36a | 62 | t.start(); //starts timer |
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 | 10:ee5708e7a36a | 72 | touch.readTouchData(tx, ty, down); //reads in touch screen coordinates |
swescott17 | 9:0f4c86e7218a | 73 | if (down) |
swescott17 | 9:0f4c86e7218a | 74 | { |
swescott17 | 10:ee5708e7a36a | 75 | if(tx >= 30 && tx <= 90 && ty >= 70 && ty <= 130) //if the acceleration button is pressed |
swescott17 | 9:0f4c86e7218a | 76 | { |
swescott17 | 10:ee5708e7a36a | 77 | if (choice == 2 || choice == 3) //if other buttons were pushed before |
swescott17 | 9:0f4c86e7218a | 78 | { |
swescott17 | 10:ee5708e7a36a | 79 | myLCD.cls(); //reset |
swescott17 | 9:0f4c86e7218a | 80 | UI(); |
swescott17 | 9:0f4c86e7218a | 81 | } |
swescott17 | 10:ee5708e7a36a | 82 | myLCD.fillcircle(60,100,30,Blue); //establish which button is pushed -- "highlight it" |
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 | 10:ee5708e7a36a | 87 | if(tx >= 130 && tx <= 190 && ty >= 70 && ty <= 130) //if the compass button is pressed |
swescott17 | 9:0f4c86e7218a | 88 | { |
swescott17 | 10:ee5708e7a36a | 89 | if (choice == 1 || choice == 3) //if other buttons were pushed before |
swescott17 | 9:0f4c86e7218a | 90 | { |
swescott17 | 10:ee5708e7a36a | 91 | myLCD.cls(); //reset |
swescott17 | 9:0f4c86e7218a | 92 | UI(); |
swescott17 | 9:0f4c86e7218a | 93 | } |
swescott17 | 10:ee5708e7a36a | 94 | myLCD.fillcircle(160,100,30,Green); //establish which button is pushed |
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 | 10:ee5708e7a36a | 100 | if(tx >= 230 && tx <= 290 && ty >= 70 && ty <= 130) //if the temperature button is pressed |
swescott17 | 9:0f4c86e7218a | 101 | { |
swescott17 | 10:ee5708e7a36a | 102 | if (choice == 1 || choice == 2) //if any other buttons were pushed before |
swescott17 | 9:0f4c86e7218a | 103 | { |
swescott17 | 10:ee5708e7a36a | 104 | myLCD.cls(); //reset |
swescott17 | 9:0f4c86e7218a | 105 | UI(); |
swescott17 | 9:0f4c86e7218a | 106 | } |
swescott17 | 10:ee5708e7a36a | 107 | myLCD.fillcircle(260,100,30,Red); //establish which button is pushed |
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 | 10:ee5708e7a36a | 115 | if (choice == 1) //acceleration |
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 | 10:ee5708e7a36a | 120 | //acceleration |
swescott17 | 9:0f4c86e7218a | 121 | } |
swescott17 | 10:ee5708e7a36a | 122 | if (choice == 2) //compass |
swescott17 | 9:0f4c86e7218a | 123 | { |
swescott17 | 9:0f4c86e7218a | 124 | myLCD.locate(160, 100); |
swescott17 | 9:0f4c86e7218a | 125 | myLCD.printf("C"); |
swescott17 | 9:0f4c86e7218a | 126 | myLCD.fillcircle(160,100,30,Green); |
swescott17 | 10:ee5708e7a36a | 127 | |
swescott17 | 10:ee5708e7a36a | 128 | //compass |
swescott17 | 9:0f4c86e7218a | 129 | } |
swescott17 | 10:ee5708e7a36a | 130 | if (choice == 3) //temperature |
swescott17 | 9:0f4c86e7218a | 131 | { |
swescott17 | 9:0f4c86e7218a | 132 | myLCD.locate(260, 100); |
swescott17 | 9:0f4c86e7218a | 133 | myLCD.printf("T"); |
swescott17 | 9:0f4c86e7218a | 134 | myLCD.fillcircle(260,100,30,Red); |
swescott17 | 10:ee5708e7a36a | 135 | //temperature |
swescott17 | 9:0f4c86e7218a | 136 | } |
swescott17 | 9:0f4c86e7218a | 137 | } |
swescott17 | 9:0f4c86e7218a | 138 | wait(0.040); |
swescott17 | 9:0f4c86e7218a | 139 | lastDown = down; |
swescott17 | 9:0f4c86e7218a | 140 | } |
swescott17 | 9:0f4c86e7218a | 141 | } |
swescott17 | 9:0f4c86e7218a | 142 | //getacceleration(); |
swescott17 | 1:20661421fa4e | 143 | /*wait(1); |
swescott17 | 0:1ebe73e062a7 | 144 | i2c_port.start(); // forces start condition |
swescott17 | 0:1ebe73e062a7 | 145 | if (interupt == 1){ |
swescott17 | 0:1ebe73e062a7 | 146 | i2c_port.start(); |
swescott17 | 0:1ebe73e062a7 | 147 | i2c_port.write(addr1); |
swescott17 | 0:1ebe73e062a7 | 148 | i2c_port.write(0x30|0x80); |
swescott17 | 0:1ebe73e062a7 | 149 | i2c_port.stop(); |
swescott17 | 0:1ebe73e062a7 | 150 | i2c_port.read(addr1,sensorData,1); |
swescott17 | 0:1ebe73e062a7 | 151 | wait(1); //checks for interupt signal from accelerometer |
swescott17 | 0:1ebe73e062a7 | 152 | if (sensorData[0] & 0x40){ //if one tap |
swescott17 | 0:1ebe73e062a7 | 153 | led1 = 1; |
swescott17 | 0:1ebe73e062a7 | 154 | temp2 = temperature(); |
swescott17 | 0:1ebe73e062a7 | 155 | pc.printf("%f", temp2); |
swescott17 | 0:1ebe73e062a7 | 156 | } |
swescott17 | 0:1ebe73e062a7 | 157 | if (sensorData[0] & 0x20) { //if two taps |
swescott17 | 0:1ebe73e062a7 | 158 | led2 = 1; |
swescott17 | 0:1ebe73e062a7 | 159 | compass_n(avg); |
swescott17 | 1:20661421fa4e | 160 | }*/ |
swescott17 | 0:1ebe73e062a7 | 161 | } |