Hauptprogramm

Dependencies:   ILI9340_Driver_Lib PM2_Libary Lib_DFPlayerMini

Revision:
25:863e6ef1245f
Parent:
24:02223fec319a
Child:
26:caa4fab7023e
--- a/main.cpp	Sat Apr 24 19:06:59 2021 +0000
+++ b/main.cpp	Tue Apr 27 20:04:51 2021 +0000
@@ -8,44 +8,57 @@
 //include Servosteuerung
 #include "servo_bewegung.h"
 
+//include Feuchtigkeitssensor
+#include "soil_tester.h"
 
 //LED Anzeige
-#include "Adafruit_LED_Backpack.h"
+//#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
-    
-
+//BufferedSerial pc(SERIAL_TX, SERIAL_RX);
+//I2C i2c(PB_9, PB_8);     // i2c1 pins
 
 bool  executeMainTask = false;
 Timer user_button_timer, loop_timer;
 
-//Adafruit_7segment matrix = Adafruit_7segment();
-
 /* declaration of custom button functions */
 void button_fall();
 void button_rise();
 
-void setup() {
-#ifndef __AVR_ATtiny85__
-  pc.set_baud(15200);
-  //pc.println("7 Segment Backpack Test");
-#endif
-  //matrix.begin(0x70);
-}
-
 
 int main()
 {
     set_time(1618332129);  //Zeit setzen
     
     //Laufvariablen
-    int i = 0;
+    int hours = 0;
+    int minutes = 0;
+    int seconds = 0;
     
     user_button.fall(&button_fall);
     user_button.rise(&button_rise);
@@ -54,65 +67,105 @@
     while (true) {
 
         loop_timer.reset();
-        
-  /*matrix.print(10000, DEC);
-  matrix.writeDisplay();
-  delay(500);
-
-  // print a hex number
-  matrix.print(0xBEEF, HEX);
-  matrix.writeDisplay();
-  delay(500);
-
-  // print a floating point 
-  matrix.print(12.34);
-  matrix.writeDisplay();
-  delay(500);
-  
-  // print with print/println
-  for (uint16_t counter = 0; counter < 9999; counter++) {
-    matrix.println(counter);
-    matrix.writeDisplay();
-    delay(10);*/
-
  
-
         if (executeMainTask) {
+            soil_test();
             
             //Zeitfunktion
             uhrzeit(time(NULL));
+
+            //Uhr Anzeige
+            //clock_display(seconds, minutes, hours);
             
-            switch(i){
+            switch(seconds){
                 //2 Minuten
-                case 120:    i += 5;
+                case 120:    seconds += 5;
                             //Seesaw Programm
+                            soil_test();
                             ThisThread::sleep_for(5s); //Wartet 5s..
                             break;
                 //5 Minuten
                 case 20:
-                case 10: {   i += 5;
+                case 10: {   seconds += 5;
                             bewegung();
                             ThisThread::sleep_for(5s); //Wartet 5s..
                             break;
                         }
                 //7 Minuten
-                case 420:    i += 5;
+                case 420:    seconds += 5;
                             //Audio Signal
                             ThisThread::sleep_for(5s); //Wartet 5s..
                             break;
                 //10 Minuten
-                case 600:   i = 0;
+                case 600:   seconds = 0;
                             ThisThread::sleep_for(5s); //Wartet 5s..
                             break;
-                default :   i += 5;
+                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()
 {