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
main.cpp
- Committer:
- OHstin
- Date:
- 2016-07-10
- Revision:
- 1:1354a7ebd0c6
- Parent:
- 0:5139f11cfc62
- Child:
- 2:104bec169fb6
File content as of revision 1:1354a7ebd0c6:
#include "mbed.h"
#include "Adafruit_ST7735.h"
Adafruit_ST7735 tft(p11, p12, p13, p10, p8, p9); // MOSI, MISO, SCLK, SSEL, TFT_DC, TFT_RST
#include "BatteryIcon.h"
//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);
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);
float currentFloat = 1.0;
int currentBatteryLevel = 0;
int previousBatteryLevel = 0;
int previousBatteryColor = 0;
int startingWidth = 20;
int startingHeight = 10;
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;
tft.fillScreen(backgroundColor);
// landscape view
tft.setRotation(1);
char current_text[40];
int batteryLevel = ain2*32.5;
int percentage = ain2*100;
sprintf(current_text, "W: %ldp H: %ldp ", tft.height(), tft.width());
testdrawtext(current_text, ST7735_WHITE);
// determine if the battery is charging
bool batteryCharging;
if (ain1 > 0.5) {
batteryCharging = true;
} else {
batteryCharging = false;
}
// create and initialise battery icon project
BatteryIcon batteryIcon(startingWidth, startingHeight,backgroundColor,percentage,batteryCharging);
// draw the battery icon
batteryIcon.drawBatteryIcon();
while (1) {
// determine if the battery is charging
percentage = ain2*100;
if (ain1 > 0.5) {
batteryCharging = true;
} else {
batteryCharging = false;
}
// set the battery percentage accordingly
batteryIcon.setBatteryPercentage(percentage,batteryCharging);
// wait half a second
wait_ms(500);
}
}
void testdrawtext(char *text, uint16_t color)
{
tft.setCursor(0, 100);
tft.setTextColor(color);
tft.setTextWrap(true);
tft.printf("%s",text);
}