Hauptprogramm
Dependencies: ILI9340_Driver_Lib PM2_Libary Lib_DFPlayerMini
main.cpp@17:621c4212fd4e, 2021-04-21 (annotated)
- Committer:
- ackerden
- Date:
- Wed Apr 21 14:09:31 2021 +0000
- Revision:
- 17:621c4212fd4e
- Parent:
- 16:f0480e9c5039
- Child:
- 18:39be9e19768f
switch;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pmic | 1:93d997d6b232 | 1 | #include "mbed.h" |
ackerden | 16:f0480e9c5039 | 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 | 15:babdd038715a | 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 |
pmic | 6:e1fa1a2d7483 | 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 | 16:f0480e9c5039 | 54 | //myservo.period_ms(20); |
ackerden | 16:f0480e9c5039 | 55 | //myservo.pulsewidth_us(MID); //NB in microseconds |
ackerden | 15:babdd038715a | 56 | |
ackerden | 13:096e5dc3ac23 | 57 | set_time(1618332129); //Zeit setzen |
ackerden | 16:f0480e9c5039 | 58 | |
ackerden | 16:f0480e9c5039 | 59 | //Laufvariablen |
ackerden | 14:153f377f4030 | 60 | int i = 0; |
ackerden | 16:f0480e9c5039 | 61 | int zeit = 30; |
ackerden | 16:f0480e9c5039 | 62 | Servo Servo1(PA_0); |
ackerden | 16:f0480e9c5039 | 63 | Servo1.Enable(1500,20000); |
ackerden | 14:153f377f4030 | 64 | |
pmic | 6:e1fa1a2d7483 | 65 | user_button.fall(&button_fall); |
pmic | 6:e1fa1a2d7483 | 66 | user_button.rise(&button_rise); |
pmic | 6:e1fa1a2d7483 | 67 | loop_timer.start(); |
pmic | 6:e1fa1a2d7483 | 68 | |
pmic | 1:93d997d6b232 | 69 | while (true) { |
pmic | 6:e1fa1a2d7483 | 70 | |
pmic | 6:e1fa1a2d7483 | 71 | loop_timer.reset(); |
ackerden | 12:dfa3591affef | 72 | |
ackerden | 16:f0480e9c5039 | 73 | /*matrix.print(10000, DEC); |
ackerden | 16:f0480e9c5039 | 74 | matrix.writeDisplay(); |
ackerden | 16:f0480e9c5039 | 75 | delay(500); |
ackerden | 16:f0480e9c5039 | 76 | |
ackerden | 16:f0480e9c5039 | 77 | // print a hex number |
ackerden | 16:f0480e9c5039 | 78 | matrix.print(0xBEEF, HEX); |
ackerden | 16:f0480e9c5039 | 79 | matrix.writeDisplay(); |
ackerden | 16:f0480e9c5039 | 80 | delay(500); |
ackerden | 16:f0480e9c5039 | 81 | |
ackerden | 16:f0480e9c5039 | 82 | // print a floating point |
ackerden | 16:f0480e9c5039 | 83 | matrix.print(12.34); |
ackerden | 16:f0480e9c5039 | 84 | matrix.writeDisplay(); |
ackerden | 16:f0480e9c5039 | 85 | delay(500); |
ackerden | 16:f0480e9c5039 | 86 | |
ackerden | 16:f0480e9c5039 | 87 | // print with print/println |
ackerden | 16:f0480e9c5039 | 88 | for (uint16_t counter = 0; counter < 9999; counter++) { |
ackerden | 16:f0480e9c5039 | 89 | matrix.println(counter); |
ackerden | 16:f0480e9c5039 | 90 | matrix.writeDisplay(); |
ackerden | 16:f0480e9c5039 | 91 | delay(10);*/ |
pmic | 6:e1fa1a2d7483 | 92 | |
ackerden | 12:dfa3591affef | 93 | |
pmic | 6:e1fa1a2d7483 | 94 | |
pmic | 6:e1fa1a2d7483 | 95 | if (executeMainTask) { |
ackerden | 16:f0480e9c5039 | 96 | |
ackerden | 17:621c4212fd4e | 97 | //Zeitfunktion |
ackerden | 17:621c4212fd4e | 98 | uhrzeit(time(NULL)); |
ackerden | 17:621c4212fd4e | 99 | |
ackerden | 17:621c4212fd4e | 100 | switch(i){ |
ackerden | 17:621c4212fd4e | 101 | //2 Minuten |
ackerden | 17:621c4212fd4e | 102 | case 24: i += 5; |
ackerden | 17:621c4212fd4e | 103 | //Seesaw Programm |
ackerden | 17:621c4212fd4e | 104 | ThisThread::sleep_for(5s); //Wartet 5s.. |
ackerden | 17:621c4212fd4e | 105 | break; |
ackerden | 17:621c4212fd4e | 106 | //5 Minuten |
ackerden | 17:621c4212fd4e | 107 | case 60: i += 5; |
ackerden | 17:621c4212fd4e | 108 | //Servo Bewegung |
ackerden | 17:621c4212fd4e | 109 | ThisThread::sleep_for(5s); //Wartet 5s.. |
ackerden | 17:621c4212fd4e | 110 | break; |
ackerden | 17:621c4212fd4e | 111 | //7 Minuten |
ackerden | 17:621c4212fd4e | 112 | case 84: i += 5; |
ackerden | 17:621c4212fd4e | 113 | //Audio Signal |
ackerden | 17:621c4212fd4e | 114 | ThisThread::sleep_for(5s); //Wartet 5s.. |
ackerden | 17:621c4212fd4e | 115 | break; |
ackerden | 17:621c4212fd4e | 116 | //10 Minuten |
ackerden | 17:621c4212fd4e | 117 | case 120: i = 0; |
ackerden | 17:621c4212fd4e | 118 | break; |
ackerden | 17:621c4212fd4e | 119 | ThisThread::sleep_for(5s); //Wartet 5s.. |
ackerden | 17:621c4212fd4e | 120 | default : i += 5; |
ackerden | 17:621c4212fd4e | 121 | ThisThread::sleep_for(5s); //Wartet 5s.. |
ackerden | 17:621c4212fd4e | 122 | break; |
ackerden | 17:621c4212fd4e | 123 | |
ackerden | 17:621c4212fd4e | 124 | |
ackerden | 16:f0480e9c5039 | 125 | for (int pos = 1000; pos < 2000; pos += 25) { |
ackerden | 16:f0480e9c5039 | 126 | Servo1.SetPosition(pos); |
ackerden | 16:f0480e9c5039 | 127 | wait_ns(50); |
ackerden | 16:f0480e9c5039 | 128 | } |
ackerden | 16:f0480e9c5039 | 129 | for (int pos = 2000; pos > 1000; pos -= 25) { |
ackerden | 16:f0480e9c5039 | 130 | Servo1.SetPosition(pos); |
ackerden | 16:f0480e9c5039 | 131 | wait_ns(50); |
ackerden | 16:f0480e9c5039 | 132 | } |
ackerden | 16:f0480e9c5039 | 133 | bewegung(zeit); |
ackerden | 16:f0480e9c5039 | 134 | |
ackerden | 13:096e5dc3ac23 | 135 | led = !led; |
pmic | 1:93d997d6b232 | 136 | } else { |
ackerden | 17:621c4212fd4e | 137 | led = 0; } |
pmic | 1:93d997d6b232 | 138 | } |
pmic | 1:93d997d6b232 | 139 | } |
pmic | 6:e1fa1a2d7483 | 140 | |
pmic | 6:e1fa1a2d7483 | 141 | void button_fall() |
pmic | 6:e1fa1a2d7483 | 142 | { |
pmic | 6:e1fa1a2d7483 | 143 | user_button_timer.reset(); |
pmic | 6:e1fa1a2d7483 | 144 | user_button_timer.start(); |
pmic | 6:e1fa1a2d7483 | 145 | } |
pmic | 6:e1fa1a2d7483 | 146 | |
pmic | 6:e1fa1a2d7483 | 147 | void button_rise() |
pmic | 6:e1fa1a2d7483 | 148 | { |
pmic | 6:e1fa1a2d7483 | 149 | int t_button_ms = duration_cast<milliseconds>(user_button_timer.elapsed_time()).count(); |
pmic | 6:e1fa1a2d7483 | 150 | user_button_timer.stop(); |
pmic | 8:9bb806a7f585 | 151 | if (t_button_ms > 200) { |
pmic | 6:e1fa1a2d7483 | 152 | executeMainTask = !executeMainTask; |
pmic | 8:9bb806a7f585 | 153 | } |
ackerden | 16:f0480e9c5039 | 154 | } |
ackerden | 16:f0480e9c5039 | 155 | |
ackerden | 16:f0480e9c5039 | 156 | /*uint16_t blinkcounter = 0; |
ackerden | 16:f0480e9c5039 | 157 | boolean drawDots = false; |
ackerden | 16:f0480e9c5039 | 158 | for (uint16_t counter = 0; counter < 9999; counter ++) { |
ackerden | 16:f0480e9c5039 | 159 | matrix.writeDigitNum(0, (counter / 1000), drawDots); |
ackerden | 16:f0480e9c5039 | 160 | matrix.writeDigitNum(1, (counter / 100) % 10, drawDots); |
ackerden | 16:f0480e9c5039 | 161 | matrix.drawColon(drawDots); |
ackerden | 16:f0480e9c5039 | 162 | matrix.writeDigitNum(3, (counter / 10) % 10, drawDots); |
ackerden | 16:f0480e9c5039 | 163 | matrix.writeDigitNum(4, counter % 10, drawDots); |
ackerden | 16:f0480e9c5039 | 164 | |
ackerden | 16:f0480e9c5039 | 165 | blinkcounter+=50; |
ackerden | 16:f0480e9c5039 | 166 | if (blinkcounter < 500) { |
ackerden | 16:f0480e9c5039 | 167 | drawDots = false; |
ackerden | 16:f0480e9c5039 | 168 | } else if (blinkcounter < 1000) { |
ackerden | 16:f0480e9c5039 | 169 | drawDots = true; |
ackerden | 16:f0480e9c5039 | 170 | } else { |
ackerden | 16:f0480e9c5039 | 171 | blinkcounter = 0; |
ackerden | 16:f0480e9c5039 | 172 | } |
ackerden | 16:f0480e9c5039 | 173 | matrix.writeDisplay(); |
ackerden | 16:f0480e9c5039 | 174 | delay(10); |
ackerden | 16:f0480e9c5039 | 175 | }*/ |