Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Adafruit_GFX Adafruit_ST7735 INA219 MODSERIAL MbedJSONValue mbed-rtos mbed
Diff: main.cpp
- Revision:
- 2:104bec169fb6
- Parent:
- 1:1354a7ebd0c6
- Child:
- 3:7666de697752
--- a/main.cpp Sun Jul 10 12:24:41 2016 +0000
+++ b/main.cpp Mon Jul 18 04:31:21 2016 +0000
@@ -3,6 +3,9 @@
Adafruit_ST7735 tft(p11, p12, p13, p10, p8, p9); // MOSI, MISO, SCLK, SSEL, TFT_DC, TFT_RST
#include "BatteryIcon.h"
+#include "SolarIcon.h"
+#include "OutputIcon.h"
+#include "SettingsIcon.h"
//LEDs used to display output
@@ -21,68 +24,102 @@
DigitalOut myled(LED1);
+void testdrawtext(char *text, uint16_t color);
+// battery icon coordinates
+int startingWidth = 15;
+int startingHeight = 7;
-void testdrawtext(char *text, uint16_t color);
-void testdrawrects(uint16_t color);
-void testfastlines(uint16_t color, int batteryLevel);
-void testDrawPercentage(char *percentage, uint16_t color);
-void displayBatteryPercentage(int percentage, uint16_t color);
-void testDrawThunderbolt();
-uint16_t determineColor(int batteryLevel);
+// solar icon coordinates
+int xCoord = 10;
+int yCoord = 65;
-float currentFloat = 1.0;
-int currentBatteryLevel = 0;
-int previousBatteryLevel = 0;
-int previousBatteryColor = 0;
+// output icon coordinates
+int xCoord2 = 100;
+int yCoord2 = 10;
-int startingWidth = 20;
-int startingHeight = 10;
-
+// settings icon coordinates
+int xCoord3 = 100;
+int yCoord3 = 60;
int main()
{
// Use this initializer if you're using a 1.8" TFT
tft.initR(INITR_BLACKTAB); // initialize a ST7735S chip, black tab
- uint16_t backgroundColor = ST7735_WHITE;
+ uint16_t backgroundColor = ST7735_BLACK;
tft.fillScreen(backgroundColor);
-
+
// landscape view
tft.setRotation(1);
char current_text[40];
int batteryLevel = ain2*32.5;
int percentage = ain2*100;
-
+ bool radiationReceived = false;
+ bool outputStatus = false;
+
sprintf(current_text, "W: %ldp H: %ldp ", tft.height(), tft.width());
- testdrawtext(current_text, ST7735_WHITE);
+ //testdrawtext(current_text, ST7735_WHITE);
// determine if the battery is charging
+ // and if solar radiation is received
bool batteryCharging;
if (ain1 > 0.5) {
batteryCharging = true;
+ radiationReceived = true;
} else {
batteryCharging = false;
+ radiationReceived = false;
}
-
+
// create and initialise battery icon project
BatteryIcon batteryIcon(startingWidth, startingHeight,backgroundColor,percentage,batteryCharging);
// draw the battery icon
batteryIcon.drawBatteryIcon();
+ // create and initialise solar icon
+ SolarIcon solarIcon(xCoord, yCoord, backgroundColor);
+ // draw solar icon
+ solarIcon.drawSolarIcon();
+
+ // create and initalise output icon
+ OutputIcon outputIcon(xCoord2, yCoord2, backgroundColor);
+ // draw output icon
+ outputIcon.drawOutputIcon();
+
+ // create and initalise output icon
+ SettingsIcon settingsIcon(xCoord3, yCoord3, backgroundColor);
+ // draw settings icon
+ settingsIcon.drawSettingsIcon();
+
while (1) {
-
+
// determine if the battery is charging
percentage = ain2*100;
if (ain1 > 0.5) {
+ radiationReceived = true;
batteryCharging = true;
} else {
batteryCharging = false;
+ radiationReceived = false;
}
+
+ if (ain > 0.5){
+ outputStatus = true;
+ } else {
+ outputStatus = false;
+ }
+
// set the battery percentage accordingly
batteryIcon.setBatteryPercentage(percentage,batteryCharging);
+
+ // animate the solar icon accordingly
+ solarIcon.animateSolarIcon(radiationReceived);
+ // animate the output icon accordingly
+ outputIcon.animateOutputIcon(outputStatus);
+
// wait half a second
wait_ms(500);
}
@@ -91,8 +128,8 @@
void testdrawtext(char *text, uint16_t color)
{
- tft.setCursor(0, 100);
+ tft.setCursor(0, 0);
tft.setTextColor(color);
tft.setTextWrap(true);
tft.printf("%s",text);
-}
+}
\ No newline at end of file