Hauptprogramm

Dependencies:   ILI9340_Driver_Lib PM2_Libary Lib_DFPlayerMini

Committer:
haefeman
Date:
Thu Apr 22 15:57:47 2021 +0000
Revision:
20:f825e91784fe
Parent:
19:9ccd591cb637
Child:
21:1aaf25fc8d53
servo in own header

Who changed what in which revision?

UserRevisionLine numberNew 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 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 17:621c4212fd4e 120
ackerden 17:621c4212fd4e 121
ackerden 18:39be9e19768f 122 /* for (int pos = 1000; pos < 2000; pos += 25) {
ackerden 16:f0480e9c5039 123 Servo1.SetPosition(pos);
ackerden 16:f0480e9c5039 124 wait_ns(50);
ackerden 16:f0480e9c5039 125 }
ackerden 16:f0480e9c5039 126 for (int pos = 2000; pos > 1000; pos -= 25) {
ackerden 16:f0480e9c5039 127 Servo1.SetPosition(pos);
ackerden 16:f0480e9c5039 128 wait_ns(50);
ackerden 18:39be9e19768f 129 }*/
ackerden 18:39be9e19768f 130 //bewegung(zeit);
ackerden 16:f0480e9c5039 131
ackerden 13:096e5dc3ac23 132 led = !led;
ackerden 18:39be9e19768f 133
ackerden 18:39be9e19768f 134 }}
pmic 1:93d997d6b232 135 }
pmic 6:e1fa1a2d7483 136
pmic 6:e1fa1a2d7483 137 void button_fall()
pmic 6:e1fa1a2d7483 138 {
pmic 6:e1fa1a2d7483 139 user_button_timer.reset();
pmic 6:e1fa1a2d7483 140 user_button_timer.start();
pmic 6:e1fa1a2d7483 141 }
pmic 6:e1fa1a2d7483 142
pmic 6:e1fa1a2d7483 143 void button_rise()
pmic 6:e1fa1a2d7483 144 {
pmic 6:e1fa1a2d7483 145 int t_button_ms = duration_cast<milliseconds>(user_button_timer.elapsed_time()).count();
pmic 6:e1fa1a2d7483 146 user_button_timer.stop();
pmic 8:9bb806a7f585 147 if (t_button_ms > 200) {
pmic 6:e1fa1a2d7483 148 executeMainTask = !executeMainTask;
pmic 8:9bb806a7f585 149 }
ackerden 16:f0480e9c5039 150 }
ackerden 16:f0480e9c5039 151
ackerden 16:f0480e9c5039 152 /*uint16_t blinkcounter = 0;
ackerden 16:f0480e9c5039 153 boolean drawDots = false;
ackerden 16:f0480e9c5039 154 for (uint16_t counter = 0; counter < 9999; counter ++) {
ackerden 16:f0480e9c5039 155 matrix.writeDigitNum(0, (counter / 1000), drawDots);
ackerden 16:f0480e9c5039 156 matrix.writeDigitNum(1, (counter / 100) % 10, drawDots);
ackerden 16:f0480e9c5039 157 matrix.drawColon(drawDots);
ackerden 16:f0480e9c5039 158 matrix.writeDigitNum(3, (counter / 10) % 10, drawDots);
ackerden 16:f0480e9c5039 159 matrix.writeDigitNum(4, counter % 10, drawDots);
ackerden 16:f0480e9c5039 160
ackerden 16:f0480e9c5039 161 blinkcounter+=50;
ackerden 16:f0480e9c5039 162 if (blinkcounter < 500) {
ackerden 16:f0480e9c5039 163 drawDots = false;
ackerden 16:f0480e9c5039 164 } else if (blinkcounter < 1000) {
ackerden 16:f0480e9c5039 165 drawDots = true;
ackerden 16:f0480e9c5039 166 } else {
ackerden 16:f0480e9c5039 167 blinkcounter = 0;
ackerden 16:f0480e9c5039 168 }
ackerden 16:f0480e9c5039 169 matrix.writeDisplay();
ackerden 16:f0480e9c5039 170 delay(10);
ackerden 16:f0480e9c5039 171 }*/