Ecran double sur port I2C

Dependencies:   Adafruit_GFX TextLCD

Committer:
diltech
Date:
Sun May 29 19:42:12 2022 -0400
Revision:
2:9c3ea033af88
Parent:
1:a48de1514875
Child:
4:b823c5f2780e
Version compl?te

Who changed what in which revision?

UserRevisionLine numberNew contents of line
diltech 0:9a306207c5b2 1 /* mbed Microcontroller Library
diltech 0:9a306207c5b2 2 * Copyright (c) 2019 ARM Limited
diltech 0:9a306207c5b2 3 * SPDX-License-Identifier: Apache-2.0
diltech 0:9a306207c5b2 4 */
diltech 0:9a306207c5b2 5
diltech 0:9a306207c5b2 6 #include "mbed.h"
diltech 2:9c3ea033af88 7 #include "Adafruit_SSD1306.h"
diltech 2:9c3ea033af88 8 #include "DS18B20.h"
diltech 2:9c3ea033af88 9 #include "TextLCD.h"
diltech 0:9a306207c5b2 10
diltech 2:9c3ea033af88 11 I2C i2c_pin(I2C_SDA, I2C_SCL);
diltech 2:9c3ea033af88 12 Adafruit_SSD1306_I2c oled(i2c_pin, PA_4, 0x78, 64, 128);
diltech 2:9c3ea033af88 13 TextLCD_I2C lcd(&i2c_pin, 0x4E);
diltech 2:9c3ea033af88 14 DS18B20 sensor(PA_5);
diltech 0:9a306207c5b2 15 // Blinking rate in milliseconds
diltech 0:9a306207c5b2 16 #define BLINKING_RATE 500ms
diltech 2:9c3ea033af88 17 int col = 0;
diltech 0:9a306207c5b2 18
diltech 2:9c3ea033af88 19 int main() {
diltech 2:9c3ea033af88 20 // *********** Oled 128 x 64 *********
diltech 2:9c3ea033af88 21 int tickTime = 1000;
diltech 2:9c3ea033af88 22 oled.begin(SSD1306_SWITCHCAPVCC);
diltech 2:9c3ea033af88 23 HAL_Delay(200);
diltech 2:9c3ea033af88 24 oled.splash();
diltech 2:9c3ea033af88 25 oled.display();
diltech 2:9c3ea033af88 26 HAL_Delay(2000);
diltech 2:9c3ea033af88 27 oled.clearDisplay();
diltech 2:9c3ea033af88 28
diltech 2:9c3ea033af88 29 // Initialise the digital pin LED1 as an output
diltech 2:9c3ea033af88 30 DigitalOut led(PC_13);
diltech 2:9c3ea033af88 31 // ******* LCD 1602 *************
diltech 2:9c3ea033af88 32 //lcd.locate(0, 0); // Position initial
diltech 2:9c3ea033af88 33 lcd.setCursor(TextLCD::CurOff_BlkOff);
diltech 2:9c3ea033af88 34 lcd.cls();
diltech 2:9c3ea033af88 35 lcd.setBacklight(TextLCD::LightOn);
diltech 2:9c3ea033af88 36 lcd.printf(" Thermal sonde\n");
diltech 0:9a306207c5b2 37
diltech 2:9c3ea033af88 38 while (true) {
diltech 2:9c3ea033af88 39 oled.clearDisplay();
diltech 2:9c3ea033af88 40 float temperature = sensor.readTemp();
diltech 2:9c3ea033af88 41 led = !led;
diltech 2:9c3ea033af88 42 ThisThread::sleep_for(BLINKING_RATE);
diltech 2:9c3ea033af88 43 // ***** LCD 1602 ***
diltech 2:9c3ea033af88 44 lcd.locate(0, 1);
diltech 2:9c3ea033af88 45 lcd.printf("Temp: %0.1f",temperature);
diltech 2:9c3ea033af88 46
diltech 2:9c3ea033af88 47 for (int g = 6;g>0;g--) {
diltech 2:9c3ea033af88 48
diltech 2:9c3ea033af88 49 lcd.locate(g+9,1);
diltech 2:9c3ea033af88 50 lcd.putc(127);
diltech 2:9c3ea033af88 51 HAL_Delay(200);
diltech 2:9c3ea033af88 52 lcd.putc(' ');
diltech 2:9c3ea033af88 53
diltech 2:9c3ea033af88 54 }
diltech 0:9a306207c5b2 55
diltech 2:9c3ea033af88 56 // ******* Oled 128 x 64 *******
diltech 2:9c3ea033af88 57 oled.setTextSize(2);
diltech 2:9c3ea033af88 58 oled.setTextCursor(0, 30);
diltech 2:9c3ea033af88 59 oled.printf("Temp: %0.1f\r", temperature);
diltech 2:9c3ea033af88 60 oled.display();
diltech 2:9c3ea033af88 61
diltech 2:9c3ea033af88 62 for (int i = 0; i < 10; i++) {
diltech 2:9c3ea033af88 63 oled.setTextSize(2);
diltech 2:9c3ea033af88 64 oled.setTextCursor(col, 0);
diltech 2:9c3ea033af88 65 oled.putc(175);
diltech 2:9c3ea033af88 66 oled.display();
diltech 2:9c3ea033af88 67 col = col + 12;
diltech 2:9c3ea033af88 68 if (col > 118) {
diltech 2:9c3ea033af88 69 col = 0;
diltech 2:9c3ea033af88 70 }
diltech 2:9c3ea033af88 71 HAL_Delay(50);
diltech 0:9a306207c5b2 72 }
diltech 2:9c3ea033af88 73 }
diltech 0:9a306207c5b2 74 }