Diltech RM Consultant
/
Double_I2C_Sample
Sample code with BluePill STM32F103C8 and Oled SSD1306 and LCD1602 on same connect on DS18B20.
main.cpp@1:27d0c6ee0e55, 23 months ago (annotated)
- Committer:
- diltech
- Date:
- Sun May 29 18:40:06 2022 -0400
- Revision:
- 1:27d0c6ee0e55
- Parent:
- 0:47b4bbc994df
Etape1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
diltech | 0:47b4bbc994df | 1 | #include "PinNames.h" |
diltech | 0:47b4bbc994df | 2 | #include "mbed.h" |
diltech | 0:47b4bbc994df | 3 | #include "TextLCD.h" // Important d'avoir la bonne librairie |
diltech | 0:47b4bbc994df | 4 | #include "DS18B20.h" |
diltech | 0:47b4bbc994df | 5 | |
diltech | 0:47b4bbc994df | 6 | I2C i2c_pin(I2C_SDA, I2C_SCL); |
diltech | 0:47b4bbc994df | 7 | DigitalOut myLed(PC_13); |
diltech | 0:47b4bbc994df | 8 | TextLCD_I2C lcd(&i2c_pin, 0x4E); |
diltech | 1:27d0c6ee0e55 | 9 | |
diltech | 0:47b4bbc994df | 10 | |
diltech | 0:47b4bbc994df | 11 | |
diltech | 0:47b4bbc994df | 12 | |
diltech | 0:47b4bbc994df | 13 | DS18B20 sensor(PA_5); |
diltech | 0:47b4bbc994df | 14 | int col = 0; |
diltech | 0:47b4bbc994df | 15 | |
diltech | 0:47b4bbc994df | 16 | |
diltech | 0:47b4bbc994df | 17 | // main() runs in its own thread in the OS |
diltech | 0:47b4bbc994df | 18 | int main() |
diltech | 0:47b4bbc994df | 19 | { |
diltech | 0:47b4bbc994df | 20 | // *********** Oled 128 x 64 ********* |
diltech | 1:27d0c6ee0e55 | 21 | |
diltech | 0:47b4bbc994df | 22 | |
diltech | 0:47b4bbc994df | 23 | // ******* LCD 1602 ************* |
diltech | 0:47b4bbc994df | 24 | //lcd.locate(0, 0); // Position initial |
diltech | 0:47b4bbc994df | 25 | lcd.setCursor(TextLCD::CurOff_BlkOff); |
diltech | 0:47b4bbc994df | 26 | lcd.cls(); |
diltech | 0:47b4bbc994df | 27 | lcd.setBacklight(TextLCD::LightOn); |
diltech | 0:47b4bbc994df | 28 | lcd.printf(" Thermal sonde\n"); |
diltech | 0:47b4bbc994df | 29 | |
diltech | 0:47b4bbc994df | 30 | while (true) { |
diltech | 1:27d0c6ee0e55 | 31 | |
diltech | 0:47b4bbc994df | 32 | myLed = !myLed; |
diltech | 0:47b4bbc994df | 33 | float temperature = sensor.readTemp(); |
diltech | 0:47b4bbc994df | 34 | // ***** LCD 1602 *** |
diltech | 0:47b4bbc994df | 35 | lcd.locate(0, 1); |
diltech | 0:47b4bbc994df | 36 | lcd.printf("Temp: %0.1f",temperature); |
diltech | 0:47b4bbc994df | 37 | |
diltech | 0:47b4bbc994df | 38 | for (int g = 6;g>0;g--) { |
diltech | 0:47b4bbc994df | 39 | |
diltech | 0:47b4bbc994df | 40 | lcd.locate(g+9,1); |
diltech | 0:47b4bbc994df | 41 | lcd.putc(127); |
diltech | 0:47b4bbc994df | 42 | HAL_Delay(200); |
diltech | 0:47b4bbc994df | 43 | lcd.putc(' '); |
diltech | 0:47b4bbc994df | 44 | |
diltech | 0:47b4bbc994df | 45 | } |
diltech | 0:47b4bbc994df | 46 | |
diltech | 0:47b4bbc994df | 47 | // ******* Oled 128 x 64 ******* |
diltech | 1:27d0c6ee0e55 | 48 | |
diltech | 0:47b4bbc994df | 49 | |
diltech | 1:27d0c6ee0e55 | 50 | |
diltech | 0:47b4bbc994df | 51 | HAL_Delay(50); |
diltech | 1:27d0c6ee0e55 | 52 | |
diltech | 0:47b4bbc994df | 53 | } |
diltech | 0:47b4bbc994df | 54 | } |