Hauptprogramm
Dependencies: ILI9340_Driver_Lib PM2_Libary Lib_DFPlayerMini
main.cpp@21:1aaf25fc8d53, 2021-04-23 (annotated)
- Committer:
- ackerden
- Date:
- Fri Apr 23 15:33:41 2021 +0000
- Revision:
- 21:1aaf25fc8d53
- Parent:
- 20:f825e91784fe
- Child:
- 24:02223fec319a
Adafruit _Seesaw Library eingebunden noch nicht angepasst;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pmic | 1:93d997d6b232 | 1 | #include "mbed.h" |
ackerden | 21:1aaf25fc8d53 | 2 | //#include "Servo.h" |
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 | 16:f0480e9c5039 | 13 | //#include "Adafruit_LED_Backpack.h" |
ackerden | 16:f0480e9c5039 | 14 | |
ackerden | 16:f0480e9c5039 | 15 | |
ackerden | 16:f0480e9c5039 | 16 | |
ackerden | 21:1aaf25fc8d53 | 17 | /* |
ackerden | 16:f0480e9c5039 | 18 | #define MID 1500 |
ackerden | 16:f0480e9c5039 | 19 | #define MIN 1000 |
ackerden | 16:f0480e9c5039 | 20 | #define MAX 2000 |
ackerden | 16:f0480e9c5039 | 21 | #define STEP 50 |
ackerden | 16:f0480e9c5039 | 22 | //Time delay between steps in milliseconds |
ackerden | 16:f0480e9c5039 | 23 | #define TIME 100 |
ackerden | 21:1aaf25fc8d53 | 24 | */ |
pmic | 6:e1fa1a2d7483 | 25 | using namespace std::chrono; |
pmic | 6:e1fa1a2d7483 | 26 | |
pmic | 8:9bb806a7f585 | 27 | InterruptIn user_button(USER_BUTTON); |
pmic | 8:9bb806a7f585 | 28 | DigitalOut led(LED1); |
pmic | 6:e1fa1a2d7483 | 29 | |
ackerden | 12:dfa3591affef | 30 | |
ackerden | 16:f0480e9c5039 | 31 | |
ackerden | 16:f0480e9c5039 | 32 | //I2C i2c(I2C_SDA , I2C_SCL); |
ackerden | 16:f0480e9c5039 | 33 | |
ackerden | 16:f0480e9c5039 | 34 | |
pmic | 6:e1fa1a2d7483 | 35 | bool executeMainTask = false; |
pmic | 6:e1fa1a2d7483 | 36 | Timer user_button_timer, loop_timer; |
ackerden | 13:096e5dc3ac23 | 37 | |
pmic | 6:e1fa1a2d7483 | 38 | |
pmic | 6:e1fa1a2d7483 | 39 | /* declaration of custom button functions */ |
pmic | 6:e1fa1a2d7483 | 40 | void button_fall(); |
pmic | 6:e1fa1a2d7483 | 41 | void button_rise(); |
pmic | 6:e1fa1a2d7483 | 42 | |
ackerden | 16:f0480e9c5039 | 43 | /*void setup() { |
ackerden | 16:f0480e9c5039 | 44 | #ifndef __AVR_ATtiny85__ |
ackerden | 16:f0480e9c5039 | 45 | Serial.begin(9600); |
ackerden | 16:f0480e9c5039 | 46 | Serial.println("7 Segment Backpack Test"); |
ackerden | 16:f0480e9c5039 | 47 | #endif |
ackerden | 16:f0480e9c5039 | 48 | matrix.begin(0x70); |
ackerden | 16:f0480e9c5039 | 49 | }*/ |
ackerden | 16:f0480e9c5039 | 50 | //Adafruit_7segment matrix = Adafruit_7segment(); |
ackerden | 15:babdd038715a | 51 | |
pmic | 1:93d997d6b232 | 52 | int main() |
pmic | 9:f10b974d01e0 | 53 | { |
ackerden | 13:096e5dc3ac23 | 54 | set_time(1618332129); //Zeit setzen |
ackerden | 16:f0480e9c5039 | 55 | |
ackerden | 16:f0480e9c5039 | 56 | //Laufvariablen |
ackerden | 14:153f377f4030 | 57 | int i = 0; |
ackerden | 14:153f377f4030 | 58 | |
pmic | 6:e1fa1a2d7483 | 59 | user_button.fall(&button_fall); |
pmic | 6:e1fa1a2d7483 | 60 | user_button.rise(&button_rise); |
pmic | 6:e1fa1a2d7483 | 61 | loop_timer.start(); |
pmic | 6:e1fa1a2d7483 | 62 | |
pmic | 1:93d997d6b232 | 63 | while (true) { |
pmic | 6:e1fa1a2d7483 | 64 | |
pmic | 6:e1fa1a2d7483 | 65 | loop_timer.reset(); |
ackerden | 12:dfa3591affef | 66 | |
ackerden | 16:f0480e9c5039 | 67 | /*matrix.print(10000, DEC); |
ackerden | 16:f0480e9c5039 | 68 | matrix.writeDisplay(); |
ackerden | 16:f0480e9c5039 | 69 | delay(500); |
ackerden | 16:f0480e9c5039 | 70 | |
ackerden | 16:f0480e9c5039 | 71 | // print a hex number |
ackerden | 16:f0480e9c5039 | 72 | matrix.print(0xBEEF, HEX); |
ackerden | 16:f0480e9c5039 | 73 | matrix.writeDisplay(); |
ackerden | 16:f0480e9c5039 | 74 | delay(500); |
ackerden | 16:f0480e9c5039 | 75 | |
ackerden | 16:f0480e9c5039 | 76 | // print a floating point |
ackerden | 16:f0480e9c5039 | 77 | matrix.print(12.34); |
ackerden | 16:f0480e9c5039 | 78 | matrix.writeDisplay(); |
ackerden | 16:f0480e9c5039 | 79 | delay(500); |
ackerden | 16:f0480e9c5039 | 80 | |
ackerden | 16:f0480e9c5039 | 81 | // print with print/println |
ackerden | 16:f0480e9c5039 | 82 | for (uint16_t counter = 0; counter < 9999; counter++) { |
ackerden | 16:f0480e9c5039 | 83 | matrix.println(counter); |
ackerden | 16:f0480e9c5039 | 84 | matrix.writeDisplay(); |
ackerden | 16:f0480e9c5039 | 85 | delay(10);*/ |
pmic | 6:e1fa1a2d7483 | 86 | |
ackerden | 12:dfa3591affef | 87 | |
pmic | 6:e1fa1a2d7483 | 88 | |
pmic | 6:e1fa1a2d7483 | 89 | if (executeMainTask) { |
ackerden | 16:f0480e9c5039 | 90 | |
ackerden | 17:621c4212fd4e | 91 | //Zeitfunktion |
ackerden | 17:621c4212fd4e | 92 | uhrzeit(time(NULL)); |
ackerden | 17:621c4212fd4e | 93 | |
ackerden | 17:621c4212fd4e | 94 | switch(i){ |
ackerden | 17:621c4212fd4e | 95 | //2 Minuten |
ackerden | 18:39be9e19768f | 96 | case 120: i += 5; |
ackerden | 17:621c4212fd4e | 97 | //Seesaw Programm |
ackerden | 17:621c4212fd4e | 98 | ThisThread::sleep_for(5s); //Wartet 5s.. |
ackerden | 17:621c4212fd4e | 99 | break; |
ackerden | 17:621c4212fd4e | 100 | //5 Minuten |
haefeman | 20:f825e91784fe | 101 | case 20: |
haefeman | 20:f825e91784fe | 102 | case 10: { i += 5; |
haefeman | 20:f825e91784fe | 103 | bewegung(); |
ackerden | 17:621c4212fd4e | 104 | ThisThread::sleep_for(5s); //Wartet 5s.. |
ackerden | 17:621c4212fd4e | 105 | break; |
haefeman | 20:f825e91784fe | 106 | } |
ackerden | 17:621c4212fd4e | 107 | //7 Minuten |
ackerden | 18:39be9e19768f | 108 | case 420: i += 5; |
ackerden | 17:621c4212fd4e | 109 | //Audio Signal |
ackerden | 17:621c4212fd4e | 110 | ThisThread::sleep_for(5s); //Wartet 5s.. |
ackerden | 17:621c4212fd4e | 111 | break; |
ackerden | 17:621c4212fd4e | 112 | //10 Minuten |
ackerden | 18:39be9e19768f | 113 | case 600: i = 0; |
haefeman | 19:9ccd591cb637 | 114 | ThisThread::sleep_for(5s); //Wartet 5s.. |
ackerden | 17:621c4212fd4e | 115 | break; |
ackerden | 17:621c4212fd4e | 116 | default : i += 5; |
ackerden | 17:621c4212fd4e | 117 | ThisThread::sleep_for(5s); //Wartet 5s.. |
ackerden | 17:621c4212fd4e | 118 | break; |
ackerden | 18:39be9e19768f | 119 | } |
ackerden | 16:f0480e9c5039 | 120 | |
ackerden | 13:096e5dc3ac23 | 121 | led = !led; |
ackerden | 18:39be9e19768f | 122 | |
ackerden | 18:39be9e19768f | 123 | }} |
pmic | 1:93d997d6b232 | 124 | } |
pmic | 6:e1fa1a2d7483 | 125 | |
pmic | 6:e1fa1a2d7483 | 126 | void button_fall() |
pmic | 6:e1fa1a2d7483 | 127 | { |
pmic | 6:e1fa1a2d7483 | 128 | user_button_timer.reset(); |
pmic | 6:e1fa1a2d7483 | 129 | user_button_timer.start(); |
pmic | 6:e1fa1a2d7483 | 130 | } |
pmic | 6:e1fa1a2d7483 | 131 | |
pmic | 6:e1fa1a2d7483 | 132 | void button_rise() |
pmic | 6:e1fa1a2d7483 | 133 | { |
pmic | 6:e1fa1a2d7483 | 134 | int t_button_ms = duration_cast<milliseconds>(user_button_timer.elapsed_time()).count(); |
pmic | 6:e1fa1a2d7483 | 135 | user_button_timer.stop(); |
pmic | 8:9bb806a7f585 | 136 | if (t_button_ms > 200) { |
pmic | 6:e1fa1a2d7483 | 137 | executeMainTask = !executeMainTask; |
pmic | 8:9bb806a7f585 | 138 | } |
ackerden | 16:f0480e9c5039 | 139 | } |
ackerden | 16:f0480e9c5039 | 140 | |
ackerden | 16:f0480e9c5039 | 141 | /*uint16_t blinkcounter = 0; |
ackerden | 16:f0480e9c5039 | 142 | boolean drawDots = false; |
ackerden | 16:f0480e9c5039 | 143 | for (uint16_t counter = 0; counter < 9999; counter ++) { |
ackerden | 16:f0480e9c5039 | 144 | matrix.writeDigitNum(0, (counter / 1000), drawDots); |
ackerden | 16:f0480e9c5039 | 145 | matrix.writeDigitNum(1, (counter / 100) % 10, drawDots); |
ackerden | 16:f0480e9c5039 | 146 | matrix.drawColon(drawDots); |
ackerden | 16:f0480e9c5039 | 147 | matrix.writeDigitNum(3, (counter / 10) % 10, drawDots); |
ackerden | 16:f0480e9c5039 | 148 | matrix.writeDigitNum(4, counter % 10, drawDots); |
ackerden | 16:f0480e9c5039 | 149 | |
ackerden | 16:f0480e9c5039 | 150 | blinkcounter+=50; |
ackerden | 16:f0480e9c5039 | 151 | if (blinkcounter < 500) { |
ackerden | 16:f0480e9c5039 | 152 | drawDots = false; |
ackerden | 16:f0480e9c5039 | 153 | } else if (blinkcounter < 1000) { |
ackerden | 16:f0480e9c5039 | 154 | drawDots = true; |
ackerden | 16:f0480e9c5039 | 155 | } else { |
ackerden | 16:f0480e9c5039 | 156 | blinkcounter = 0; |
ackerden | 16:f0480e9c5039 | 157 | } |
ackerden | 16:f0480e9c5039 | 158 | matrix.writeDisplay(); |
ackerden | 16:f0480e9c5039 | 159 | delay(10); |
ackerden | 16:f0480e9c5039 | 160 | }*/ |