Hauptprogramm
Dependencies: ILI9340_Driver_Lib PM2_Libary Lib_DFPlayerMini
main.cpp@24:02223fec319a, 2021-04-24 (annotated)
- Committer:
- ackerden
- Date:
- Sat Apr 24 19:06:59 2021 +0000
- Revision:
- 24:02223fec319a
- Parent:
- 21:1aaf25fc8d53
- Child:
- 25:863e6ef1245f
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 | 13:096e5dc3ac23 | 11 | |
ackerden | 15:babdd038715a | 12 | //LED Anzeige |
ackerden | 24:02223fec319a | 13 | #include "Adafruit_LED_Backpack.h" |
ackerden | 16:f0480e9c5039 | 14 | |
pmic | 6:e1fa1a2d7483 | 15 | using namespace std::chrono; |
pmic | 6:e1fa1a2d7483 | 16 | |
pmic | 8:9bb806a7f585 | 17 | InterruptIn user_button(USER_BUTTON); |
pmic | 8:9bb806a7f585 | 18 | DigitalOut led(LED1); |
pmic | 6:e1fa1a2d7483 | 19 | |
ackerden | 24:02223fec319a | 20 | BufferedSerial pc(SERIAL_TX, SERIAL_RX); |
ackerden | 24:02223fec319a | 21 | I2C i2c(PB_9, PB_8); // i2c1 pins |
ackerden | 24:02223fec319a | 22 | |
ackerden | 16:f0480e9c5039 | 23 | |
ackerden | 16:f0480e9c5039 | 24 | |
pmic | 6:e1fa1a2d7483 | 25 | bool executeMainTask = false; |
pmic | 6:e1fa1a2d7483 | 26 | Timer user_button_timer, loop_timer; |
ackerden | 13:096e5dc3ac23 | 27 | |
ackerden | 24:02223fec319a | 28 | //Adafruit_7segment matrix = Adafruit_7segment(); |
pmic | 6:e1fa1a2d7483 | 29 | |
pmic | 6:e1fa1a2d7483 | 30 | /* declaration of custom button functions */ |
pmic | 6:e1fa1a2d7483 | 31 | void button_fall(); |
pmic | 6:e1fa1a2d7483 | 32 | void button_rise(); |
pmic | 6:e1fa1a2d7483 | 33 | |
ackerden | 24:02223fec319a | 34 | void setup() { |
ackerden | 16:f0480e9c5039 | 35 | #ifndef __AVR_ATtiny85__ |
ackerden | 24:02223fec319a | 36 | pc.set_baud(15200); |
ackerden | 24:02223fec319a | 37 | //pc.println("7 Segment Backpack Test"); |
ackerden | 16:f0480e9c5039 | 38 | #endif |
ackerden | 24:02223fec319a | 39 | //matrix.begin(0x70); |
ackerden | 24:02223fec319a | 40 | } |
ackerden | 24:02223fec319a | 41 | |
ackerden | 15:babdd038715a | 42 | |
pmic | 1:93d997d6b232 | 43 | int main() |
pmic | 9:f10b974d01e0 | 44 | { |
ackerden | 13:096e5dc3ac23 | 45 | set_time(1618332129); //Zeit setzen |
ackerden | 16:f0480e9c5039 | 46 | |
ackerden | 16:f0480e9c5039 | 47 | //Laufvariablen |
ackerden | 14:153f377f4030 | 48 | int i = 0; |
ackerden | 14:153f377f4030 | 49 | |
pmic | 6:e1fa1a2d7483 | 50 | user_button.fall(&button_fall); |
pmic | 6:e1fa1a2d7483 | 51 | user_button.rise(&button_rise); |
pmic | 6:e1fa1a2d7483 | 52 | loop_timer.start(); |
pmic | 6:e1fa1a2d7483 | 53 | |
pmic | 1:93d997d6b232 | 54 | while (true) { |
pmic | 6:e1fa1a2d7483 | 55 | |
pmic | 6:e1fa1a2d7483 | 56 | loop_timer.reset(); |
ackerden | 12:dfa3591affef | 57 | |
ackerden | 16:f0480e9c5039 | 58 | /*matrix.print(10000, DEC); |
ackerden | 16:f0480e9c5039 | 59 | matrix.writeDisplay(); |
ackerden | 16:f0480e9c5039 | 60 | delay(500); |
ackerden | 16:f0480e9c5039 | 61 | |
ackerden | 16:f0480e9c5039 | 62 | // print a hex number |
ackerden | 16:f0480e9c5039 | 63 | matrix.print(0xBEEF, HEX); |
ackerden | 16:f0480e9c5039 | 64 | matrix.writeDisplay(); |
ackerden | 16:f0480e9c5039 | 65 | delay(500); |
ackerden | 16:f0480e9c5039 | 66 | |
ackerden | 16:f0480e9c5039 | 67 | // print a floating point |
ackerden | 16:f0480e9c5039 | 68 | matrix.print(12.34); |
ackerden | 16:f0480e9c5039 | 69 | matrix.writeDisplay(); |
ackerden | 16:f0480e9c5039 | 70 | delay(500); |
ackerden | 16:f0480e9c5039 | 71 | |
ackerden | 16:f0480e9c5039 | 72 | // print with print/println |
ackerden | 16:f0480e9c5039 | 73 | for (uint16_t counter = 0; counter < 9999; counter++) { |
ackerden | 16:f0480e9c5039 | 74 | matrix.println(counter); |
ackerden | 16:f0480e9c5039 | 75 | matrix.writeDisplay(); |
ackerden | 16:f0480e9c5039 | 76 | delay(10);*/ |
pmic | 6:e1fa1a2d7483 | 77 | |
ackerden | 12:dfa3591affef | 78 | |
pmic | 6:e1fa1a2d7483 | 79 | |
pmic | 6:e1fa1a2d7483 | 80 | if (executeMainTask) { |
ackerden | 16:f0480e9c5039 | 81 | |
ackerden | 17:621c4212fd4e | 82 | //Zeitfunktion |
ackerden | 17:621c4212fd4e | 83 | uhrzeit(time(NULL)); |
ackerden | 17:621c4212fd4e | 84 | |
ackerden | 17:621c4212fd4e | 85 | switch(i){ |
ackerden | 17:621c4212fd4e | 86 | //2 Minuten |
ackerden | 18:39be9e19768f | 87 | case 120: i += 5; |
ackerden | 17:621c4212fd4e | 88 | //Seesaw Programm |
ackerden | 17:621c4212fd4e | 89 | ThisThread::sleep_for(5s); //Wartet 5s.. |
ackerden | 17:621c4212fd4e | 90 | break; |
ackerden | 17:621c4212fd4e | 91 | //5 Minuten |
haefeman | 20:f825e91784fe | 92 | case 20: |
haefeman | 20:f825e91784fe | 93 | case 10: { i += 5; |
haefeman | 20:f825e91784fe | 94 | bewegung(); |
ackerden | 17:621c4212fd4e | 95 | ThisThread::sleep_for(5s); //Wartet 5s.. |
ackerden | 17:621c4212fd4e | 96 | break; |
haefeman | 20:f825e91784fe | 97 | } |
ackerden | 17:621c4212fd4e | 98 | //7 Minuten |
ackerden | 18:39be9e19768f | 99 | case 420: i += 5; |
ackerden | 17:621c4212fd4e | 100 | //Audio Signal |
ackerden | 17:621c4212fd4e | 101 | ThisThread::sleep_for(5s); //Wartet 5s.. |
ackerden | 17:621c4212fd4e | 102 | break; |
ackerden | 17:621c4212fd4e | 103 | //10 Minuten |
ackerden | 18:39be9e19768f | 104 | case 600: i = 0; |
haefeman | 19:9ccd591cb637 | 105 | ThisThread::sleep_for(5s); //Wartet 5s.. |
ackerden | 17:621c4212fd4e | 106 | break; |
ackerden | 17:621c4212fd4e | 107 | default : i += 5; |
ackerden | 17:621c4212fd4e | 108 | ThisThread::sleep_for(5s); //Wartet 5s.. |
ackerden | 17:621c4212fd4e | 109 | break; |
ackerden | 18:39be9e19768f | 110 | } |
ackerden | 16:f0480e9c5039 | 111 | |
ackerden | 13:096e5dc3ac23 | 112 | led = !led; |
ackerden | 18:39be9e19768f | 113 | |
ackerden | 18:39be9e19768f | 114 | }} |
pmic | 1:93d997d6b232 | 115 | } |
pmic | 6:e1fa1a2d7483 | 116 | |
pmic | 6:e1fa1a2d7483 | 117 | void button_fall() |
pmic | 6:e1fa1a2d7483 | 118 | { |
pmic | 6:e1fa1a2d7483 | 119 | user_button_timer.reset(); |
pmic | 6:e1fa1a2d7483 | 120 | user_button_timer.start(); |
pmic | 6:e1fa1a2d7483 | 121 | } |
pmic | 6:e1fa1a2d7483 | 122 | |
pmic | 6:e1fa1a2d7483 | 123 | void button_rise() |
pmic | 6:e1fa1a2d7483 | 124 | { |
pmic | 6:e1fa1a2d7483 | 125 | int t_button_ms = duration_cast<milliseconds>(user_button_timer.elapsed_time()).count(); |
pmic | 6:e1fa1a2d7483 | 126 | user_button_timer.stop(); |
pmic | 8:9bb806a7f585 | 127 | if (t_button_ms > 200) { |
pmic | 6:e1fa1a2d7483 | 128 | executeMainTask = !executeMainTask; |
pmic | 8:9bb806a7f585 | 129 | } |
ackerden | 16:f0480e9c5039 | 130 | } |