Hackathon

Dependencies:   C12832 CCS811 MMA7660 Sht31 TSL2561

Fork of Mbed-Connect-Cloud-Demo by Cambridge Hackathon

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main_working.h Source File

main_working.h

00001 //----------------------------------------------------------------------------
00002 // The confidential and proprietary information contained in this file may
00003 // only be used by a person authorised under and to the extent permitted
00004 // by a subsisting licensing agreement from ARM Limited or its affiliates.
00005 //
00006 // (C) COPYRIGHT 2016 ARM Limited or its affiliates.
00007 // ALL RIGHTS RESERVED
00008 //
00009 // This entire notice must be reproduced on all copies of this file
00010 // and copies of this file may only be made by a person if such person is
00011 // permitted to do so under the terms of a subsisting license agreement
00012 // from ARM Limited or its affiliates.
00013 //----------------------------------------------------------------------------
00014 #include "mbed.h"
00015 #include "C12832.h"
00016 #include "CCS811.h"
00017 #include "Sht31.h"
00018 #include "TSL2561.h"
00019 #include "MMA7660.h"
00020 
00021 // GLOBAL VARIABLES HERE
00022 
00023 C12832  lcd(PE_14, PE_12, PD_12, PD_11, PE_9);
00024 Sht31   temp_sensor(PF_0, PF_1);
00025 DigitalOut  led(PB_8, 1);
00026 InterruptIn button(PF_2);
00027 CCS811  air_sensor(PF_0, PF_1);
00028 TSL2561 light_sensor(PF_0, PF_1, TSL2561_ADDR_HIGH);
00029 MMA7660 accel(PF_0, PF_1);
00030 
00031 // FUNCTION DEFINTIONS HERE
00032 
00033 void lcd_print(const char* message) {
00034     lcd.cls();
00035     lcd.locate(0, 3);
00036     lcd.printf(message);
00037 }
00038 
00039 void toggle_led() {
00040     led = !led;
00041 }
00042 
00043 void read_temp() {
00044     float t = temp_sensor.readTemperature();
00045     float h = temp_sensor.readHumidity();
00046     char val[32];
00047     sprintf(val, "TEMP: %3.2fC, HUM: %3.2f%%", t, h);
00048     lcd_print(val);
00049 }
00050 
00051 void read_air() {
00052     air_sensor.init();
00053     uint16_t eco2, tvoc;
00054     air_sensor.readData(&eco2, &tvoc);
00055     char val[32];
00056     sprintf(val, "eCO2: %dppm, TVOC: %dppb", eco2, tvoc);
00057     lcd_print(val);
00058 }
00059 
00060 void read_light() {
00061     int vis = light_sensor.getLuminosity(TSL2561_VISIBLE);
00062     int infr = light_sensor.getLuminosity(TSL2561_INFRARED);
00063     char val[32];
00064     sprintf(val, "VIS: %d, INFR: %d ", vis, infr);
00065     lcd_print(val);
00066 }
00067 
00068 void read_accel() {
00069     float x = accel.x();
00070     float y = accel.y();
00071     float z = accel.z();
00072     char val[32];
00073     sprintf(val, "x=%.2f y=%.2f z=%.2f", x, y, z);
00074     lcd_print(val);
00075 }
00076 
00077 int main() {
00078 
00079     // MAIN CODE HERE
00080     lcd_print("Hello World!");
00081     button.rise(&toggle_led);
00082     light_sensor.begin();
00083     light_sensor.setGain(TSL2561_GAIN_0X);
00084     light_sensor.setTiming(TSL2561_INTEGRATIONTIME_402MS);
00085 
00086     while(1) {
00087         // WHILE LOOP CODE HERE
00088         read_temp();
00089         wait_ms(2000);
00090         read_air();
00091         wait_ms(2000);
00092         read_light();
00093         wait_ms(2000);
00094         read_accel();
00095         wait_ms(2000);
00096     }
00097 
00098 }