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>
- #include <TimeLib.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)
- Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
- #define BMP280_ADRESA (0x76) // nastavení adresy senzoru
- Adafruit_BMP280 bmp; // inicializace senzoru BME z knihovny
- const int MPU_addr = 0x68; // inicializace proměnné pro určení adresy senzoru
- int16_t AcX, AcY, AcZ, Tmp, GyX, GyY, GyZ; // inicializace proměnných, do kterých se uloží data
- const int button1 = A0;
- const int button2 = A1;
- const int button3 = A2;
- const int button4 = A3;
- const int led1 = 2;
- const int led2 = 3;
- const int led3 = 4;
- const int led4 = 13;
- const int led5 = 5;
- int x = 0;
- void setup() {
- pinMode(button1, INPUT_PULLUP); // nastaví pin kde je tlačítko jako vstup
- pinMode(button2, INPUT_PULLUP);
- pinMode(button3, INPUT_PULLUP);
- pinMode(button4, INPUT_PULLUP);
- pinMode(led1, OUTPUT); // nastaví vystup u Led1 na výstup
- pinMode(led2, OUTPUT); // nastaví vystup u Led2 na výstup
- pinMode(led3, OUTPUT); // nastaví vystup u Led3 na výstup
- pinMode(led4, OUTPUT); // nastaví vystup u Led3 na výstup
- pinMode(led5, OUTPUT); // nastaví vystup u Led3 na výstup
- Serial.begin(9600); // komunikace po sériové lince rychlostí 115200 baud
- display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //Start the OLED,adress 0x3C 128x32
- Wire.begin();
- display.clearDisplay();
- display.setTextColor(WHITE);
- display.setTextSize(1);
- display.print("Kenny-Tech"); //Show the name, you can remove it or replace it
- display.setCursor(32, 12);
- display.setTextSize(2);
- display.println("NATEPNIK");
- display.display();
- delay(2000);
- }
- uint8_t button = 0;
- void loop()
- {
- // tady si vyctes stavy tlacitek a nastavis promennou
- if (digitalRead(button1) == false)
- button = 1;
- else if (digitalRead(button2) == false)
- button = 2;
- else if (digitalRead(button3) == false)
- button = 3;
- else if (digitalRead(button4) == false)
- button = 4;
- //else // poku chces aby se neustale provadela cast kterou jsi navolil tlacitkem, tak vynech tenhle else
- // button = 0;
- switch (button)
- {
- case 1:
- { // provede se ukol pro prvni tlacitko
- digitalWrite(led1, HIGH);
- digitalWrite(led2, LOW);
- digitalWrite(led3, LOW);
- digitalWrite(led4, LOW);
- digitalWrite(led5, LOW);
- tmElements_t tm;
- display.clearDisplay();
- RTC.read(tm);
- display.setTextSize(2);
- display.setTextColor(WHITE);
- display.setCursor(0, 0);
- display.print(tm.Hour);
- display.print(":");
- display.print(tm.Minute);
- display.print(":");
- display.print(tm.Second);
- display.setCursor(0,17);
- display.setTextSize(2);
- display.print(tm.Day);
- display.print(':');
- display.print(tm.Month);
- display.print(':');
- display.print(tmYearToCalendar(tm.Year));
- display.display();
- digitalWrite(led1, LOW);
- delay(1000);
- break;
- }
- case 2:
- { // provede se ukol pro druhe tlacitko
- digitalWrite(led1, LOW);
- digitalWrite(led2, HIGH);
- digitalWrite(led3, LOW);
- digitalWrite(led4, LOW);
- digitalWrite(led5, LOW);
- bmp.begin(0x76); //Start the bmp
- 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.25); //Calthe Altitude, the "1019.66" in (hPa)level at day in your region
- display.setCursor(0,0); //Oled display,
- display.setTextColor(WHITE);
- display.setTextSize(2);
- display.print("Temp");
- display.setCursor(0,18);
- display.print(T,1);
- display.setCursor(50,17);
- display.setTextSize(1);
- 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("Alt");
- display.setCursor(90,25);
- display.print(A,0);
- display.setCursor(110,25);
- display.print("m");
- display.display();
- //digitalWrite(led2, LOW);
- delay (200);
- break;
- }
- case 3:
- {
- // provede se ukol pro teti tlacitko
- digitalWrite(led1, LOW);
- digitalWrite(led2, LOW);
- digitalWrite(led3, HIGH);
- digitalWrite(led4, LOW);
- digitalWrite(led5, LOW);
- display.clearDisplay();
- const int MPU_addr = 0x68; // inicializace proměnné pro určení adresy senzoru
- int16_t AcX, AcY, AcZ, Tmp, GyX, GyY, GyZ; // inicializace proměnných, do kterých se uloží data
- Wire.beginTransmission(MPU_addr); // zapnutí přenosu
- Wire.write(0x3B); // zápis do registru ACCEL_XOUT_H
- Wire.endTransmission(false);
- Wire.requestFrom(MPU_addr, 14, true); // vyzvednutí dat z 14 registrů
- 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();
- display.setCursor(0, 0); //Oled display, just playing with text size and cursor to get the display you want
- display.setTextColor(WHITE);
- display.setTextSize(1);
- display.print(AcX);
- display.print(":");
- display.print(AcY);
- display.print(":");
- display.print(AcZ);
- display.print(":");
- display.setTextSize(1);
- display.setCursor(0, 18);
- display.print(Tmp);
- display.print(":");
- display.print(GyX);
- display.print(":");
- display.print(GyY);
- display.print(":");
- display.print(GyZ);
- display.print(":");
- display.display();
- digitalWrite(led3, LOW);
- delay(500);
- break;
- }
- case 4:
- { // provede se ukol pro druhe tlacitko
- digitalWrite(led1, LOW);
- digitalWrite(led2, LOW);
- digitalWrite(led3, LOW);
- digitalWrite(led4, HIGH);
- digitalWrite(led5, HIGH);
- display.clearDisplay();
- display.setCursor(0,0); //Oled display,
- display.setTextColor(WHITE);
- display.setTextSize(3);
- display.print("Svetlo");
- /*
- display.setCursor(0,18);
- display.print(T,1);
- display.setCursor(50,17);
- display.setTextSize(1);
- 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("Alt");
- display.setCursor(90,25);
- display.print(A,0);
- display.setCursor(110,25);
- display.print("m");
- */
- display.display();
- digitalWrite(led4, LOW);
- delay (200);
- break;
- }
- default:
- {
- // provede ukol pro ostatni stavy (napr. StisknuteTlacitko == 0)
- digitalWrite(led1, HIGH);
- digitalWrite(led2, HIGH);
- digitalWrite(led3, HIGH);
- digitalWrite(led4, HIGH);
- digitalWrite(led5, HIGH);
- delay(100);
- digitalWrite(led1, LOW);
- digitalWrite(led2, LOW);
- digitalWrite(led3, LOW);
- digitalWrite(led4, LOW);
- digitalWrite(led5, LOW);
- delay(100);
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment