|
13 | 13 | #include <Adafruit_LittleFS.h>
|
14 | 14 | #include <InternalFileSystem.h>
|
15 | 15 | #include <Wire.h>
|
| 16 | +#include <Adafruit_NeoPixel.h> |
16 | 17 | #include "Adafruit_MCP9808.h"
|
17 | 18 |
|
18 | 19 | // Read temperature in degrees Fahrenheit
|
19 | 20 | #define TEMPERATURE_F
|
20 | 21 | // uncomment the following line if you want to read temperature in degrees Celsius
|
21 | 22 | // #define TEMPERATURE_C
|
22 | 23 |
|
| 24 | +// Feather NRF52840 Built-in NeoPixel |
| 25 | +#define PIN 16 |
| 26 | +Adafruit_NeoPixel pixels(1, PIN, NEO_GRB + NEO_KHZ800); |
| 27 | + |
| 28 | +// Maximum temperature value for armband's fever indicator |
| 29 | +// NOTE: This is in degrees Fahrenheit, please adjust |
| 30 | +float fever_temp = 100.4; |
| 31 | + |
| 32 | +// offset is +0.5-1.0 degrees to make |
| 33 | +// axillary temperature comparible to ear or temporal. |
| 34 | +float temp_offset = 0.5; |
| 35 | + |
23 | 36 | // Sensor read timeout, in minutes
|
24 | 37 | // NOTE: Measuring your armpit temperature for a minimum
|
25 | 38 | // of 12 minutes is equivalent to measuring your core body temperature.
|
26 |
| -const long interval = 60000; |
27 |
| - |
28 |
| -// last time the temperature was read |
29 |
| -unsigned long prv_ms = 0; |
| 39 | +const long interval = 1; |
30 | 40 |
|
31 | 41 | // BLE Service
|
32 | 42 | BLEDfu bledfu; // OTA DFU service
|
@@ -87,47 +97,60 @@ void setup() {
|
87 | 97 | startAdv();
|
88 | 98 |
|
89 | 99 | Serial.println("Please use Adafruit's Bluefruit LE app to connect in UART mode");
|
90 |
| - Serial.println("Once connected, enter character(s) that you wish to send"); |
| 100 | + |
| 101 | + // initialize neopixel object |
| 102 | + pixels.begin(); |
| 103 | + |
| 104 | + // set all pixel colors to 'off' |
| 105 | + pixels.clear(); |
91 | 106 |
|
92 | 107 | }
|
93 | 108 |
|
94 | 109 | void loop() {
|
95 | 110 |
|
96 |
| - unsigned long current_ms = millis(); |
97 |
| - |
98 |
| - if (current_ms - prv_ms >= (1000*5)) { |
99 |
| - prv_ms = current_ms; |
100 |
| - |
101 |
| - // wakes up MCP9808 - power consumption ~200 mikro Ampere |
102 |
| - Serial.println("Wake up MCP9808"); |
103 |
| - tempsensor.wake(); |
104 |
| - |
105 |
| - // read and print the temperature |
106 |
| - Serial.print("Temp: "); |
107 |
| - #ifdef TEMPERATURE_F |
108 |
| - float temp = tempsensor.readTempF(); |
109 |
| - Serial.print(temp); |
110 |
| - Serial.println("*F."); |
111 |
| - #endif |
112 |
| - |
113 |
| - #ifdef TEMPERATURE_C |
114 |
| - float temp = tempsensor.readTempC(); |
115 |
| - Serial.print(temp); |
116 |
| - Serial.println("*C."); |
117 |
| - #endif |
118 |
| - |
119 |
| - char buffer [8]; |
120 |
| - //itoa(temp, buffer, 10); |
121 |
| - snprintf(buffer, sizeof(buffer) - 1, "%0.*f", 2, temp); |
122 |
| - bleuart.write(buffer); |
123 |
| - bleuart.write("\n"); |
124 |
| - |
125 |
| - // shutdown MSP9808 - power consumption ~0.1 mikro Ampere |
126 |
| - // stops temperature sampling |
127 |
| - Serial.println("Shutting down MCP9808"); |
128 |
| - tempsensor.shutdown_wake(1); |
| 111 | + // wakes up MCP9808 - power consumption ~200 mikro Ampere |
| 112 | + Serial.println("Wake up MCP9808"); |
| 113 | + tempsensor.wake(); |
| 114 | + |
| 115 | + // read and print the temperature |
| 116 | + Serial.print("Temp: "); |
| 117 | + #ifdef TEMPERATURE_F |
| 118 | + float temp = tempsensor.readTempF(); |
| 119 | + Serial.print(temp); |
| 120 | + Serial.println("*F."); |
| 121 | + #endif |
| 122 | + |
| 123 | + #ifdef TEMPERATURE_C |
| 124 | + float temp = tempsensor.readTempC(); |
| 125 | + Serial.print(temp); |
| 126 | + Serial.println("*C."); |
| 127 | + #endif |
| 128 | + |
| 129 | + // add temp_offset |
| 130 | + temp += temp_offset; |
| 131 | + |
| 132 | + if (temp >= fever_temp) { |
| 133 | + pixels.setPixelColor(1, pixels.Color(255, 0, 0)); |
| 134 | + pixels.show(); |
| 135 | + } |
| 136 | + else { |
| 137 | + pixels.clear(); |
129 | 138 | }
|
130 | 139 |
|
| 140 | + char buffer [8]; |
| 141 | + snprintf(buffer, sizeof(buffer) - 1, "%0.*f", 2, temp); |
| 142 | + bleuart.write(buffer); |
| 143 | + |
| 144 | + // shutdown MSP9808 - power consumption ~0.1 mikro Ampere |
| 145 | + // stops temperature sampling |
| 146 | + Serial.println("Shutting down MCP9808"); |
| 147 | + tempsensor.shutdown_wake(1); |
| 148 | + |
| 149 | + // sleep for interval minutes |
| 150 | + // NOTE: NRF delay puts the MCU into a sleep mode: |
| 151 | + // (https://www.freertos.org/low-power-tickless-rtos.html) |
| 152 | + delay(1000*60*interval); |
| 153 | + |
131 | 154 | }
|
132 | 155 |
|
133 | 156 |
|
|
0 commit comments