Augustine Kizito / Mbed 2 deprecated Solar_Powered_Smart_Camera

Dependencies:   Adafruit_GFX Adafruit_ST7735 INA219 MODSERIAL MbedJSONValue mbed-rtos mbed

Committer:
OHstin
Date:
Mon Jul 18 04:31:21 2016 +0000
Revision:
2:104bec169fb6
Parent:
1:1354a7ebd0c6
Child:
3:7666de697752
Output Icon added

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 1:1354a7ebd0c6 4 Adafruit_ST7735 tft(p11, p12, p13, p10, p8, p9); // MOSI, MISO, SCLK, SSEL, TFT_DC, TFT_RST
OHstin 1:1354a7ebd0c6 5 #include "BatteryIcon.h"
OHstin 2:104bec169fb6 6 #include "SolarIcon.h"
OHstin 2:104bec169fb6 7 #include "OutputIcon.h"
OHstin 2:104bec169fb6 8 #include "SettingsIcon.h"
OHstin 0:5139f11cfc62 9
OHstin 1:1354a7ebd0c6 10
OHstin 0:5139f11cfc62 11 //LEDs used to display output
OHstin 0:5139f11cfc62 12
OHstin 0:5139f11cfc62 13 DigitalIn enable1(p21);
OHstin 0:5139f11cfc62 14 DigitalIn enable2(p22);
OHstin 0:5139f11cfc62 15 DigitalIn enable3(p23);
OHstin 0:5139f11cfc62 16
OHstin 0:5139f11cfc62 17 DigitalOut led1(LED1);
OHstin 0:5139f11cfc62 18 DigitalOut led2(LED2);
OHstin 0:5139f11cfc62 19 DigitalOut led3(LED3);
OHstin 0:5139f11cfc62 20
OHstin 0:5139f11cfc62 21 AnalogIn ain(p20);
OHstin 0:5139f11cfc62 22 AnalogIn ain1(p19);
OHstin 0:5139f11cfc62 23 AnalogIn ain2(p18);
OHstin 0:5139f11cfc62 24
OHstin 0:5139f11cfc62 25 DigitalOut myled(LED1);
OHstin 0:5139f11cfc62 26
OHstin 2:104bec169fb6 27 void testdrawtext(char *text, uint16_t color);
OHstin 1:1354a7ebd0c6 28
OHstin 2:104bec169fb6 29 // battery icon coordinates
OHstin 2:104bec169fb6 30 int startingWidth = 15;
OHstin 2:104bec169fb6 31 int startingHeight = 7;
OHstin 1:1354a7ebd0c6 32
OHstin 2:104bec169fb6 33 // solar icon coordinates
OHstin 2:104bec169fb6 34 int xCoord = 10;
OHstin 2:104bec169fb6 35 int yCoord = 65;
OHstin 0:5139f11cfc62 36
OHstin 2:104bec169fb6 37 // output icon coordinates
OHstin 2:104bec169fb6 38 int xCoord2 = 100;
OHstin 2:104bec169fb6 39 int yCoord2 = 10;
OHstin 1:1354a7ebd0c6 40
OHstin 2:104bec169fb6 41 // settings icon coordinates
OHstin 2:104bec169fb6 42 int xCoord3 = 100;
OHstin 2:104bec169fb6 43 int yCoord3 = 60;
OHstin 0:5139f11cfc62 44
OHstin 0:5139f11cfc62 45 int main()
OHstin 0:5139f11cfc62 46 {
OHstin 0:5139f11cfc62 47 // Use this initializer if you're using a 1.8" TFT
OHstin 0:5139f11cfc62 48 tft.initR(INITR_BLACKTAB); // initialize a ST7735S chip, black tab
OHstin 0:5139f11cfc62 49
OHstin 2:104bec169fb6 50 uint16_t backgroundColor = ST7735_BLACK;
OHstin 1:1354a7ebd0c6 51 tft.fillScreen(backgroundColor);
OHstin 2:104bec169fb6 52
OHstin 1:1354a7ebd0c6 53 // landscape view
OHstin 0:5139f11cfc62 54 tft.setRotation(1);
OHstin 0:5139f11cfc62 55 char current_text[40];
OHstin 1:1354a7ebd0c6 56
OHstin 1:1354a7ebd0c6 57 int batteryLevel = ain2*32.5;
OHstin 1:1354a7ebd0c6 58 int percentage = ain2*100;
OHstin 2:104bec169fb6 59 bool radiationReceived = false;
OHstin 2:104bec169fb6 60 bool outputStatus = false;
OHstin 2:104bec169fb6 61
OHstin 1:1354a7ebd0c6 62 sprintf(current_text, "W: %ldp H: %ldp ", tft.height(), tft.width());
OHstin 2:104bec169fb6 63 //testdrawtext(current_text, ST7735_WHITE);
OHstin 0:5139f11cfc62 64
OHstin 1:1354a7ebd0c6 65 // determine if the battery is charging
OHstin 2:104bec169fb6 66 // and if solar radiation is received
OHstin 1:1354a7ebd0c6 67 bool batteryCharging;
OHstin 1:1354a7ebd0c6 68 if (ain1 > 0.5) {
OHstin 1:1354a7ebd0c6 69 batteryCharging = true;
OHstin 2:104bec169fb6 70 radiationReceived = true;
OHstin 1:1354a7ebd0c6 71 } else {
OHstin 1:1354a7ebd0c6 72 batteryCharging = false;
OHstin 2:104bec169fb6 73 radiationReceived = false;
OHstin 1:1354a7ebd0c6 74 }
OHstin 2:104bec169fb6 75
OHstin 1:1354a7ebd0c6 76 // create and initialise battery icon project
OHstin 1:1354a7ebd0c6 77 BatteryIcon batteryIcon(startingWidth, startingHeight,backgroundColor,percentage,batteryCharging);
OHstin 1:1354a7ebd0c6 78 // draw the battery icon
OHstin 1:1354a7ebd0c6 79 batteryIcon.drawBatteryIcon();
OHstin 1:1354a7ebd0c6 80
OHstin 2:104bec169fb6 81 // create and initialise solar icon
OHstin 2:104bec169fb6 82 SolarIcon solarIcon(xCoord, yCoord, backgroundColor);
OHstin 2:104bec169fb6 83 // draw solar icon
OHstin 2:104bec169fb6 84 solarIcon.drawSolarIcon();
OHstin 2:104bec169fb6 85
OHstin 2:104bec169fb6 86 // create and initalise output icon
OHstin 2:104bec169fb6 87 OutputIcon outputIcon(xCoord2, yCoord2, backgroundColor);
OHstin 2:104bec169fb6 88 // draw output icon
OHstin 2:104bec169fb6 89 outputIcon.drawOutputIcon();
OHstin 2:104bec169fb6 90
OHstin 2:104bec169fb6 91 // create and initalise output icon
OHstin 2:104bec169fb6 92 SettingsIcon settingsIcon(xCoord3, yCoord3, backgroundColor);
OHstin 2:104bec169fb6 93 // draw settings icon
OHstin 2:104bec169fb6 94 settingsIcon.drawSettingsIcon();
OHstin 2:104bec169fb6 95
OHstin 1:1354a7ebd0c6 96 while (1) {
OHstin 2:104bec169fb6 97
OHstin 1:1354a7ebd0c6 98 // determine if the battery is charging
OHstin 1:1354a7ebd0c6 99 percentage = ain2*100;
OHstin 1:1354a7ebd0c6 100 if (ain1 > 0.5) {
OHstin 2:104bec169fb6 101 radiationReceived = true;
OHstin 1:1354a7ebd0c6 102 batteryCharging = true;
OHstin 1:1354a7ebd0c6 103 } else {
OHstin 1:1354a7ebd0c6 104 batteryCharging = false;
OHstin 2:104bec169fb6 105 radiationReceived = false;
OHstin 0:5139f11cfc62 106 }
OHstin 2:104bec169fb6 107
OHstin 2:104bec169fb6 108 if (ain > 0.5){
OHstin 2:104bec169fb6 109 outputStatus = true;
OHstin 2:104bec169fb6 110 } else {
OHstin 2:104bec169fb6 111 outputStatus = false;
OHstin 2:104bec169fb6 112 }
OHstin 2:104bec169fb6 113
OHstin 1:1354a7ebd0c6 114 // set the battery percentage accordingly
OHstin 1:1354a7ebd0c6 115 batteryIcon.setBatteryPercentage(percentage,batteryCharging);
OHstin 2:104bec169fb6 116
OHstin 2:104bec169fb6 117 // animate the solar icon accordingly
OHstin 2:104bec169fb6 118 solarIcon.animateSolarIcon(radiationReceived);
OHstin 0:5139f11cfc62 119
OHstin 2:104bec169fb6 120 // animate the output icon accordingly
OHstin 2:104bec169fb6 121 outputIcon.animateOutputIcon(outputStatus);
OHstin 2:104bec169fb6 122
OHstin 1:1354a7ebd0c6 123 // wait half a second
OHstin 1:1354a7ebd0c6 124 wait_ms(500);
OHstin 0:5139f11cfc62 125 }
OHstin 1:1354a7ebd0c6 126
OHstin 0:5139f11cfc62 127 }
OHstin 0:5139f11cfc62 128
OHstin 0:5139f11cfc62 129 void testdrawtext(char *text, uint16_t color)
OHstin 0:5139f11cfc62 130 {
OHstin 2:104bec169fb6 131 tft.setCursor(0, 0);
OHstin 0:5139f11cfc62 132 tft.setTextColor(color);
OHstin 0:5139f11cfc62 133 tft.setTextWrap(true);
OHstin 0:5139f11cfc62 134 tft.printf("%s",text);
OHstin 2:104bec169fb6 135 }