Augustine Kizito / Mbed 2 deprecated Solar_Powered_Smart_Camera

Dependencies:   Adafruit_GFX Adafruit_ST7735 INA219 MODSERIAL MbedJSONValue mbed-rtos mbed

main.cpp

Committer:
OHstin
Date:
2016-07-01
Revision:
0:5139f11cfc62
Child:
1:1354a7ebd0c6

File content as of revision 0:5139f11cfc62:

#include "mbed.h"
#include "Adafruit_ST7735.h"


Adafruit_ST7735 tft(p11, p12, p13, p10, p8, p9); // MOSI, MISO, SCLK, SSEL, TFT_DC, TFT_RST
//LEDs used to display output

DigitalIn enable1(p21);
DigitalIn enable2(p22);
DigitalIn enable3(p23);

DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);

AnalogIn ain(p20);
AnalogIn ain1(p19);
AnalogIn ain2(p18);

DigitalOut myled(LED1);

void testdrawtext(char *text, uint16_t color);

float currentFloat = 1.0;


int main()
{
    // Use this initializer if you're using a 1.8" TFT
    tft.initR(INITR_BLACKTAB);   // initialize a ST7735S chip, black tab

    tft.fillScreen(ST7735_BLACK);
    tft.setRotation(1);
    char current_text[40];
    //sprintf(current_text, "current is : %+6.3f [mA]", current.read_current());
    //testdrawtext(current_text, ST7735_WHITE);
    //testdrawtext("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa, fringilla sed malesuada et, malesuada sit amet turpis. Sed porttitor neque ut ante pretium vitae malesuada nunc bibendum. Nullam aliquet ultrices massa eu hendrerit. Ut sed nisi lorem. In vestibulum purus a tortor imperdiet posuere. ", ST7735_WHITE);
    wait_ms(1000);

    while(1) {
        //tft.fillScreen(ST7735_BLACK);
        float newCurrent = ain2;
        sprintf(current_text, "%+6.1f [mA]", newCurrent);
        testdrawtext(current_text, ST7735_WHITE);
        //testdrawtext("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa, fringilla sed malesuada et, malesuada sit amet turpis. Sed porttitor neque ut ante pretium vitae malesuada nunc bibendum. Nullam aliquet ultrices massa eu hendrerit. Ut sed nisi lorem. In vestibulum purus a tortor imperdiet posuere. ", ST7735_WHITE);
        
        wait_ms(1000);
        
        if (newCurrent == currentFloat){
            
        }
        else{
        
            testdrawtext(current_text, ST7735_BLACK);
        }
        currentFloat = newCurrent;
        
        if (enable1){
            led1 = !led1;
            }
            
        if (enable2){
            led2 = !led2;
            }
            
        if (enable3){
            led3 = !led3;
            }
        
        
        
    }
}

void testdrawtext(char *text, uint16_t color)
{
    tft.setCursor(0, 0);
    tft.setTextColor(color);
    tft.setTextWrap(true);
    tft.printf("%s",text);
}