blink stm32 cubemx
This commit is contained in:
57
ESP32/OLED_ESP32/src/main.cpp
Normal file
57
ESP32/OLED_ESP32/src/main.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
#include <Arduino.h>
|
||||
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_SSD1306.h>
|
||||
#include "Adafruit_MCP9808.h"
|
||||
|
||||
|
||||
|
||||
#define SCREEN_WIDTH 128 // OLED display width, in pixels
|
||||
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
|
||||
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
|
||||
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
|
||||
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
|
||||
|
||||
// Create the MCP9808 temperature sensor object
|
||||
Adafruit_MCP9808 tempsensor = Adafruit_MCP9808();
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
|
||||
display.clearDisplay();
|
||||
if (!tempsensor.begin(0x18)) {
|
||||
Serial.println("Couldn't find MCP9808! Checloop_time your connections and verify the address is correct.");
|
||||
|
||||
}
|
||||
tempsensor.setResolution(3);
|
||||
|
||||
}
|
||||
int contador =0;
|
||||
unsigned long loop_time = 0;
|
||||
void loop()
|
||||
{
|
||||
if ((millis() - loop_time) >= 200){
|
||||
|
||||
display.clearDisplay();
|
||||
display.setTextSize(1);
|
||||
display.setTextColor(WHITE);
|
||||
display.setCursor(0,0);
|
||||
display.print("Contador: ");
|
||||
display.println(contador++);
|
||||
display.setTextSize(1);
|
||||
display.println("UNELECTRONICA ESP32");
|
||||
display.setTextSize(2);
|
||||
display.print("T: ");
|
||||
//tempsensor.waloop_timee();
|
||||
float f = tempsensor.readTempC();
|
||||
//tempsensor.shutdown_waloop_timee(1);
|
||||
display.println(f);
|
||||
display.display();
|
||||
loop_time = millis();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user