Hauptprogramm
Dependencies: ILI9340_Driver_Lib PM2_Libary Lib_DFPlayerMini
main.cpp@15:babdd038715a, 2021-04-19 (annotated)
- Committer:
- ackerden
- Date:
- Mon Apr 19 14:10:40 2021 +0000
- Revision:
- 15:babdd038715a
- Parent:
- 14:153f377f4030
- Child:
- 16:f0480e9c5039
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pmic | 1:93d997d6b232 | 1 | #include "mbed.h" |
pmic | 6:e1fa1a2d7483 | 2 | |
ackerden | 13:096e5dc3ac23 | 3 | //Eigene Header einbinden |
ackerden | 13:096e5dc3ac23 | 4 | #include "realtimer.h" |
haefeman | 11:be62f37f3a98 | 5 | |
ackerden | 13:096e5dc3ac23 | 6 | |
ackerden | 15:babdd038715a | 7 | //LED Anzeige |
ackerden | 15:babdd038715a | 8 | #include "Adafruit_LEDBackpack.h" |
ackerden | 15:babdd038715a | 9 | #include "Adafruit_GFX.h" |
ackerden | 15:babdd038715a | 10 | #include "glcdfont.h" |
ackerden | 15:babdd038715a | 11 | |
pmic | 6:e1fa1a2d7483 | 12 | |
pmic | 6:e1fa1a2d7483 | 13 | using namespace std::chrono; |
pmic | 6:e1fa1a2d7483 | 14 | |
pmic | 8:9bb806a7f585 | 15 | InterruptIn user_button(USER_BUTTON); |
pmic | 8:9bb806a7f585 | 16 | DigitalOut led(LED1); |
pmic | 6:e1fa1a2d7483 | 17 | |
ackerden | 12:dfa3591affef | 18 | |
pmic | 6:e1fa1a2d7483 | 19 | bool executeMainTask = false; |
pmic | 6:e1fa1a2d7483 | 20 | Timer user_button_timer, loop_timer; |
ackerden | 13:096e5dc3ac23 | 21 | |
pmic | 6:e1fa1a2d7483 | 22 | |
pmic | 6:e1fa1a2d7483 | 23 | /* declaration of custom button functions */ |
pmic | 6:e1fa1a2d7483 | 24 | void button_fall(); |
pmic | 6:e1fa1a2d7483 | 25 | void button_rise(); |
pmic | 6:e1fa1a2d7483 | 26 | |
ackerden | 12:dfa3591affef | 27 | |
ackerden | 15:babdd038715a | 28 | I2C i2c(D14, D6); |
ackerden | 15:babdd038715a | 29 | Adafruit_8x8matrix matrix = Adafruit_8x8matrix(&i2c); |
ackerden | 15:babdd038715a | 30 | |
pmic | 1:93d997d6b232 | 31 | int main() |
pmic | 9:f10b974d01e0 | 32 | { |
ackerden | 15:babdd038715a | 33 | matrix.begin(0x70); |
ackerden | 15:babdd038715a | 34 | |
ackerden | 13:096e5dc3ac23 | 35 | set_time(1618332129); //Zeit setzen |
ackerden | 14:153f377f4030 | 36 | int i = 0; |
ackerden | 14:153f377f4030 | 37 | |
ackerden | 14:153f377f4030 | 38 | |
pmic | 6:e1fa1a2d7483 | 39 | user_button.fall(&button_fall); |
pmic | 6:e1fa1a2d7483 | 40 | user_button.rise(&button_rise); |
pmic | 6:e1fa1a2d7483 | 41 | loop_timer.start(); |
pmic | 6:e1fa1a2d7483 | 42 | |
pmic | 1:93d997d6b232 | 43 | while (true) { |
pmic | 6:e1fa1a2d7483 | 44 | |
pmic | 6:e1fa1a2d7483 | 45 | loop_timer.reset(); |
ackerden | 12:dfa3591affef | 46 | |
ackerden | 15:babdd038715a | 47 | matrix.clear(); |
ackerden | 15:babdd038715a | 48 | for (int i = 0; i < 8; i++) { |
ackerden | 15:babdd038715a | 49 | for (int j = 0; j < 8; j++) { |
ackerden | 15:babdd038715a | 50 | matrix.drawPixel(i, j, LED_ON); |
ackerden | 15:babdd038715a | 51 | } |
ackerden | 15:babdd038715a | 52 | } |
ackerden | 15:babdd038715a | 53 | matrix.writeDisplay(); // write the changes we just made to the display |
ackerden | 15:babdd038715a | 54 | wait(60); |
pmic | 6:e1fa1a2d7483 | 55 | |
ackerden | 12:dfa3591affef | 56 | |
pmic | 6:e1fa1a2d7483 | 57 | |
pmic | 6:e1fa1a2d7483 | 58 | if (executeMainTask) { |
ackerden | 13:096e5dc3ac23 | 59 | |
ackerden | 13:096e5dc3ac23 | 60 | //Zeitfunktion |
ackerden | 13:096e5dc3ac23 | 61 | uhrzeit(time(NULL)); |
ackerden | 14:153f377f4030 | 62 | |
ackerden | 14:153f377f4030 | 63 | |
ackerden | 14:153f377f4030 | 64 | //Zeitfunktionen |
ackerden | 14:153f377f4030 | 65 | if (i != 360){ |
ackerden | 14:153f377f4030 | 66 | ThisThread::sleep_for(5s); //Wartet 5s.. |
ackerden | 14:153f377f4030 | 67 | printf("%d\n", i); |
ackerden | 14:153f377f4030 | 68 | } |
ackerden | 14:153f377f4030 | 69 | else{ |
ackerden | 14:153f377f4030 | 70 | i=0; |
ackerden | 14:153f377f4030 | 71 | } |
ackerden | 14:153f377f4030 | 72 | i += 5; |
pmic | 6:e1fa1a2d7483 | 73 | |
ackerden | 13:096e5dc3ac23 | 74 | led = !led; |
pmic | 9:f10b974d01e0 | 75 | |
pmic | 1:93d997d6b232 | 76 | } else { |
pmic | 6:e1fa1a2d7483 | 77 | |
ackerden | 13:096e5dc3ac23 | 78 | |
pmic | 6:e1fa1a2d7483 | 79 | led = 0; |
pmic | 1:93d997d6b232 | 80 | } |
pmic | 6:e1fa1a2d7483 | 81 | |
ackerden | 13:096e5dc3ac23 | 82 | |
pmic | 1:93d997d6b232 | 83 | } |
pmic | 1:93d997d6b232 | 84 | } |
pmic | 6:e1fa1a2d7483 | 85 | |
pmic | 6:e1fa1a2d7483 | 86 | void button_fall() |
pmic | 6:e1fa1a2d7483 | 87 | { |
pmic | 6:e1fa1a2d7483 | 88 | user_button_timer.reset(); |
pmic | 6:e1fa1a2d7483 | 89 | user_button_timer.start(); |
pmic | 6:e1fa1a2d7483 | 90 | } |
pmic | 6:e1fa1a2d7483 | 91 | |
pmic | 6:e1fa1a2d7483 | 92 | void button_rise() |
pmic | 6:e1fa1a2d7483 | 93 | { |
pmic | 6:e1fa1a2d7483 | 94 | int t_button_ms = duration_cast<milliseconds>(user_button_timer.elapsed_time()).count(); |
pmic | 6:e1fa1a2d7483 | 95 | user_button_timer.stop(); |
pmic | 8:9bb806a7f585 | 96 | if (t_button_ms > 200) { |
pmic | 6:e1fa1a2d7483 | 97 | executeMainTask = !executeMainTask; |
pmic | 8:9bb806a7f585 | 98 | } |
pmic | 6:e1fa1a2d7483 | 99 | } |