Hauptprogramm

Dependencies:   ILI9340_Driver_Lib PM2_Libary Lib_DFPlayerMini

Committer:
ackerden
Date:
Wed Apr 21 13:48:47 2021 +0000
Revision:
16:f0480e9c5039
Parent:
15:babdd038715a
Child:
17:621c4212fd4e

        

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 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 16:f0480e9c5039 97 for (int pos = 1000; pos < 2000; pos += 25) {
ackerden 16:f0480e9c5039 98 Servo1.SetPosition(pos);
ackerden 16:f0480e9c5039 99 wait_ns(50);
ackerden 16:f0480e9c5039 100 }
ackerden 16:f0480e9c5039 101 for (int pos = 2000; pos > 1000; pos -= 25) {
ackerden 16:f0480e9c5039 102 Servo1.SetPosition(pos);
ackerden 16:f0480e9c5039 103 wait_ns(50);
ackerden 16:f0480e9c5039 104 }
ackerden 16:f0480e9c5039 105 bewegung(zeit);
ackerden 16:f0480e9c5039 106
ackerden 13:096e5dc3ac23 107
ackerden 13:096e5dc3ac23 108 //Zeitfunktion
ackerden 13:096e5dc3ac23 109 uhrzeit(time(NULL));
ackerden 14:153f377f4030 110
ackerden 14:153f377f4030 111
ackerden 14:153f377f4030 112 //Zeitfunktionen
ackerden 14:153f377f4030 113 if (i != 360){
ackerden 14:153f377f4030 114 ThisThread::sleep_for(5s); //Wartet 5s..
ackerden 14:153f377f4030 115 printf("%d\n", i);
ackerden 14:153f377f4030 116 }
ackerden 14:153f377f4030 117 else{
ackerden 14:153f377f4030 118 i=0;
ackerden 14:153f377f4030 119 }
ackerden 14:153f377f4030 120 i += 5;
pmic 6:e1fa1a2d7483 121
ackerden 13:096e5dc3ac23 122 led = !led;
pmic 9:f10b974d01e0 123
pmic 1:93d997d6b232 124 } else {
pmic 6:e1fa1a2d7483 125
ackerden 13:096e5dc3ac23 126
pmic 6:e1fa1a2d7483 127 led = 0;
pmic 1:93d997d6b232 128 }
pmic 6:e1fa1a2d7483 129
ackerden 13:096e5dc3ac23 130
pmic 1:93d997d6b232 131 }
pmic 1:93d997d6b232 132 }
pmic 6:e1fa1a2d7483 133
pmic 6:e1fa1a2d7483 134 void button_fall()
pmic 6:e1fa1a2d7483 135 {
pmic 6:e1fa1a2d7483 136 user_button_timer.reset();
pmic 6:e1fa1a2d7483 137 user_button_timer.start();
pmic 6:e1fa1a2d7483 138 }
pmic 6:e1fa1a2d7483 139
pmic 6:e1fa1a2d7483 140 void button_rise()
pmic 6:e1fa1a2d7483 141 {
pmic 6:e1fa1a2d7483 142 int t_button_ms = duration_cast<milliseconds>(user_button_timer.elapsed_time()).count();
pmic 6:e1fa1a2d7483 143 user_button_timer.stop();
pmic 8:9bb806a7f585 144 if (t_button_ms > 200) {
pmic 6:e1fa1a2d7483 145 executeMainTask = !executeMainTask;
pmic 8:9bb806a7f585 146 }
ackerden 16:f0480e9c5039 147 }
ackerden 16:f0480e9c5039 148
ackerden 16:f0480e9c5039 149 /*uint16_t blinkcounter = 0;
ackerden 16:f0480e9c5039 150 boolean drawDots = false;
ackerden 16:f0480e9c5039 151 for (uint16_t counter = 0; counter < 9999; counter ++) {
ackerden 16:f0480e9c5039 152 matrix.writeDigitNum(0, (counter / 1000), drawDots);
ackerden 16:f0480e9c5039 153 matrix.writeDigitNum(1, (counter / 100) % 10, drawDots);
ackerden 16:f0480e9c5039 154 matrix.drawColon(drawDots);
ackerden 16:f0480e9c5039 155 matrix.writeDigitNum(3, (counter / 10) % 10, drawDots);
ackerden 16:f0480e9c5039 156 matrix.writeDigitNum(4, counter % 10, drawDots);
ackerden 16:f0480e9c5039 157
ackerden 16:f0480e9c5039 158 blinkcounter+=50;
ackerden 16:f0480e9c5039 159 if (blinkcounter < 500) {
ackerden 16:f0480e9c5039 160 drawDots = false;
ackerden 16:f0480e9c5039 161 } else if (blinkcounter < 1000) {
ackerden 16:f0480e9c5039 162 drawDots = true;
ackerden 16:f0480e9c5039 163 } else {
ackerden 16:f0480e9c5039 164 blinkcounter = 0;
ackerden 16:f0480e9c5039 165 }
ackerden 16:f0480e9c5039 166 matrix.writeDisplay();
ackerden 16:f0480e9c5039 167 delay(10);
ackerden 16:f0480e9c5039 168 }*/