![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Mini Project 10: Displaying stuff from day 7
Dependencies: DmTouch_UniGraphic UniGraphic mbed
main.cpp
- Committer:
- swescott17
- Date:
- 2017-01-17
- Revision:
- 0:1ebe73e062a7
- Child:
- 1:20661421fa4e
File content as of revision 0:1ebe73e062a7:
//MiniProject Day 7 //If tapped, the mbed will either read from a temperature sensor or the compass #include "mbed.h" #include "compass_sensor.h" #include "temp_sensor.h" #include "acceler_sensor.h" Serial pc(USBTX, USBRX); I2C i2c_port(p9, p10); // configures pins 9,10 for I2C communication with external sensors float temp2; int avg; const int addr1 = 0x53<<1; DigitalOut led1(LED1); // configures mbed internal LED 1 DigitalOut led2(LED2); // configures mbed internal LED 2 DigitalIn interupt(p20); // sets accelerometer interupt as digital input at pin 20; int main() { char sensorData[1]; led1 = 0; led2 = 0; avg = compass_config(); temperature_config(); acceleration_n(); while(1){ wait(1); i2c_port.start(); // forces start condition if (interupt == 1){ i2c_port.start(); i2c_port.write(addr1); i2c_port.write(0x30|0x80); i2c_port.stop(); i2c_port.read(addr1,sensorData,1); wait(1); //checks for interupt signal from accelerometer if (sensorData[0] & 0x40){ //if one tap led1 = 1; temp2 = temperature(); pc.printf("%f", temp2); } if (sensorData[0] & 0x20) { //if two taps led2 = 1; compass_n(avg); } } } }