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.
Fork of Test_Ecran_OLED by
Revision 2:a147a943a716, committed 2017-09-18
- Comitter:
- Tbroussard
- Date:
- Mon Sep 18 11:59:20 2017 +0000
- Parent:
- 1:f4f60a95dd2a
- Commit message:
- Programme de test avec fonction "icone batterie"
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sun Sep 17 07:24:44 2017 +0000 +++ b/main.cpp Mon Sep 18 11:59:20 2017 +0000 @@ -28,6 +28,11 @@ // Déclaration des E/S DigitalOut myled(LED1); + + +// Fonctions locales +void Battery_Charge_SPI(int x, int y, int Niveau); + // sub-class SPI : // Caractéristiques par défaut de la communication SPI avec le SSD1306 class SPIPreInit : public SPI @@ -35,11 +40,12 @@ public: SPIPreInit(PinName mosi, PinName miso, PinName clk) : SPI(mosi,miso,clk) { - format(8,3); // définition du format (nombre de colonnes,nombre de ligne) - frequency(2000000);// Fréquence d'utilisation (en Hz) + format(8,3); + frequency(2000000); }; }; + // sub-class I2C : // Caractéristiques par défaut de la communication I2C avec le SSD1306 class I2CPreInit : public I2C @@ -61,7 +67,7 @@ //Adafruit_SSD1306_I2c gOled2(gI2C,RST_I2C); int main() -{ uint16_t x=0,y=0; +{ uint16_t x=100,y=0; //gOled1.printf("%ux%u Thomas \r\n", gOled1.width(), gOled1.height()); //gOled2.printf("%ux%u OLED Display\r\n", gOled2.width(), gOled2.height()); @@ -83,31 +89,59 @@ gOled1.drawFastHLine(0, 20, 128, WHITE); gOled1.drawFastHLine(0, 22, 128, WHITE); - //Affichage temperature + //Affichage X gOled1.setTextCursor(0,30); - gOled1.printf("Temp : %d",x); + gOled1.printf("X = %d",x); gOled1.setTextCursor(80,30); - gOled1.printf("\tC"); + //gOled1.printf("\tC"); - // Affichage humidité + // Affichage Y gOled1.setTextCursor(0,40); - gOled1.printf("Moist : %d",y); + gOled1.printf("Y = %d",y); gOled1.setTextCursor(80,40); - gOled1.printf("\t/\t"); + //gOled1.printf("\t/\t"); + + // Affichage batterie : + Battery_Charge_SPI(110, 45, x); + gOled1.display(); - x+=1; + x-=1; y+=2; if (y > 100) { y = 0; } - if (x > 100) + if (x <= 0) { - x = 0; + x = 100; } - wait(0.2); } -} \ No newline at end of file +} + +void Battery_Charge_SPI(int x, int y, int Niveau) +{ + int color_1 = BLACK , color_2 = BLACK , color_3 = BLACK , color_4 = BLACK; + + // 1 - tracé de la batterie + gOled1.drawRect(x,2 + y ,9,15,WHITE); + gOled1.drawRect(1 + x ,y ,7,3,WHITE); + + // 2 - Nombre de barres + if (Niveau > 75) + color_1 = WHITE; + if (Niveau > 50) + color_2 = WHITE; + if (Niveau > 25) + color_3 = WHITE; + if (Niveau > 0) + color_4 = WHITE; + + // 3 Affichage barres + gOled1.fillRect(2 + x ,4 + y ,5,2,color_1); + gOled1.fillRect(2 + x ,7 + y ,5,2,color_2); + gOled1.fillRect(2 + x ,10 + y ,5,2,color_3); + gOled1.fillRect(2 + x ,13 + y ,5,2,color_4); +} \ No newline at end of file