Hauptprogramm

Dependencies:   ILI9340_Driver_Lib PM2_Libary Lib_DFPlayerMini

main.cpp

Committer:
ackerden
Date:
2021-04-23
Revision:
21:1aaf25fc8d53
Parent:
20:f825e91784fe
Child:
24:02223fec319a

File content as of revision 21:1aaf25fc8d53:

#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;
    
    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 20:
                case 10: {   i += 5;
                            bewegung();
                            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;
                            }
        
        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);
  }*/