Hauptprogramm

Dependencies:   ILI9340_Driver_Lib PM2_Libary Lib_DFPlayerMini

main.cpp

Committer:
haefeman
Date:
2021-04-22
Revision:
19:9ccd591cb637
Parent:
18:39be9e19768f
Child:
20:f825e91784fe

File content as of revision 19:9ccd591cb637:

#include "mbed.h"
#include "Servo.h"
//Eigene Header einbinden

//include Zeitfunktion
#include "realtimer.h"

//include Servosteuerung
#include "servo_bewegung.h"


//LED Anzeige
//#include "Adafruit_LED_Backpack.h"




#define MID         1500
#define MIN         1000
#define MAX         2000
#define STEP          50
//Time delay between steps in milliseconds
#define TIME         100

using namespace std::chrono;

InterruptIn user_button(USER_BUTTON);
DigitalOut  led(LED1);



//I2C i2c(I2C_SDA , I2C_SCL);


bool  executeMainTask = false;
Timer user_button_timer, loop_timer;


/* declaration of custom button functions */
void button_fall();
void button_rise();

/*void setup() {
#ifndef __AVR_ATtiny85__
  Serial.begin(9600);
  Serial.println("7 Segment Backpack Test");
#endif
  matrix.begin(0x70);
}*/
//Adafruit_7segment matrix = Adafruit_7segment();

int main()
{
    set_time(1618332129);  //Zeit setzen
    
    //Laufvariablen
    int i = 0;
    Servo servo1(PA_0);
    servo1.Enable(1000,20000);
    
    user_button.fall(&button_fall);
    user_button.rise(&button_rise);
    loop_timer.start();

    while (true) {

        loop_timer.reset();
        
  /*matrix.print(10000, DEC);
  matrix.writeDisplay();
  delay(500);

  // print a hex number
  matrix.print(0xBEEF, HEX);
  matrix.writeDisplay();
  delay(500);

  // print a floating point 
  matrix.print(12.34);
  matrix.writeDisplay();
  delay(500);
  
  // print with print/println
  for (uint16_t counter = 0; counter < 9999; counter++) {
    matrix.println(counter);
    matrix.writeDisplay();
    delay(10);*/

 

        if (executeMainTask) {
            
            //Zeitfunktion
            uhrzeit(time(NULL));
            
            switch(i){
                //2 Minuten
                case 120:    i += 5;
                            //Seesaw Programm
                            ThisThread::sleep_for(5s); //Wartet 5s..
                            break;
                //5 Minuten
                case 30:    i += 5;
                            //Servo Bewegung
                            for(int j=0; j<2; j++){
                                for (int pos = 800; pos < 1200; pos += 25) {
                                    servo1.SetPosition(pos);
                                    thread_sleep_for(STEP);
                                }
                                for (int pos = 1200; pos > 800; pos -= 25) {
                                    servo1.SetPosition(pos);
                                    thread_sleep_for(STEP);
                                }
                            }
                            servo1.SetPosition(1000);
                            ThisThread::sleep_for(5s); //Wartet 5s..
                            break;
                //7 Minuten
                case 420:    i += 5;
                            //Audio Signal
                            ThisThread::sleep_for(5s); //Wartet 5s..
                            break;
                //10 Minuten
                case 600:   i = 0;
                            ThisThread::sleep_for(5s); //Wartet 5s..
                            break;
                default :   i += 5;
                            ThisThread::sleep_for(5s); //Wartet 5s..
                            break;
                            }
            
            
      /*  for (int pos = 1000; pos < 2000; pos += 25) {
          Servo1.SetPosition(pos);
          wait_ns(50);
      }
      for (int pos = 2000; pos > 1000; pos -= 25) {
          Servo1.SetPosition(pos);
          wait_ns(50);
      }*/
        //bewegung(zeit);
        
        led = !led;
        
    }}
}

void button_fall()
{
    user_button_timer.reset();
    user_button_timer.start();
}

void button_rise()
{
    int t_button_ms = duration_cast<milliseconds>(user_button_timer.elapsed_time()).count();
    user_button_timer.stop();
    if (t_button_ms > 200) {
        executeMainTask = !executeMainTask;
    }
}

/*uint16_t blinkcounter = 0;
  boolean drawDots = false;
  for (uint16_t counter = 0; counter < 9999; counter ++) {
    matrix.writeDigitNum(0, (counter / 1000), drawDots);
    matrix.writeDigitNum(1, (counter / 100) % 10, drawDots);
    matrix.drawColon(drawDots);
    matrix.writeDigitNum(3, (counter / 10) % 10, drawDots);
    matrix.writeDigitNum(4, counter % 10, drawDots);
   
    blinkcounter+=50;
    if (blinkcounter < 500) {
      drawDots = false;
    } else if (blinkcounter < 1000) {
      drawDots = true;
    } else {
      blinkcounter = 0;
    }
    matrix.writeDisplay();
    delay(10);
  }*/