Ecran double sur port I2C
Dependencies: Adafruit_GFX TextLCD
main.cpp@4:b823c5f2780e, 23 months ago (annotated)
- Committer:
- diltech
- Date:
- Mon May 30 00:27:58 2022 -0400
- Branch:
- develop
- Revision:
- 4:b823c5f2780e
- Parent:
- 2:9c3ea033af88
revision
Who changed what in which revision?
User | Revision | Line number | New 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 | 4:b823c5f2780e | 20 | |
diltech | 2:9c3ea033af88 | 21 | // *********** Oled 128 x 64 ********* |
diltech | 2:9c3ea033af88 | 22 | int tickTime = 1000; |
diltech | 2:9c3ea033af88 | 23 | oled.begin(SSD1306_SWITCHCAPVCC); |
diltech | 2:9c3ea033af88 | 24 | HAL_Delay(200); |
diltech | 2:9c3ea033af88 | 25 | oled.splash(); |
diltech | 2:9c3ea033af88 | 26 | oled.display(); |
diltech | 2:9c3ea033af88 | 27 | HAL_Delay(2000); |
diltech | 2:9c3ea033af88 | 28 | oled.clearDisplay(); |
diltech | 2:9c3ea033af88 | 29 | |
diltech | 2:9c3ea033af88 | 30 | // Initialise the digital pin LED1 as an output |
diltech | 2:9c3ea033af88 | 31 | DigitalOut led(PC_13); |
diltech | 2:9c3ea033af88 | 32 | // ******* LCD 1602 ************* |
diltech | 2:9c3ea033af88 | 33 | //lcd.locate(0, 0); // Position initial |
diltech | 2:9c3ea033af88 | 34 | lcd.setCursor(TextLCD::CurOff_BlkOff); |
diltech | 2:9c3ea033af88 | 35 | lcd.cls(); |
diltech | 2:9c3ea033af88 | 36 | lcd.setBacklight(TextLCD::LightOn); |
diltech | 4:b823c5f2780e | 37 | lcd.printf(" Sonde thermale\n"); |
diltech | 0:9a306207c5b2 | 38 | |
diltech | 2:9c3ea033af88 | 39 | while (true) { |
diltech | 2:9c3ea033af88 | 40 | oled.clearDisplay(); |
diltech | 2:9c3ea033af88 | 41 | float temperature = sensor.readTemp(); |
diltech | 2:9c3ea033af88 | 42 | led = !led; |
diltech | 2:9c3ea033af88 | 43 | ThisThread::sleep_for(BLINKING_RATE); |
diltech | 2:9c3ea033af88 | 44 | // ***** LCD 1602 *** |
diltech | 2:9c3ea033af88 | 45 | lcd.locate(0, 1); |
diltech | 2:9c3ea033af88 | 46 | lcd.printf("Temp: %0.1f",temperature); |
diltech | 2:9c3ea033af88 | 47 | |
diltech | 2:9c3ea033af88 | 48 | for (int g = 6;g>0;g--) { |
diltech | 2:9c3ea033af88 | 49 | |
diltech | 2:9c3ea033af88 | 50 | lcd.locate(g+9,1); |
diltech | 2:9c3ea033af88 | 51 | lcd.putc(127); |
diltech | 2:9c3ea033af88 | 52 | HAL_Delay(200); |
diltech | 2:9c3ea033af88 | 53 | lcd.putc(' '); |
diltech | 2:9c3ea033af88 | 54 | |
diltech | 2:9c3ea033af88 | 55 | } |
diltech | 0:9a306207c5b2 | 56 | |
diltech | 2:9c3ea033af88 | 57 | // ******* Oled 128 x 64 ******* |
diltech | 2:9c3ea033af88 | 58 | oled.setTextSize(2); |
diltech | 2:9c3ea033af88 | 59 | oled.setTextCursor(0, 30); |
diltech | 2:9c3ea033af88 | 60 | oled.printf("Temp: %0.1f\r", temperature); |
diltech | 2:9c3ea033af88 | 61 | oled.display(); |
diltech | 2:9c3ea033af88 | 62 | |
diltech | 2:9c3ea033af88 | 63 | for (int i = 0; i < 10; i++) { |
diltech | 2:9c3ea033af88 | 64 | oled.setTextSize(2); |
diltech | 2:9c3ea033af88 | 65 | oled.setTextCursor(col, 0); |
diltech | 2:9c3ea033af88 | 66 | oled.putc(175); |
diltech | 2:9c3ea033af88 | 67 | oled.display(); |
diltech | 2:9c3ea033af88 | 68 | col = col + 12; |
diltech | 2:9c3ea033af88 | 69 | if (col > 118) { |
diltech | 2:9c3ea033af88 | 70 | col = 0; |
diltech | 2:9c3ea033af88 | 71 | } |
diltech | 2:9c3ea033af88 | 72 | HAL_Delay(50); |
diltech | 0:9a306207c5b2 | 73 | } |
diltech | 2:9c3ea033af88 | 74 | } |
diltech | 0:9a306207c5b2 | 75 | } |