Programme de test pour l'ecran OLED SSD1306 qui sera utilisé dans le projet

Dependencies:   Test_OLED mbed

Dependents:   Test_OLED

Fork of Test_Ecran_OLED by Plantsigfox

Revision:
0:6962712951df
Child:
1:f4f60a95dd2a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Sep 13 19:40:33 2017 +0000
@@ -0,0 +1,80 @@
+/*
+ *  Copyright (c) 2012 Neal Horman - http://www.wanlink.com
+ *  
+ *  License: MIT open source (http://opensource.org/licenses/MIT)
+ *      Summary;
+ *      Use / modify / distribute / publish it how you want and 
+ *      if you use it, or don't, you can't hold me liable for how
+ *      it does or doesn't work.
+ *      If it doesn't work how you want, don't use it, or change
+ *      it so that it does work.
+ */
+ 
+#include "mbed.h"
+#include "Adafruit_SSD1306.h"
+ 
+// Définition des pattes SPI
+#define MOSI        D0
+#define MISO        NC
+#define CLK         D1 
+#define DC          D2  
+#define CS          D4
+#define RST_SPI     A0
+
+// Définition des pattes i2c
+#define SDA         D5
+#define SCL         D6
+#define RST_I2C     A1
+
+// Déclaration des E/S
+DigitalOut myled(LED1);
+ 
+// sub-class SPI : 
+// Caractéristiques par défaut de la communication SPI avec le SSD1306
+class SPIPreInit : public SPI
+{
+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)
+    };
+};
+ 
+// sub-class I2C : 
+// Caractéristiques par défaut de la communication I2C avec le SSD1306
+class I2CPreInit : public I2C
+{
+public:
+    I2CPreInit(PinName sda, PinName scl) : I2C(sda, scl)
+    {
+        frequency(400000);// Fréquence d'utilisation(en Hz)
+        start(); //Condition de start
+    };
+};
+
+// Initialisation de l'écran en mode SPI
+SPIPreInit gSpi(MOSI,MISO,CLK);
+Adafruit_SSD1306_Spi gOled1(gSpi,DC,RST_SPI,CS);
+ 
+// Initialisation de l'écran en mode I2C
+I2CPreInit gI2C(SDA,SCL);
+Adafruit_SSD1306_I2c gOled2(gI2C,RST_I2C);
+ 
+int main()
+{   uint16_t x=0;
+ 
+    gOled1.printf("%ux%u OLED Display\r\n", gOled1.width(), gOled1.height());
+    gOled2.printf("%ux%u OLED Display\r\n", gOled2.width(), gOled2.height());
+    
+    while(1)
+    {
+        myled = !myled;
+        gOled1.printf("%u\r",x);
+        gOled1.display();
+        gOled2.printf("%u\r",x);
+        gOled2.display();
+        x++;
+        wait(1.0);
+    }
+}
\ No newline at end of file