A simple example for analog input and EPD usage.

Dependencies:   GDEP015OC1 acn_nrf52_saadc aconno_bsp

Fork of acd52832_Car_battery_ch by Jurica Resetar

main.cpp

Committer:
jurica238814
Date:
2017-06-29
Revision:
4:f6f94ef38e6a
Parent:
3:4fb622e929d0
Child:
5:6566725c8835

File content as of revision 4:f6f94ef38e6a:

/* Copyright (c) 2017 Aconno. All Rights Reserved.
 *
 * Licensees are granted free, non-transferable use of the information. NO
 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
 * the file.
 */
 
#include "mbed.h"
#include "acd52832_bsp.h"
#include "GDEP015OC1.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)

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);

AnalogIn  battery   (p28);
AnalogIn  usb1      (p29);
AnalogIn  usb2      (p30);

int main(){
    char buffer[25] = {0};
    float adc1_mean=0, adc2_mean=0, adc3_mean=0;
    int count = 0;
    
    wait_ms(100);
    NRF_SAADC->RESOLUTION = 0x00000002;             // Set 12b resolution
    while(true){   
        
        adc1_mean += battery.read_u16();
        adc2_mean += usb1.read_u16();
        adc3_mean += usb2.read_u16();
        count ++;
        
        if (count == 10){
            
            adc1_mean /= 10;
            adc2_mean /= 10;
            adc3_mean /= 10;
            
            count = 0;
            epd.empty();
            epd.writeFull(); 
            
            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
            
            
            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
            
            adc1_mean = 0;
            adc2_mean = 0;
            adc3_mean = 0;
        }
    }
}