![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Mini Project 10: Displaying stuff from day 7
Dependencies: DmTouch_UniGraphic UniGraphic mbed
main.cpp@0:1ebe73e062a7, 2017-01-17 (annotated)
- Committer:
- swescott17
- Date:
- Tue Jan 17 18:14:15 2017 +0000
- Revision:
- 0:1ebe73e062a7
- Child:
- 1:20661421fa4e
Added files and libraries from other mini projects;
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 | 0:1ebe73e062a7 | 3 | |
swescott17 | 0:1ebe73e062a7 | 4 | #include "mbed.h" |
swescott17 | 0:1ebe73e062a7 | 5 | #include "compass_sensor.h" |
swescott17 | 0:1ebe73e062a7 | 6 | #include "temp_sensor.h" |
swescott17 | 0:1ebe73e062a7 | 7 | #include "acceler_sensor.h" |
swescott17 | 0:1ebe73e062a7 | 8 | Serial pc(USBTX, USBRX); |
swescott17 | 0:1ebe73e062a7 | 9 | I2C i2c_port(p9, p10); // configures pins 9,10 for I2C communication with external sensors |
swescott17 | 0:1ebe73e062a7 | 10 | float temp2; |
swescott17 | 0:1ebe73e062a7 | 11 | int avg; |
swescott17 | 0:1ebe73e062a7 | 12 | const int addr1 = 0x53<<1; |
swescott17 | 0:1ebe73e062a7 | 13 | DigitalOut led1(LED1); // configures mbed internal LED 1 |
swescott17 | 0:1ebe73e062a7 | 14 | DigitalOut led2(LED2); // configures mbed internal LED 2 |
swescott17 | 0:1ebe73e062a7 | 15 | DigitalIn interupt(p20); // sets accelerometer interupt as digital input at pin 20; |
swescott17 | 0:1ebe73e062a7 | 16 | int main() { |
swescott17 | 0:1ebe73e062a7 | 17 | char sensorData[1]; |
swescott17 | 0:1ebe73e062a7 | 18 | led1 = 0; |
swescott17 | 0:1ebe73e062a7 | 19 | led2 = 0; |
swescott17 | 0:1ebe73e062a7 | 20 | avg = compass_config(); |
swescott17 | 0:1ebe73e062a7 | 21 | temperature_config(); |
swescott17 | 0:1ebe73e062a7 | 22 | |
swescott17 | 0:1ebe73e062a7 | 23 | acceleration_n(); |
swescott17 | 0:1ebe73e062a7 | 24 | while(1){ |
swescott17 | 0:1ebe73e062a7 | 25 | wait(1); |
swescott17 | 0:1ebe73e062a7 | 26 | i2c_port.start(); // forces start condition |
swescott17 | 0:1ebe73e062a7 | 27 | if (interupt == 1){ |
swescott17 | 0:1ebe73e062a7 | 28 | i2c_port.start(); |
swescott17 | 0:1ebe73e062a7 | 29 | i2c_port.write(addr1); |
swescott17 | 0:1ebe73e062a7 | 30 | i2c_port.write(0x30|0x80); |
swescott17 | 0:1ebe73e062a7 | 31 | i2c_port.stop(); |
swescott17 | 0:1ebe73e062a7 | 32 | i2c_port.read(addr1,sensorData,1); |
swescott17 | 0:1ebe73e062a7 | 33 | wait(1); //checks for interupt signal from accelerometer |
swescott17 | 0:1ebe73e062a7 | 34 | if (sensorData[0] & 0x40){ //if one tap |
swescott17 | 0:1ebe73e062a7 | 35 | led1 = 1; |
swescott17 | 0:1ebe73e062a7 | 36 | temp2 = temperature(); |
swescott17 | 0:1ebe73e062a7 | 37 | pc.printf("%f", temp2); |
swescott17 | 0:1ebe73e062a7 | 38 | } |
swescott17 | 0:1ebe73e062a7 | 39 | if (sensorData[0] & 0x20) { //if two taps |
swescott17 | 0:1ebe73e062a7 | 40 | led2 = 1; |
swescott17 | 0:1ebe73e062a7 | 41 | compass_n(avg); |
swescott17 | 0:1ebe73e062a7 | 42 | } |
swescott17 | 0:1ebe73e062a7 | 43 | } |
swescott17 | 0:1ebe73e062a7 | 44 | } |
swescott17 | 0:1ebe73e062a7 | 45 | } |