Hauptprogramm
Dependencies: ILI9340_Driver_Lib PM2_Libary Lib_DFPlayerMini
main.cpp
- Committer:
- haefeman
- Date:
- 2021-04-28
- Revision:
- 26:caa4fab7023e
- Parent:
- 25:863e6ef1245f
- Child:
- 27:bbcd157dcd63
File content as of revision 26:caa4fab7023e:
#include "mbed.h" //Eigene Header einbinden //include Zeitfunktion #include "realtimer.h" //include Servosteuerung #include "servo_bewegung.h" //include Feuchtigkeitssensor #include "soil_tester.h" //LED Anzeige //#include "clock_display.h" //#include "Adafruit_LED_Backpack.h" #define TIME_24_HOUR true #define DISPLAY_ADDRESS 0x70 // an I2C sub-class that provides a constructed default class I2CPreInit : public I2C { public: I2CPreInit(PinName sda, PinName scl) : I2C(sda, scl) { frequency(400000); //start(); }; }; I2CPreInit gI2C(I2C_SDA, I2C_SCL); //Adafruit_7segment clockDisplay = Adafruit_7segment(); //clockDisplay.begin(DISPLAY_ADDRESS); //bool blinkColon = false; using namespace std::chrono; InterruptIn user_button(USER_BUTTON); DigitalOut led(LED1); //BufferedSerial pc(SERIAL_TX, SERIAL_RX); //I2C i2c(PB_9, PB_8); // i2c1 pins bool executeMainTask = false; Timer user_button_timer, loop_timer; /* declaration of custom button functions */ void button_fall(); void button_rise(); int main() { set_time(1618332129); //Zeit setzen //Laufvariablen int hours = 0; int minutes = 0; int seconds = 0; user_button.fall(&button_fall); user_button.rise(&button_rise); loop_timer.start(); while (true) { loop_timer.reset(); if (executeMainTask) { soil_test(); //Zeitfunktion uhrzeit(time(NULL)); //Uhr Anzeige //clock_display(seconds, minutes, hours); switch(seconds){ //2 Minuten case 120: seconds += 5; //Seesaw Programm soil_test(); ThisThread::sleep_for(5s); //Wartet 5s.. break; //5 Minuten case 300: { seconds += 5; bewegung(1); ThisThread::sleep_for(5s); //Wartet 5s.. break; } //7 Minuten case 420: seconds += 5; bewegung(2); //Audio Signal ThisThread::sleep_for(5s); //Wartet 5s.. break; //10 Minuten case 600: seconds += 5; bewegung(3); //Audio Signal ThisThread::sleep_for(5s); //Wartet 5s.. break; default : seconds += 5; ThisThread::sleep_for(5s); //Wartet 5s.. break; } led = !led; } } } /*void clock_display(){ //int displayValue = hours*100 + minutes; // Now print the time value to the display. clockDisplay.print(displayValue, DEC); // Add zero padding when in 24 hour mode and it's midnight. // In this case the print function above won't have leading 0's // which can look confusing. Go in and explicitly add these zeros. if (TIME_24_HOUR && hours == 0) { // Pad hour 0. clockDisplay.writeDigitNum(1, 0); // Also pad when the 10's minute is 0 and should be padded. if (minutes < 10) { clockDisplay.writeDigitNum(2, 0); } } // Blink the colon by flipping its value every loop iteration // (which happens every second). blinkColon = !blinkColon; clockDisplay.drawColon(blinkColon); // Now push out to the display the new values that were set above. clockDisplay.writeDisplay(); // Pause for a second for time to elapse. This value is in milliseconds // so 1000 milliseconds = 1 second. delay(1000); // Now increase the seconds by one. seconds += 1; // If the seconds go above 59 then the minutes should increase and // the seconds should wrap back to 0. if (seconds > 59) { seconds = 0; minutes += 1; // Again if the minutes go above 59 then the hour should increase and // the minutes should wrap back to 0. if (minutes > 59) { minutes = 0; hours += 1; // Note that when the minutes are 0 (i.e. it's the top of a new hour) // then the start of the loop will read the actual time from the DS1307 // again. Just to be safe though we'll also increment the hour and wrap // back to 0 if it goes above 23 (i.e. past midnight). if (hours > 23) { hours = 0; } } }}*/ void button_fall() { user_button_timer.reset(); user_button_timer.start(); } void button_rise() { int t_button_ms = duration_cast<milliseconds>(user_button_timer.elapsed_time()).count(); user_button_timer.stop(); if (t_button_ms > 200) { executeMainTask = !executeMainTask; } }