Hauptprogramm
Dependencies: ILI9340_Driver_Lib PM2_Libary Lib_DFPlayerMini
main.cpp@25:863e6ef1245f, 2021-04-27 (annotated)
- Committer:
- ackerden
- Date:
- Tue Apr 27 20:04:51 2021 +0000
- Revision:
- 25:863e6ef1245f
- Parent:
- 24:02223fec319a
- Child:
- 26:caa4fab7023e
Who changed what in which revision?
User | Revision | Line number | New 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 | 20:f825e91784fe | 88 | case 20: |
ackerden | 25:863e6ef1245f | 89 | case 10: { seconds += 5; |
haefeman | 20:f825e91784fe | 90 | bewegung(); |
ackerden | 17:621c4212fd4e | 91 | ThisThread::sleep_for(5s); //Wartet 5s.. |
ackerden | 17:621c4212fd4e | 92 | break; |
haefeman | 20:f825e91784fe | 93 | } |
ackerden | 17:621c4212fd4e | 94 | //7 Minuten |
ackerden | 25:863e6ef1245f | 95 | case 420: seconds += 5; |
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 |
ackerden | 25:863e6ef1245f | 100 | case 600: seconds = 0; |
haefeman | 19:9ccd591cb637 | 101 | ThisThread::sleep_for(5s); //Wartet 5s.. |
ackerden | 17:621c4212fd4e | 102 | break; |
ackerden | 25:863e6ef1245f | 103 | default : seconds += 5; |
ackerden | 17:621c4212fd4e | 104 | ThisThread::sleep_for(5s); //Wartet 5s.. |
ackerden | 17:621c4212fd4e | 105 | break; |
ackerden | 18:39be9e19768f | 106 | } |
ackerden | 16:f0480e9c5039 | 107 | |
ackerden | 13:096e5dc3ac23 | 108 | led = !led; |
ackerden | 18:39be9e19768f | 109 | |
ackerden | 25:863e6ef1245f | 110 | } |
ackerden | 25:863e6ef1245f | 111 | } |
pmic | 1:93d997d6b232 | 112 | } |
ackerden | 25:863e6ef1245f | 113 | /*void clock_display(){ |
ackerden | 25:863e6ef1245f | 114 | //int displayValue = hours*100 + minutes; |
ackerden | 25:863e6ef1245f | 115 | |
ackerden | 25:863e6ef1245f | 116 | // Now print the time value to the display. |
ackerden | 25:863e6ef1245f | 117 | clockDisplay.print(displayValue, DEC); |
ackerden | 25:863e6ef1245f | 118 | |
ackerden | 25:863e6ef1245f | 119 | // Add zero padding when in 24 hour mode and it's midnight. |
ackerden | 25:863e6ef1245f | 120 | // In this case the print function above won't have leading 0's |
ackerden | 25:863e6ef1245f | 121 | // which can look confusing. Go in and explicitly add these zeros. |
ackerden | 25:863e6ef1245f | 122 | if (TIME_24_HOUR && hours == 0) { |
ackerden | 25:863e6ef1245f | 123 | // Pad hour 0. |
ackerden | 25:863e6ef1245f | 124 | clockDisplay.writeDigitNum(1, 0); |
ackerden | 25:863e6ef1245f | 125 | // Also pad when the 10's minute is 0 and should be padded. |
ackerden | 25:863e6ef1245f | 126 | if (minutes < 10) { |
ackerden | 25:863e6ef1245f | 127 | clockDisplay.writeDigitNum(2, 0); |
ackerden | 25:863e6ef1245f | 128 | } |
ackerden | 25:863e6ef1245f | 129 | } |
ackerden | 25:863e6ef1245f | 130 | |
ackerden | 25:863e6ef1245f | 131 | // Blink the colon by flipping its value every loop iteration |
ackerden | 25:863e6ef1245f | 132 | // (which happens every second). |
ackerden | 25:863e6ef1245f | 133 | blinkColon = !blinkColon; |
ackerden | 25:863e6ef1245f | 134 | clockDisplay.drawColon(blinkColon); |
ackerden | 25:863e6ef1245f | 135 | |
ackerden | 25:863e6ef1245f | 136 | // Now push out to the display the new values that were set above. |
ackerden | 25:863e6ef1245f | 137 | clockDisplay.writeDisplay(); |
ackerden | 25:863e6ef1245f | 138 | |
ackerden | 25:863e6ef1245f | 139 | // Pause for a second for time to elapse. This value is in milliseconds |
ackerden | 25:863e6ef1245f | 140 | // so 1000 milliseconds = 1 second. |
ackerden | 25:863e6ef1245f | 141 | delay(1000); |
ackerden | 25:863e6ef1245f | 142 | |
ackerden | 25:863e6ef1245f | 143 | // Now increase the seconds by one. |
ackerden | 25:863e6ef1245f | 144 | seconds += 1; |
ackerden | 25:863e6ef1245f | 145 | // If the seconds go above 59 then the minutes should increase and |
ackerden | 25:863e6ef1245f | 146 | // the seconds should wrap back to 0. |
ackerden | 25:863e6ef1245f | 147 | if (seconds > 59) { |
ackerden | 25:863e6ef1245f | 148 | seconds = 0; |
ackerden | 25:863e6ef1245f | 149 | minutes += 1; |
ackerden | 25:863e6ef1245f | 150 | // Again if the minutes go above 59 then the hour should increase and |
ackerden | 25:863e6ef1245f | 151 | // the minutes should wrap back to 0. |
ackerden | 25:863e6ef1245f | 152 | if (minutes > 59) { |
ackerden | 25:863e6ef1245f | 153 | minutes = 0; |
ackerden | 25:863e6ef1245f | 154 | hours += 1; |
ackerden | 25:863e6ef1245f | 155 | // Note that when the minutes are 0 (i.e. it's the top of a new hour) |
ackerden | 25:863e6ef1245f | 156 | // then the start of the loop will read the actual time from the DS1307 |
ackerden | 25:863e6ef1245f | 157 | // again. Just to be safe though we'll also increment the hour and wrap |
ackerden | 25:863e6ef1245f | 158 | // back to 0 if it goes above 23 (i.e. past midnight). |
ackerden | 25:863e6ef1245f | 159 | if (hours > 23) { |
ackerden | 25:863e6ef1245f | 160 | hours = 0; |
ackerden | 25:863e6ef1245f | 161 | } |
ackerden | 25:863e6ef1245f | 162 | } |
ackerden | 25:863e6ef1245f | 163 | }}*/ |
ackerden | 25:863e6ef1245f | 164 | |
ackerden | 25:863e6ef1245f | 165 | |
ackerden | 25:863e6ef1245f | 166 | |
ackerden | 25:863e6ef1245f | 167 | |
ackerden | 25:863e6ef1245f | 168 | |
pmic | 6:e1fa1a2d7483 | 169 | |
pmic | 6:e1fa1a2d7483 | 170 | void button_fall() |
pmic | 6:e1fa1a2d7483 | 171 | { |
pmic | 6:e1fa1a2d7483 | 172 | user_button_timer.reset(); |
pmic | 6:e1fa1a2d7483 | 173 | user_button_timer.start(); |
pmic | 6:e1fa1a2d7483 | 174 | } |
pmic | 6:e1fa1a2d7483 | 175 | |
pmic | 6:e1fa1a2d7483 | 176 | void button_rise() |
pmic | 6:e1fa1a2d7483 | 177 | { |
pmic | 6:e1fa1a2d7483 | 178 | int t_button_ms = duration_cast<milliseconds>(user_button_timer.elapsed_time()).count(); |
pmic | 6:e1fa1a2d7483 | 179 | user_button_timer.stop(); |
pmic | 8:9bb806a7f585 | 180 | if (t_button_ms > 200) { |
pmic | 6:e1fa1a2d7483 | 181 | executeMainTask = !executeMainTask; |
pmic | 8:9bb806a7f585 | 182 | } |
ackerden | 16:f0480e9c5039 | 183 | } |