Augustine Kizito / Mbed 2 deprecated Solar_Powered_Smart_Camera

Dependencies:   Adafruit_GFX Adafruit_ST7735 INA219 MODSERIAL MbedJSONValue mbed-rtos mbed

Committer:
OHstin
Date:
Fri Jul 01 13:33:14 2016 +0000
Revision:
0:5139f11cfc62
Child:
1:1354a7ebd0c6
Setting up of pots and buttons to mbed complete

Who changed what in which revision?

UserRevisionLine numberNew contents of line
OHstin 0:5139f11cfc62 1 #include "mbed.h"
OHstin 0:5139f11cfc62 2 #include "Adafruit_ST7735.h"
OHstin 0:5139f11cfc62 3
OHstin 0:5139f11cfc62 4
OHstin 0:5139f11cfc62 5 Adafruit_ST7735 tft(p11, p12, p13, p10, p8, p9); // MOSI, MISO, SCLK, SSEL, TFT_DC, TFT_RST
OHstin 0:5139f11cfc62 6 //LEDs used to display output
OHstin 0:5139f11cfc62 7
OHstin 0:5139f11cfc62 8 DigitalIn enable1(p21);
OHstin 0:5139f11cfc62 9 DigitalIn enable2(p22);
OHstin 0:5139f11cfc62 10 DigitalIn enable3(p23);
OHstin 0:5139f11cfc62 11
OHstin 0:5139f11cfc62 12 DigitalOut led1(LED1);
OHstin 0:5139f11cfc62 13 DigitalOut led2(LED2);
OHstin 0:5139f11cfc62 14 DigitalOut led3(LED3);
OHstin 0:5139f11cfc62 15
OHstin 0:5139f11cfc62 16 AnalogIn ain(p20);
OHstin 0:5139f11cfc62 17 AnalogIn ain1(p19);
OHstin 0:5139f11cfc62 18 AnalogIn ain2(p18);
OHstin 0:5139f11cfc62 19
OHstin 0:5139f11cfc62 20 DigitalOut myled(LED1);
OHstin 0:5139f11cfc62 21
OHstin 0:5139f11cfc62 22 void testdrawtext(char *text, uint16_t color);
OHstin 0:5139f11cfc62 23
OHstin 0:5139f11cfc62 24 float currentFloat = 1.0;
OHstin 0:5139f11cfc62 25
OHstin 0:5139f11cfc62 26
OHstin 0:5139f11cfc62 27 int main()
OHstin 0:5139f11cfc62 28 {
OHstin 0:5139f11cfc62 29 // Use this initializer if you're using a 1.8" TFT
OHstin 0:5139f11cfc62 30 tft.initR(INITR_BLACKTAB); // initialize a ST7735S chip, black tab
OHstin 0:5139f11cfc62 31
OHstin 0:5139f11cfc62 32 tft.fillScreen(ST7735_BLACK);
OHstin 0:5139f11cfc62 33 tft.setRotation(1);
OHstin 0:5139f11cfc62 34 char current_text[40];
OHstin 0:5139f11cfc62 35 //sprintf(current_text, "current is : %+6.3f [mA]", current.read_current());
OHstin 0:5139f11cfc62 36 //testdrawtext(current_text, ST7735_WHITE);
OHstin 0:5139f11cfc62 37 //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);
OHstin 0:5139f11cfc62 38 wait_ms(1000);
OHstin 0:5139f11cfc62 39
OHstin 0:5139f11cfc62 40 while(1) {
OHstin 0:5139f11cfc62 41 //tft.fillScreen(ST7735_BLACK);
OHstin 0:5139f11cfc62 42 float newCurrent = ain2;
OHstin 0:5139f11cfc62 43 sprintf(current_text, "%+6.1f [mA]", newCurrent);
OHstin 0:5139f11cfc62 44 testdrawtext(current_text, ST7735_WHITE);
OHstin 0:5139f11cfc62 45 //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);
OHstin 0:5139f11cfc62 46
OHstin 0:5139f11cfc62 47 wait_ms(1000);
OHstin 0:5139f11cfc62 48
OHstin 0:5139f11cfc62 49 if (newCurrent == currentFloat){
OHstin 0:5139f11cfc62 50
OHstin 0:5139f11cfc62 51 }
OHstin 0:5139f11cfc62 52 else{
OHstin 0:5139f11cfc62 53
OHstin 0:5139f11cfc62 54 testdrawtext(current_text, ST7735_BLACK);
OHstin 0:5139f11cfc62 55 }
OHstin 0:5139f11cfc62 56 currentFloat = newCurrent;
OHstin 0:5139f11cfc62 57
OHstin 0:5139f11cfc62 58 if (enable1){
OHstin 0:5139f11cfc62 59 led1 = !led1;
OHstin 0:5139f11cfc62 60 }
OHstin 0:5139f11cfc62 61
OHstin 0:5139f11cfc62 62 if (enable2){
OHstin 0:5139f11cfc62 63 led2 = !led2;
OHstin 0:5139f11cfc62 64 }
OHstin 0:5139f11cfc62 65
OHstin 0:5139f11cfc62 66 if (enable3){
OHstin 0:5139f11cfc62 67 led3 = !led3;
OHstin 0:5139f11cfc62 68 }
OHstin 0:5139f11cfc62 69
OHstin 0:5139f11cfc62 70
OHstin 0:5139f11cfc62 71
OHstin 0:5139f11cfc62 72 }
OHstin 0:5139f11cfc62 73 }
OHstin 0:5139f11cfc62 74
OHstin 0:5139f11cfc62 75 void testdrawtext(char *text, uint16_t color)
OHstin 0:5139f11cfc62 76 {
OHstin 0:5139f11cfc62 77 tft.setCursor(0, 0);
OHstin 0:5139f11cfc62 78 tft.setTextColor(color);
OHstin 0:5139f11cfc62 79 tft.setTextWrap(true);
OHstin 0:5139f11cfc62 80 tft.printf("%s",text);
OHstin 0:5139f11cfc62 81 }