Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include <SPI.h>
- #include <Adafruit_GFX.h> //Libraries for the OLED and BMP280
- #include <Adafruit_SSD1306.h>
- #include <Adafruit_Sensor.h>
- #include <Adafruit_BMP280.h>
- #include <DS1307RTC.h>
- #define SCREEN_WIDTH 128 // OLED display width, in pixels
- #define SCREEN_HEIGHT 32 // OLED display height, in pixels
- #define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
- #define BMP280_ADRESA (0x76) // nastavení adresy senzoru
- Adafruit_BMP280 bmp; // inicializace senzoru BMP z knihovny
- bool a, points;
- int x = 0;
- Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
- tmElements_t tm;
- // inicializace proměnné pro určení adresy senzoru
- // 0x68 nebo 0x69, dle připojení AD0
- const int MPU_addr = 0x68;
- // inicializace proměnných, do kterých se uloží data
- int16_t AcX, AcY, AcZ, Tmp, GyX, GyY, GyZ;
- const int button0 = A0; //konstanty co se nemeni pro tlacitka
- const int button1 = A1;
- const int button2 = A2;
- const int led1 = 2; //konstanty co se nemeni pro led
- const int led2 = 3;
- const int led3 = 4;
- void setup() {
- pinMode(button0, INPUT_PULLUP); // nastaví pin kde je tlačítko jako vstup
- pinMode(button1, INPUT_PULLUP);
- pinMode(button2, INPUT_PULLUP);
- pinMode(led1, OUTPUT);
- pinMode(led2, OUTPUT); // nastaví vystup u Led2 na výstup
- pinMode(led3, OUTPUT); // nastaví vystup u Led3 na výstup
- digitalWrite(button0, HIGH); // zapnutí pullup rezistoru,
- digitalWrite(button1, HIGH); // zapnutí pullup rezistoru,
- digitalWrite(button2, HIGH); // zapnutí pullup rezistoru,
- Serial.begin(115200); // komunikace po sériové lince rychlostí 115200 baud
- bmp.begin(); //Start the bmp
- display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //Start the OLED display
- display.clearDisplay();
- display.display();
- }
- void loop(bmp) {
- if ((digitalRead(button0)) == LOW) {
- digitalWrite(led1, HIGH);
- display.clearDisplay();
- float T = bmp.readTemperature();
- //Read temperature in C
- float P = bmp.readPressure() / 100;
- //Read Pressure in Pa and conversion to hPa
- float A = bmp.readAltitude(1019.66);
- display.setCursor(0, 0);
- display.setTextColor(WHITE);
- display.setTextSize(2);
- display.print("Temp");
- display.setCursor(0, 18);
- display.print(T, 1);
- display.setCursor(50, 17);
- display.setTextSize(2);
- display.print("C");
- display.setTextSize(1);
- display.setCursor(65, 0);
- display.print("tlak");
- display.setCursor(65, 10);
- display.print(P);
- display.setCursor(110, 10);
- display.print("hPa");
- display.setCursor(65, 25);
- display.print("Mnm");
- display.setCursor(90, 25);
- display.print(A, 0);
- display.setCursor(110, 25);
- display.print("m");
- display.display();
- // výpis všech dostupných informací ze senzoru BMP
- // výpis teploty
- Serial.print("Teplota: ");
- Serial.print(bmp.readTemperature());
- Serial.println(" stupnu Celsia.");
- // výpis tlaku s přepočtem na hektoPascaly
- Serial.print("Tlak: ");
- Serial.print(bmp.readPressure() / 100.0F);
- Serial.println(" hPa.");
- // vytištění prázdného řádku a pauza po dobu 2 vteřin
- Serial.println();
- delay(100);
- } else {
- //while (1);
- digitalWrite(led1, LOW);
- }
- if ((digitalRead(button1)) == LOW) {
- digitalWrite(led2, HIGH);
- display.clearDisplay();
- RTC.read(tm);
- x = tm.Second % 2; //Dividing the seconds value by 2 and store the rest value, it's either 0 or 1
- display.setTextSize(3);
- display.setTextColor(WHITE);
- display.setCursor(0, 10);
- ampm(tm.Hour);
- if (x == 0) //if x=0 we don't display the ":"
- display.print(" ");
- if (x == 1) //if x=1 we display it, so for every 1s we display or not the ":"
- display.print(":");
- display.print(tm.Minute);
- display.setTextSize(1);
- display.setCursor(50, 0);
- if (a == true)
- display.print(" am");
- if (a == false)
- display.print(" pm");
- display.setCursor(90, 5);
- display.setTextSize(2);
- display.print(tm.Month);
- display.print('/');
- display.print(tm.Day);
- display.setCursor(95, 23);
- display.setTextSize(1);
- display.print(tmYearToCalendar(tm.Year));
- display.display();
- display.clearDisplay();
- } else {
- digitalWrite(led2, LOW);
- }
- if ((digitalRead(button2)) == LOW) {
- digitalWrite(led3, HIGH);
- // zapnutí přenosu
- Wire.beginTransmission(MPU_addr);
- // zápis do registru ACCEL_XOUT_H
- Wire.write(0x3B);
- Wire.endTransmission(false);
- // vyzvednutí dat z 14 registrů
- Wire.requestFrom(MPU_addr, 14, true);
- AcX = Wire.read() << 8 | Wire.read();
- AcY = Wire.read() << 8 | Wire.read();
- AcZ = Wire.read() << 8 | Wire.read();
- Tmp = Wire.read() << 8 | Wire.read();
- GyX = Wire.read() << 8 | Wire.read();
- GyY = Wire.read() << 8 | Wire.read();
- GyZ = Wire.read() << 8 | Wire.read();
- // výpis surových dat z proměnných na sériovou linku
- Serial.print("AcX = "); Serial.print(AcX);
- Serial.print(" | AcY = "); Serial.print(AcY);
- Serial.print(" | AcZ = "); Serial.print(AcZ);
- // přepočtení teploty dle datasheetu
- Serial.print(" | Temp = "); Serial.print(Tmp / 340.00 + 36.53);
- Serial.print(" | GyX = "); Serial.print(GyX);
- Serial.print(" | GyY = "); Serial.print(GyY);
- Serial.print(" | GyZ = "); Serial.println(GyZ);
- delay(100);
- } else {
- digitalWrite(led3, LOW);
- }
- } // konec tretiho tlacitka
- void ampm(int Hour){ //ampm function takes the hour value 0-23
- if(Hour==0){ //if it's 0 it becomes 12
- Hour=12;
- a=true; //true if it's am, false otherwise
- display.print(Hour);
- }
- else if(Hour>0 && Hour<12){
- a=true; //normal value
- display.print(Hour);
- }
- else if(Hour==12){
- a=false; //changing to pm
- display.print(Hour);
- }
- else if(Hour>12){
- Hour=Hour-12; //substract 12 to bring it back to 1,2,3,...
- a=false;
- display.print(Hour);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment