![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Mini Project 10: Displaying stuff from day 7
Dependencies: DmTouch_UniGraphic UniGraphic mbed
main.cpp@5:eaf6008bf60b, 2017-01-17 (annotated)
- Committer:
- swescott17
- Date:
- Tue Jan 17 18:58:27 2017 +0000
- Revision:
- 5:eaf6008bf60b
- Parent:
- 4:cb3a18844abc
- Parent:
- 3:dbb843b8d2f4
- Child:
- 7:ee7f2c33d45d
Button stuff
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 | 4:cb3a18844abc | 22 | //const int addr1 = 0x53<<1; |
swescott17 | 0:1ebe73e062a7 | 23 | DigitalOut led1(LED1); // configures mbed internal LED 1 |
swescott17 | 0:1ebe73e062a7 | 24 | DigitalOut led2(LED2); // configures mbed internal LED 2 |
swescott17 | 1:20661421fa4e | 25 | DigitalIn interupt(p20); // sets accelerometer interupt as digital input at pin 20; |
ezimmerman17 | 3:dbb843b8d2f4 | 26 | Timer sensor_timer; |
swescott17 | 1:20661421fa4e | 27 | DmTouch touch(DmTouch::DM_TFT24_104, p5, p6, p7, p8, p9); |
swescott17 | 1:20661421fa4e | 28 | PinName dataBus[]= {p30, p29, p28, p27, p26, p25, p24, p23}; |
swescott17 | 1:20661421fa4e | 29 | 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 | 30 | |
swescott17 | 0:1ebe73e062a7 | 31 | int main() { |
swescott17 | 4:cb3a18844abc | 32 | myLCD.set_orientation(orient); |
swescott17 | 4:cb3a18844abc | 33 | //char sensorData[1]; |
swescott17 | 0:1ebe73e062a7 | 34 | led1 = 0; |
swescott17 | 0:1ebe73e062a7 | 35 | led2 = 0; |
swescott17 | 4:cb3a18844abc | 36 | //avg = compass_config(); |
swescott17 | 4:cb3a18844abc | 37 | //temperature_config(); |
swescott17 | 4:cb3a18844abc | 38 | //acceleration_n(); |
swescott17 | 0:1ebe73e062a7 | 39 | while(1){ |
swescott17 | 1:20661421fa4e | 40 | myLCD.set_font((unsigned char*) Arial24x23); |
swescott17 | 4:cb3a18844abc | 41 | //myLCD.foreground(Black); |
swescott17 | 4:cb3a18844abc | 42 | //myLCD.background(White); |
swescott17 | 4:cb3a18844abc | 43 | touch.readTouchData(tx, ty, down); |
swescott17 | 4:cb3a18844abc | 44 | myLCD.locate(60, 100); |
swescott17 | 4:cb3a18844abc | 45 | myLCD.printf("A"); |
swescott17 | 4:cb3a18844abc | 46 | myLCD.circle(60,100,30,Blue); |
swescott17 | 4:cb3a18844abc | 47 | myLCD.locate(160, 100); |
swescott17 | 4:cb3a18844abc | 48 | myLCD.printf("C"); |
swescott17 | 4:cb3a18844abc | 49 | myLCD.circle(160,100,30,Green); |
swescott17 | 4:cb3a18844abc | 50 | myLCD.locate(260, 100); |
swescott17 | 4:cb3a18844abc | 51 | myLCD.printf("T"); |
swescott17 | 4:cb3a18844abc | 52 | myLCD.circle(260,100,30,Red); |
swescott17 | 1:20661421fa4e | 53 | /*wait(1); |
swescott17 | 0:1ebe73e062a7 | 54 | i2c_port.start(); // forces start condition |
swescott17 | 0:1ebe73e062a7 | 55 | if (interupt == 1){ |
swescott17 | 0:1ebe73e062a7 | 56 | i2c_port.start(); |
swescott17 | 0:1ebe73e062a7 | 57 | i2c_port.write(addr1); |
swescott17 | 0:1ebe73e062a7 | 58 | i2c_port.write(0x30|0x80); |
swescott17 | 0:1ebe73e062a7 | 59 | i2c_port.stop(); |
swescott17 | 0:1ebe73e062a7 | 60 | i2c_port.read(addr1,sensorData,1); |
swescott17 | 0:1ebe73e062a7 | 61 | wait(1); //checks for interupt signal from accelerometer |
swescott17 | 0:1ebe73e062a7 | 62 | if (sensorData[0] & 0x40){ //if one tap |
swescott17 | 0:1ebe73e062a7 | 63 | led1 = 1; |
swescott17 | 0:1ebe73e062a7 | 64 | temp2 = temperature(); |
swescott17 | 0:1ebe73e062a7 | 65 | pc.printf("%f", temp2); |
swescott17 | 0:1ebe73e062a7 | 66 | } |
swescott17 | 0:1ebe73e062a7 | 67 | if (sensorData[0] & 0x20) { //if two taps |
swescott17 | 0:1ebe73e062a7 | 68 | led2 = 1; |
swescott17 | 0:1ebe73e062a7 | 69 | compass_n(avg); |
swescott17 | 1:20661421fa4e | 70 | }*/ |
swescott17 | 0:1ebe73e062a7 | 71 | } |
swescott17 | 0:1ebe73e062a7 | 72 | } |