Hauptprogramm

Dependencies:   ILI9340_Driver_Lib PM2_Libary Lib_DFPlayerMini

Committer:
haefeman
Date:
Wed Apr 28 14:58:37 2021 +0000
Revision:
26:caa4fab7023e
Parent:
25:863e6ef1245f
Child:
27:bbcd157dcd63
3 servos

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pmic 1:93d997d6b232 1 #include "mbed.h"
ackerden 24:02223fec319a 2
ackerden 16:f0480e9c5039 3 //Eigene Header einbinden
pmic 6:e1fa1a2d7483 4
ackerden 16:f0480e9c5039 5 //include Zeitfunktion
ackerden 13:096e5dc3ac23 6 #include "realtimer.h"
haefeman 11:be62f37f3a98 7
ackerden 16:f0480e9c5039 8 //include Servosteuerung
ackerden 16:f0480e9c5039 9 #include "servo_bewegung.h"
ackerden 16:f0480e9c5039 10
ackerden 25:863e6ef1245f 11 //include Feuchtigkeitssensor
ackerden 25:863e6ef1245f 12 #include "soil_tester.h"
ackerden 13:096e5dc3ac23 13
ackerden 15:babdd038715a 14 //LED Anzeige
ackerden 25:863e6ef1245f 15 //#include "clock_display.h"
ackerden 25:863e6ef1245f 16 //#include "Adafruit_LED_Backpack.h"
ackerden 25:863e6ef1245f 17
ackerden 25:863e6ef1245f 18 #define TIME_24_HOUR true
ackerden 25:863e6ef1245f 19 #define DISPLAY_ADDRESS 0x70
ackerden 25:863e6ef1245f 20
ackerden 25:863e6ef1245f 21 // an I2C sub-class that provides a constructed default
ackerden 25:863e6ef1245f 22 class I2CPreInit : public I2C
ackerden 25:863e6ef1245f 23 {
ackerden 25:863e6ef1245f 24 public:
ackerden 25:863e6ef1245f 25 I2CPreInit(PinName sda, PinName scl) : I2C(sda, scl)
ackerden 25:863e6ef1245f 26 {
ackerden 25:863e6ef1245f 27 frequency(400000);
ackerden 25:863e6ef1245f 28 //start();
ackerden 25:863e6ef1245f 29 };
ackerden 25:863e6ef1245f 30 };
ackerden 25:863e6ef1245f 31
ackerden 25:863e6ef1245f 32
ackerden 25:863e6ef1245f 33 I2CPreInit gI2C(I2C_SDA, I2C_SCL);
ackerden 25:863e6ef1245f 34 //Adafruit_7segment clockDisplay = Adafruit_7segment();
ackerden 25:863e6ef1245f 35 //clockDisplay.begin(DISPLAY_ADDRESS);
ackerden 25:863e6ef1245f 36 //bool blinkColon = false;
ackerden 16:f0480e9c5039 37
pmic 6:e1fa1a2d7483 38 using namespace std::chrono;
pmic 6:e1fa1a2d7483 39
pmic 8:9bb806a7f585 40 InterruptIn user_button(USER_BUTTON);
pmic 8:9bb806a7f585 41 DigitalOut led(LED1);
pmic 6:e1fa1a2d7483 42
ackerden 25:863e6ef1245f 43 //BufferedSerial pc(SERIAL_TX, SERIAL_RX);
ackerden 25:863e6ef1245f 44 //I2C i2c(PB_9, PB_8); // i2c1 pins
ackerden 16:f0480e9c5039 45
pmic 6:e1fa1a2d7483 46 bool executeMainTask = false;
pmic 6:e1fa1a2d7483 47 Timer user_button_timer, loop_timer;
ackerden 13:096e5dc3ac23 48
pmic 6:e1fa1a2d7483 49 /* declaration of custom button functions */
pmic 6:e1fa1a2d7483 50 void button_fall();
pmic 6:e1fa1a2d7483 51 void button_rise();
pmic 6:e1fa1a2d7483 52
ackerden 15:babdd038715a 53
pmic 1:93d997d6b232 54 int main()
pmic 9:f10b974d01e0 55 {
ackerden 13:096e5dc3ac23 56 set_time(1618332129); //Zeit setzen
ackerden 16:f0480e9c5039 57
ackerden 16:f0480e9c5039 58 //Laufvariablen
ackerden 25:863e6ef1245f 59 int hours = 0;
ackerden 25:863e6ef1245f 60 int minutes = 0;
ackerden 25:863e6ef1245f 61 int seconds = 0;
ackerden 14:153f377f4030 62
pmic 6:e1fa1a2d7483 63 user_button.fall(&button_fall);
pmic 6:e1fa1a2d7483 64 user_button.rise(&button_rise);
pmic 6:e1fa1a2d7483 65 loop_timer.start();
pmic 6:e1fa1a2d7483 66
pmic 1:93d997d6b232 67 while (true) {
pmic 6:e1fa1a2d7483 68
pmic 6:e1fa1a2d7483 69 loop_timer.reset();
ackerden 12:dfa3591affef 70
pmic 6:e1fa1a2d7483 71 if (executeMainTask) {
ackerden 25:863e6ef1245f 72 soil_test();
ackerden 16:f0480e9c5039 73
ackerden 17:621c4212fd4e 74 //Zeitfunktion
ackerden 17:621c4212fd4e 75 uhrzeit(time(NULL));
ackerden 25:863e6ef1245f 76
ackerden 25:863e6ef1245f 77 //Uhr Anzeige
ackerden 25:863e6ef1245f 78 //clock_display(seconds, minutes, hours);
ackerden 17:621c4212fd4e 79
ackerden 25:863e6ef1245f 80 switch(seconds){
ackerden 17:621c4212fd4e 81 //2 Minuten
ackerden 25:863e6ef1245f 82 case 120: seconds += 5;
ackerden 17:621c4212fd4e 83 //Seesaw Programm
ackerden 25:863e6ef1245f 84 soil_test();
ackerden 17:621c4212fd4e 85 ThisThread::sleep_for(5s); //Wartet 5s..
ackerden 17:621c4212fd4e 86 break;
ackerden 17:621c4212fd4e 87 //5 Minuten
haefeman 26:caa4fab7023e 88 case 300: { seconds += 5;
haefeman 26:caa4fab7023e 89 bewegung(1);
ackerden 17:621c4212fd4e 90 ThisThread::sleep_for(5s); //Wartet 5s..
ackerden 17:621c4212fd4e 91 break;
haefeman 20:f825e91784fe 92 }
ackerden 17:621c4212fd4e 93 //7 Minuten
ackerden 25:863e6ef1245f 94 case 420: seconds += 5;
haefeman 26:caa4fab7023e 95 bewegung(2);
ackerden 17:621c4212fd4e 96 //Audio Signal
ackerden 17:621c4212fd4e 97 ThisThread::sleep_for(5s); //Wartet 5s..
ackerden 17:621c4212fd4e 98 break;
ackerden 17:621c4212fd4e 99 //10 Minuten
haefeman 26:caa4fab7023e 100 case 600: seconds += 5;
haefeman 26:caa4fab7023e 101 bewegung(3);
haefeman 26:caa4fab7023e 102 //Audio Signal
haefeman 19:9ccd591cb637 103 ThisThread::sleep_for(5s); //Wartet 5s..
ackerden 17:621c4212fd4e 104 break;
ackerden 25:863e6ef1245f 105 default : seconds += 5;
ackerden 17:621c4212fd4e 106 ThisThread::sleep_for(5s); //Wartet 5s..
ackerden 17:621c4212fd4e 107 break;
ackerden 18:39be9e19768f 108 }
ackerden 16:f0480e9c5039 109
ackerden 13:096e5dc3ac23 110 led = !led;
ackerden 18:39be9e19768f 111
ackerden 25:863e6ef1245f 112 }
ackerden 25:863e6ef1245f 113 }
pmic 1:93d997d6b232 114 }
ackerden 25:863e6ef1245f 115 /*void clock_display(){
ackerden 25:863e6ef1245f 116 //int displayValue = hours*100 + minutes;
ackerden 25:863e6ef1245f 117
ackerden 25:863e6ef1245f 118 // Now print the time value to the display.
ackerden 25:863e6ef1245f 119 clockDisplay.print(displayValue, DEC);
ackerden 25:863e6ef1245f 120
ackerden 25:863e6ef1245f 121 // Add zero padding when in 24 hour mode and it's midnight.
ackerden 25:863e6ef1245f 122 // In this case the print function above won't have leading 0's
ackerden 25:863e6ef1245f 123 // which can look confusing. Go in and explicitly add these zeros.
ackerden 25:863e6ef1245f 124 if (TIME_24_HOUR && hours == 0) {
ackerden 25:863e6ef1245f 125 // Pad hour 0.
ackerden 25:863e6ef1245f 126 clockDisplay.writeDigitNum(1, 0);
ackerden 25:863e6ef1245f 127 // Also pad when the 10's minute is 0 and should be padded.
ackerden 25:863e6ef1245f 128 if (minutes < 10) {
ackerden 25:863e6ef1245f 129 clockDisplay.writeDigitNum(2, 0);
ackerden 25:863e6ef1245f 130 }
ackerden 25:863e6ef1245f 131 }
ackerden 25:863e6ef1245f 132
ackerden 25:863e6ef1245f 133 // Blink the colon by flipping its value every loop iteration
ackerden 25:863e6ef1245f 134 // (which happens every second).
ackerden 25:863e6ef1245f 135 blinkColon = !blinkColon;
ackerden 25:863e6ef1245f 136 clockDisplay.drawColon(blinkColon);
ackerden 25:863e6ef1245f 137
ackerden 25:863e6ef1245f 138 // Now push out to the display the new values that were set above.
ackerden 25:863e6ef1245f 139 clockDisplay.writeDisplay();
ackerden 25:863e6ef1245f 140
ackerden 25:863e6ef1245f 141 // Pause for a second for time to elapse. This value is in milliseconds
ackerden 25:863e6ef1245f 142 // so 1000 milliseconds = 1 second.
ackerden 25:863e6ef1245f 143 delay(1000);
ackerden 25:863e6ef1245f 144
ackerden 25:863e6ef1245f 145 // Now increase the seconds by one.
ackerden 25:863e6ef1245f 146 seconds += 1;
ackerden 25:863e6ef1245f 147 // If the seconds go above 59 then the minutes should increase and
ackerden 25:863e6ef1245f 148 // the seconds should wrap back to 0.
ackerden 25:863e6ef1245f 149 if (seconds > 59) {
ackerden 25:863e6ef1245f 150 seconds = 0;
ackerden 25:863e6ef1245f 151 minutes += 1;
ackerden 25:863e6ef1245f 152 // Again if the minutes go above 59 then the hour should increase and
ackerden 25:863e6ef1245f 153 // the minutes should wrap back to 0.
ackerden 25:863e6ef1245f 154 if (minutes > 59) {
ackerden 25:863e6ef1245f 155 minutes = 0;
ackerden 25:863e6ef1245f 156 hours += 1;
ackerden 25:863e6ef1245f 157 // Note that when the minutes are 0 (i.e. it's the top of a new hour)
ackerden 25:863e6ef1245f 158 // then the start of the loop will read the actual time from the DS1307
ackerden 25:863e6ef1245f 159 // again. Just to be safe though we'll also increment the hour and wrap
ackerden 25:863e6ef1245f 160 // back to 0 if it goes above 23 (i.e. past midnight).
ackerden 25:863e6ef1245f 161 if (hours > 23) {
ackerden 25:863e6ef1245f 162 hours = 0;
ackerden 25:863e6ef1245f 163 }
ackerden 25:863e6ef1245f 164 }
ackerden 25:863e6ef1245f 165 }}*/
ackerden 25:863e6ef1245f 166
ackerden 25:863e6ef1245f 167
ackerden 25:863e6ef1245f 168
ackerden 25:863e6ef1245f 169
ackerden 25:863e6ef1245f 170
pmic 6:e1fa1a2d7483 171
pmic 6:e1fa1a2d7483 172 void button_fall()
pmic 6:e1fa1a2d7483 173 {
pmic 6:e1fa1a2d7483 174 user_button_timer.reset();
pmic 6:e1fa1a2d7483 175 user_button_timer.start();
pmic 6:e1fa1a2d7483 176 }
pmic 6:e1fa1a2d7483 177
pmic 6:e1fa1a2d7483 178 void button_rise()
pmic 6:e1fa1a2d7483 179 {
pmic 6:e1fa1a2d7483 180 int t_button_ms = duration_cast<milliseconds>(user_button_timer.elapsed_time()).count();
pmic 6:e1fa1a2d7483 181 user_button_timer.stop();
pmic 8:9bb806a7f585 182 if (t_button_ms > 200) {
pmic 6:e1fa1a2d7483 183 executeMainTask = !executeMainTask;
pmic 8:9bb806a7f585 184 }
ackerden 16:f0480e9c5039 185 }