Hauptprogramm

Dependencies:   ILI9340_Driver_Lib PM2_Libary Lib_DFPlayerMini

Committer:
ackerden
Date:
Wed May 05 15:25:02 2021 +0000
Revision:
29:91df2c5fb297
Parent:
27:bbcd157dcd63
Child:
30:39a53ed11b7d
audio;

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 27:bbcd157dcd63 12 #include "Chirp.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 29:91df2c5fb297 33 //I2CPreInit gI2C(PB_9, PB_8);
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
ackerden 27:bbcd157dcd63 40 InterruptIn user_button(USER_BUTTON);
pmic 8:9bb806a7f585 41 DigitalOut led(LED1);
pmic 6:e1fa1a2d7483 42
ackerden 29:91df2c5fb297 43 //BufferedSerial pc(SERIAL_TX, SERIAL_RX);
ackerden 29:91df2c5fb297 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 29:91df2c5fb297 72
ackerden 17:621c4212fd4e 73 //Zeitfunktion
ackerden 17:621c4212fd4e 74 uhrzeit(time(NULL));
ackerden 25:863e6ef1245f 75
ackerden 25:863e6ef1245f 76 //Uhr Anzeige
ackerden 25:863e6ef1245f 77 //clock_display(seconds, minutes, hours);
ackerden 17:621c4212fd4e 78
ackerden 25:863e6ef1245f 79 switch(seconds){
ackerden 17:621c4212fd4e 80 //2 Minuten
ackerden 25:863e6ef1245f 81 case 120: seconds += 5;
ackerden 17:621c4212fd4e 82 //Seesaw Programm
ackerden 27:bbcd157dcd63 83 getResults();
ackerden 17:621c4212fd4e 84 ThisThread::sleep_for(5s); //Wartet 5s..
ackerden 17:621c4212fd4e 85 break;
ackerden 17:621c4212fd4e 86 //5 Minuten
haefeman 26:caa4fab7023e 87 case 300: { seconds += 5;
haefeman 26:caa4fab7023e 88 bewegung(1);
ackerden 17:621c4212fd4e 89 ThisThread::sleep_for(5s); //Wartet 5s..
ackerden 17:621c4212fd4e 90 break;
haefeman 20:f825e91784fe 91 }
ackerden 17:621c4212fd4e 92 //7 Minuten
ackerden 25:863e6ef1245f 93 case 420: seconds += 5;
haefeman 26:caa4fab7023e 94 bewegung(2);
ackerden 17:621c4212fd4e 95 //Audio Signal
ackerden 17:621c4212fd4e 96 ThisThread::sleep_for(5s); //Wartet 5s..
ackerden 17:621c4212fd4e 97 break;
ackerden 17:621c4212fd4e 98 //10 Minuten
haefeman 26:caa4fab7023e 99 case 600: seconds += 5;
haefeman 26:caa4fab7023e 100 bewegung(3);
haefeman 26:caa4fab7023e 101 //Audio Signal
haefeman 19:9ccd591cb637 102 ThisThread::sleep_for(5s); //Wartet 5s..
ackerden 17:621c4212fd4e 103 break;
ackerden 25:863e6ef1245f 104 default : seconds += 5;
ackerden 17:621c4212fd4e 105 ThisThread::sleep_for(5s); //Wartet 5s..
ackerden 17:621c4212fd4e 106 break;
ackerden 18:39be9e19768f 107 }
ackerden 16:f0480e9c5039 108
ackerden 13:096e5dc3ac23 109 led = !led;
ackerden 18:39be9e19768f 110
ackerden 25:863e6ef1245f 111 }
ackerden 25:863e6ef1245f 112 }
pmic 1:93d997d6b232 113 }
pmic 6:e1fa1a2d7483 114
pmic 6:e1fa1a2d7483 115 void button_fall()
pmic 6:e1fa1a2d7483 116 {
pmic 6:e1fa1a2d7483 117 user_button_timer.reset();
pmic 6:e1fa1a2d7483 118 user_button_timer.start();
pmic 6:e1fa1a2d7483 119 }
pmic 6:e1fa1a2d7483 120
pmic 6:e1fa1a2d7483 121 void button_rise()
pmic 6:e1fa1a2d7483 122 {
pmic 6:e1fa1a2d7483 123 int t_button_ms = duration_cast<milliseconds>(user_button_timer.elapsed_time()).count();
pmic 6:e1fa1a2d7483 124 user_button_timer.stop();
pmic 8:9bb806a7f585 125 if (t_button_ms > 200) {
pmic 6:e1fa1a2d7483 126 executeMainTask = !executeMainTask;
pmic 8:9bb806a7f585 127 }
ackerden 27:bbcd157dcd63 128 }