initial file
This commit is contained in:
parent
d3dcd7648c
commit
ee916c8ff7
1 changed files with 72 additions and 0 deletions
72
main/main.ino
Normal file
72
main/main.ino
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
// for sensor
|
||||
#include <OneWire.h>
|
||||
#include <DallasTemperature.h>
|
||||
#define ONE_WIRE_BUS 4
|
||||
// Setup a oneWire instance to communicate with any OneWire devices
|
||||
OneWire oneWire(ONE_WIRE_BUS);
|
||||
|
||||
// Pass our oneWire reference to Dallas Temperature sensor
|
||||
DallasTemperature sensors(&oneWire);
|
||||
|
||||
// for the display
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_SSD1306.h>
|
||||
|
||||
#define SCREEN_WIDTH 128 // OLED display width, in pixels
|
||||
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
|
||||
|
||||
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
|
||||
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
|
||||
|
||||
// Other global variables
|
||||
bool fillCircle = false;
|
||||
|
||||
// Draw a small circle, change between emtpy and full to indicate that there is an update on the display and not stock
|
||||
void drawCircle() {
|
||||
if(fillCircle){
|
||||
display.fillCircle(5, 5, 5, WHITE);
|
||||
fillCircle = !fillCircle;
|
||||
} else {
|
||||
display.drawCircle(5, 5, 5, WHITE);
|
||||
fillCircle = !fillCircle;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// small function to write text on the display with option for changing font
|
||||
void textToDisplay(char* text = "default", int fontSize = 1) {
|
||||
display.clearDisplay();
|
||||
drawCircle();
|
||||
display.setTextSize(fontSize);
|
||||
display.setTextColor(WHITE);
|
||||
display.setCursor(20, 0);
|
||||
// Display static text
|
||||
display.println(text);
|
||||
display.display();
|
||||
}
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
|
||||
Serial.println(F("SSD1306 allocation failed"));
|
||||
for(;;);
|
||||
}
|
||||
// Start up the library
|
||||
sensors.begin();
|
||||
textToDisplay("Finished setup...");
|
||||
delay(1000);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
|
||||
sensors.requestTemperatures();
|
||||
float temp = sensors.getTempCByIndex(0);
|
||||
String message = String(temp) + " C"; // Convert float to String, then concatenate
|
||||
textToDisplay(message.c_str(),2);
|
||||
Serial.println(message.c_str());
|
||||
delay(1000);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue