![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Hackathon
Dependencies: C12832 CCS811 MMA7660 Sht31 TSL2561
Fork of Mbed-Connect-Cloud-Demo by
working/main_working.h@1:6791f0504ab0, 2017-11-09 (annotated)
- Committer:
- Jenny Plunkett
- Date:
- Thu Nov 09 12:36:44 2017 -0600
- Revision:
- 1:6791f0504ab0
- Parent:
- 0:801b555a3dd8
Fixed typo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Jenny Plunkett |
0:801b555a3dd8 | 1 | //---------------------------------------------------------------------------- |
Jenny Plunkett |
0:801b555a3dd8 | 2 | // The confidential and proprietary information contained in this file may |
Jenny Plunkett |
0:801b555a3dd8 | 3 | // only be used by a person authorised under and to the extent permitted |
Jenny Plunkett |
0:801b555a3dd8 | 4 | // by a subsisting licensing agreement from ARM Limited or its affiliates. |
Jenny Plunkett |
0:801b555a3dd8 | 5 | // |
Jenny Plunkett |
0:801b555a3dd8 | 6 | // (C) COPYRIGHT 2016 ARM Limited or its affiliates. |
Jenny Plunkett |
0:801b555a3dd8 | 7 | // ALL RIGHTS RESERVED |
Jenny Plunkett |
0:801b555a3dd8 | 8 | // |
Jenny Plunkett |
0:801b555a3dd8 | 9 | // This entire notice must be reproduced on all copies of this file |
Jenny Plunkett |
0:801b555a3dd8 | 10 | // and copies of this file may only be made by a person if such person is |
Jenny Plunkett |
0:801b555a3dd8 | 11 | // permitted to do so under the terms of a subsisting license agreement |
Jenny Plunkett |
0:801b555a3dd8 | 12 | // from ARM Limited or its affiliates. |
Jenny Plunkett |
0:801b555a3dd8 | 13 | //---------------------------------------------------------------------------- |
Jenny Plunkett |
0:801b555a3dd8 | 14 | #include "mbed.h" |
Jenny Plunkett |
0:801b555a3dd8 | 15 | #include "C12832.h" |
Jenny Plunkett |
0:801b555a3dd8 | 16 | #include "CCS811.h" |
Jenny Plunkett |
0:801b555a3dd8 | 17 | #include "Sht31.h" |
Jenny Plunkett |
0:801b555a3dd8 | 18 | #include "TSL2561.h" |
Jenny Plunkett |
0:801b555a3dd8 | 19 | #include "MMA7660.h" |
Jenny Plunkett |
0:801b555a3dd8 | 20 | |
Jenny Plunkett |
0:801b555a3dd8 | 21 | // GLOBAL VARIABLES HERE |
Jenny Plunkett |
0:801b555a3dd8 | 22 | |
Jenny Plunkett |
0:801b555a3dd8 | 23 | C12832 lcd(PE_14, PE_12, PD_12, PD_11, PE_9); |
Jenny Plunkett |
0:801b555a3dd8 | 24 | Sht31 temp_sensor(PF_0, PF_1); |
Jenny Plunkett |
0:801b555a3dd8 | 25 | DigitalOut led(PB_8, 1); |
Jenny Plunkett |
0:801b555a3dd8 | 26 | InterruptIn button(PF_2); |
Jenny Plunkett |
0:801b555a3dd8 | 27 | CCS811 air_sensor(PF_0, PF_1); |
Jenny Plunkett |
0:801b555a3dd8 | 28 | TSL2561 light_sensor(PF_0, PF_1, TSL2561_ADDR_HIGH); |
Jenny Plunkett |
0:801b555a3dd8 | 29 | MMA7660 accel(PF_0, PF_1); |
Jenny Plunkett |
0:801b555a3dd8 | 30 | |
Jenny Plunkett |
0:801b555a3dd8 | 31 | // FUNCTION DEFINTIONS HERE |
Jenny Plunkett |
0:801b555a3dd8 | 32 | |
Jenny Plunkett |
0:801b555a3dd8 | 33 | void lcd_print(const char* message) { |
Jenny Plunkett |
0:801b555a3dd8 | 34 | lcd.cls(); |
Jenny Plunkett |
0:801b555a3dd8 | 35 | lcd.locate(0, 3); |
Jenny Plunkett |
0:801b555a3dd8 | 36 | lcd.printf(message); |
Jenny Plunkett |
0:801b555a3dd8 | 37 | } |
Jenny Plunkett |
0:801b555a3dd8 | 38 | |
Jenny Plunkett |
0:801b555a3dd8 | 39 | void toggle_led() { |
Jenny Plunkett |
0:801b555a3dd8 | 40 | led = !led; |
Jenny Plunkett |
0:801b555a3dd8 | 41 | } |
Jenny Plunkett |
0:801b555a3dd8 | 42 | |
Jenny Plunkett |
0:801b555a3dd8 | 43 | void read_temp() { |
Jenny Plunkett |
0:801b555a3dd8 | 44 | float t = temp_sensor.readTemperature(); |
Jenny Plunkett |
0:801b555a3dd8 | 45 | float h = temp_sensor.readHumidity(); |
Jenny Plunkett |
0:801b555a3dd8 | 46 | char val[32]; |
Jenny Plunkett |
0:801b555a3dd8 | 47 | sprintf(val, "TEMP: %3.2fC, HUM: %3.2f%%", t, h); |
Jenny Plunkett |
0:801b555a3dd8 | 48 | lcd_print(val); |
Jenny Plunkett |
0:801b555a3dd8 | 49 | } |
Jenny Plunkett |
0:801b555a3dd8 | 50 | |
Jenny Plunkett |
0:801b555a3dd8 | 51 | void read_air() { |
Jenny Plunkett |
0:801b555a3dd8 | 52 | air_sensor.init(); |
Jenny Plunkett |
0:801b555a3dd8 | 53 | uint16_t eco2, tvoc; |
Jenny Plunkett |
0:801b555a3dd8 | 54 | air_sensor.readData(&eco2, &tvoc); |
Jenny Plunkett |
0:801b555a3dd8 | 55 | char val[32]; |
Jenny Plunkett |
1:6791f0504ab0 | 56 | sprintf(val, "eCO2: %dppm, TVOC: %dppb", eco2, tvoc); |
Jenny Plunkett |
0:801b555a3dd8 | 57 | lcd_print(val); |
Jenny Plunkett |
0:801b555a3dd8 | 58 | } |
Jenny Plunkett |
0:801b555a3dd8 | 59 | |
Jenny Plunkett |
0:801b555a3dd8 | 60 | void read_light() { |
Jenny Plunkett |
0:801b555a3dd8 | 61 | int vis = light_sensor.getLuminosity(TSL2561_VISIBLE); |
Jenny Plunkett |
0:801b555a3dd8 | 62 | int infr = light_sensor.getLuminosity(TSL2561_INFRARED); |
Jenny Plunkett |
0:801b555a3dd8 | 63 | char val[32]; |
Jenny Plunkett |
0:801b555a3dd8 | 64 | sprintf(val, "VIS: %d, INFR: %d ", vis, infr); |
Jenny Plunkett |
0:801b555a3dd8 | 65 | lcd_print(val); |
Jenny Plunkett |
0:801b555a3dd8 | 66 | } |
Jenny Plunkett |
0:801b555a3dd8 | 67 | |
Jenny Plunkett |
0:801b555a3dd8 | 68 | void read_accel() { |
Jenny Plunkett |
0:801b555a3dd8 | 69 | float x = accel.x(); |
Jenny Plunkett |
0:801b555a3dd8 | 70 | float y = accel.y(); |
Jenny Plunkett |
0:801b555a3dd8 | 71 | float z = accel.z(); |
Jenny Plunkett |
0:801b555a3dd8 | 72 | char val[32]; |
Jenny Plunkett |
0:801b555a3dd8 | 73 | sprintf(val, "x=%.2f y=%.2f z=%.2f", x, y, z); |
Jenny Plunkett |
0:801b555a3dd8 | 74 | lcd_print(val); |
Jenny Plunkett |
0:801b555a3dd8 | 75 | } |
Jenny Plunkett |
0:801b555a3dd8 | 76 | |
Jenny Plunkett |
0:801b555a3dd8 | 77 | int main() { |
Jenny Plunkett |
0:801b555a3dd8 | 78 | |
Jenny Plunkett |
0:801b555a3dd8 | 79 | // MAIN CODE HERE |
Jenny Plunkett |
0:801b555a3dd8 | 80 | lcd_print("Hello World!"); |
Jenny Plunkett |
0:801b555a3dd8 | 81 | button.rise(&toggle_led); |
Jenny Plunkett |
0:801b555a3dd8 | 82 | light_sensor.begin(); |
Jenny Plunkett |
0:801b555a3dd8 | 83 | light_sensor.setGain(TSL2561_GAIN_0X); |
Jenny Plunkett |
0:801b555a3dd8 | 84 | light_sensor.setTiming(TSL2561_INTEGRATIONTIME_402MS); |
Jenny Plunkett |
0:801b555a3dd8 | 85 | |
Jenny Plunkett |
0:801b555a3dd8 | 86 | while(1) { |
Jenny Plunkett |
0:801b555a3dd8 | 87 | // WHILE LOOP CODE HERE |
Jenny Plunkett |
0:801b555a3dd8 | 88 | read_temp(); |
Jenny Plunkett |
0:801b555a3dd8 | 89 | wait_ms(2000); |
Jenny Plunkett |
0:801b555a3dd8 | 90 | read_air(); |
Jenny Plunkett |
0:801b555a3dd8 | 91 | wait_ms(2000); |
Jenny Plunkett |
0:801b555a3dd8 | 92 | read_light(); |
Jenny Plunkett |
0:801b555a3dd8 | 93 | wait_ms(2000); |
Jenny Plunkett |
0:801b555a3dd8 | 94 | read_accel(); |
Jenny Plunkett |
0:801b555a3dd8 | 95 | wait_ms(2000); |
Jenny Plunkett |
0:801b555a3dd8 | 96 | } |
Jenny Plunkett |
0:801b555a3dd8 | 97 | |
Jenny Plunkett |
0:801b555a3dd8 | 98 | } |