A simple example for analog input and EPD usage.
Dependencies: GDEP015OC1 acn_nrf52_saadc aconno_bsp
Fork of acd52832_3_Analog_In by
Diff: main.cpp
- Revision:
- 5:6566725c8835
- Parent:
- 4:f6f94ef38e6a
- Child:
- 6:e848c82b5248
--- a/main.cpp Thu Jun 29 16:21:53 2017 +0000
+++ b/main.cpp Fri Jun 30 11:45:56 2017 +0000
@@ -8,12 +8,19 @@
#include "mbed.h"
#include "acd52832_bsp.h"
#include "GDEP015OC1.h"
+#include "pictures.h"
-#define delay_time (1000)
-#define ADC_MAX_VALUE (4092)
-#define ADC_REF_VOLTAGE (3.6)
-#define VOLTAGE_DIVIDER_RATION (130.0/30)
-#define CURRENT_FACTOR (36.0)
+#define DEBUG (1)
+#define ADC_MAX_VALUE (4092)
+#define ADC_REF_VOLTAGE (3.6)
+#define VOLTAGE_DIVIDER_RATION (130.0/30)
+#define CURRENT_FACTOR (36.0)
+#define BATTERY_MAX_V (14.0)
+#define BATTERY_MIN_V (12.0)
+#define BATTERY_STEP (0.4)
+#define LOW_QUICK_CURRENT (0.5)
+
+
SPI spi(PIN_EPD_MOSI, NC, PIN_EPD_SCK, NC);
GDEP015OC1 epd = GDEP015OC1(spi, PIN_EPD_CS, PIN_EPD_DC, PIN_EPD_RST, PIN_EPD_BUSY);
@@ -24,11 +31,18 @@
int main(){
char buffer[25] = {0};
+ char low_string[25] = "LOW";
+ char quick_string[25] = "QUICK";
float adc1_mean=0, adc2_mean=0, adc3_mean=0;
+ float battery_voltage = 0;
+ float usb1_current = 0, usb2_current = 0;
int count = 0;
- wait_ms(100);
NRF_SAADC->RESOLUTION = 0x00000002; // Set 12b resolution
+
+ epd.empty();
+ epd.writeFull();
+
while(true){
adc1_mean += battery.read_u16();
@@ -41,23 +55,84 @@
adc1_mean /= 10;
adc2_mean /= 10;
adc3_mean /= 10;
+ count = 0;
- count = 0;
- epd.empty();
- epd.writeFull();
+ battery_voltage = adc1_mean*(ADC_REF_VOLTAGE/ADC_MAX_VALUE)*VOLTAGE_DIVIDER_RATION;
+ usb1_current = (CURRENT_FACTOR/ADC_MAX_VALUE)*adc2_mean;
+ usb2_current = (CURRENT_FACTOR/ADC_MAX_VALUE)*adc3_mean;
- sprintf(buffer, "Battery: %5.5fV", adc1_mean*(ADC_REF_VOLTAGE/ADC_MAX_VALUE)*VOLTAGE_DIVIDER_RATION); // Create a string
- epd.writeString(buffer,25,70,0); // Write new data to the buffer
- epd.write(); // Write string to the EPD
+ if(battery_voltage > BATTERY_MAX_V - BATTERY_STEP){
+ //Load image
+ for(uint16_t x=0;x<5000;x++)
+ epd.fill(BS_5[x], x);
+ epd.write();
+ }
+ else if((battery_voltage > BATTERY_MAX_V - BATTERY_STEP * 2) && (battery_voltage < BATTERY_MAX_V - BATTERY_STEP * 1)){
+ //Load image
+ for(uint16_t x=0;x<5000;x++)
+ epd.fill(BS_4[x], x);
+ epd.write();
+ }
+ else if((battery_voltage > BATTERY_MAX_V - BATTERY_STEP * 3) && (battery_voltage < BATTERY_MAX_V - BATTERY_STEP * 2)){
+ //Load image
+ for(uint16_t x=0;x<5000;x++)
+ epd.fill(BS_3[x], x);
+ epd.write();
+ }
+ else if((battery_voltage > BATTERY_MAX_V - BATTERY_STEP * 4) && (battery_voltage < BATTERY_MAX_V - BATTERY_STEP * 3)){
+ //Load image
+ for(uint16_t x=0;x<5000;x++)
+ epd.fill(BS_2[x], x);
+ epd.write();
+ }
+ else if((battery_voltage > BATTERY_MAX_V - BATTERY_STEP * 5) && (battery_voltage < BATTERY_MAX_V - BATTERY_STEP * 4)){
+ //Load image
+ for(uint16_t x=0;x<5000;x++)
+ epd.fill(BS_1[x], x);
+ epd.write();
+ }
+ else if(battery_voltage < BATTERY_MAX_V - BATTERY_STEP * 5){
+ //Load image
+ for(uint16_t x=0;x<5000;x++)
+ epd.fill(BS_E[x], x);
+ epd.write();
+ }
+
+ if(usb1_current < (float)LOW_QUICK_CURRENT){
+ epd.writeString(low_string, 25, 180, 0);
+ epd.write();
+ }
+ else{
+ epd.writeString(quick_string, 25, 180, 0);
+ epd.write();
+ }
+
+ if(usb2_current < (float)LOW_QUICK_CURRENT){
+ epd.writeString(low_string, 135, 180, 0);
+ epd.write();
+ }
+ else{
+ epd.writeString(quick_string, 135, 180, 0);
+ epd.write();
+ }
- sprintf(buffer, "USB1: %5.5fA", (CURRENT_FACTOR/ADC_MAX_VALUE)*adc2_mean); // Create a string
- epd.writeString(buffer,25,90,0); // Write new data to the buffer
- epd.write(); // Write string to the EPD
- sprintf(buffer, "USB1: %5.5fA", (CURRENT_FACTOR/ADC_MAX_VALUE)*adc3_mean); // Create a string
- epd.writeString(buffer,25,110,0); // Write new data to the buffer
- epd.write(); // Write string to the EPD
+ #if DEBUG
+ /*
+ // Print voltage and current values in debug mode
+ sprintf(buffer, "Battery: %5.5fV", adc1_mean*(ADC_REF_VOLTAGE/ADC_MAX_VALUE)*VOLTAGE_DIVIDER_RATION); // Create a string
+ epd.writeString(buffer,25,95,0); // Write new data to the buffer
+ epd.write(); // Write string to the EPD
+ */
+ sprintf(buffer, "USB1: %5.5fA", (CURRENT_FACTOR/ADC_MAX_VALUE)*adc2_mean); // Create a string
+ epd.writeString(buffer,5,190,0); // Write new data to the buffer
+ epd.write(); // Write string to the EPD
+
+ sprintf(buffer, "USB1: %5.5fA", (CURRENT_FACTOR/ADC_MAX_VALUE)*adc3_mean); // Create a string
+ epd.writeString(buffer,105,190,0); // Write new data to the buffer
+ epd.write(); // Write string to the EPD
+ #endif
adc1_mean = 0;
adc2_mean = 0;
