/* Library examples for TM1638. Copyright (C) 2011 Ricardo Batista This program is free software: you can redistribute it and/or modify it under the terms of the version 3 GNU General Public License as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include #include "RTClock.h" //RTClock rrt (RTCSEL_LSE); // initialise //uint32 tt; #define NO_MODULES 1 #define BOARD_LED_PIN PB1 #define spea PA1 // define a regular module and a inverted module // datathinks PB12 - clockthinks PB13- Strobethinks PB14 TM1638 module(PB12, PB13, PB14); TM1638* modules[NO_MODULES] = { &module, }; byte modes[NO_MODULES]; unsigned long startTime; unsigned long runningSecs; long allfcount = micros(); long startt = 2400; long maintime = millis(); int zeit1=0; int zeit2=0; int ka=0; int county =0; int leds1[8] = {0,2,4,6,8}; int frequ=0; int fcount=0; // int seconds, hours, minutes; //clock::::::::::::::::::::::::::::::::::::::::::::::::::::::::: int globAlmCnt = 0; int globOvCnt = 0; int globSecCnt = 0; int specAlmCnt = 0; int lastGlobAlmCnt = -1; int lastSpecAlmCnt = -1; int blinkt=0; int blinkc=0; String cach = ""; void rtc_sec_intr() { if (rtc_is_second()) globSecCnt++; } void rtc_ovf_intr() { if (rtc_is_overflow()) globOvCnt++; } void rtc_glob_alm_intr() { if (rtc_is_alarm()) globAlmCnt++; } void rtc_spec_alm_intr() { if (rtc_is_alarm()) specAlmCnt++; } //clock::::::::::::::::::::::::::::::::::::::::::::::::::::::::: int testy= 123; void setup() { cach += ".."; startTime = millis(); pinMode(BOARD_LED_PIN, OUTPUT); // delay(5000); Serial.println("begin RTC blink"); //delay(1000); rtc_init(RTCSEL_LSI); rtc_set_prescaler_load(0x7fff); // rtc_set_count(0); rtc_attach_interrupt(RTC_SECONDS_INTERRUPT, rtc_sec_intr); rtc_attach_interrupt(RTC_OVERFLOW_INTERRUPT, rtc_ovf_intr); // expected every 128000 seconds rtc_attach_interrupt(RTC_ALARM_GLOBAL_INTERRUPT, rtc_glob_alm_intr); rtc_attach_interrupt(RTC_ALARM_SPECIFIC_INTERRUPT, rtc_spec_alm_intr); for (int i = 0; i < NO_MODULES; i++) { module.setupDisplay(true, 8); modes[i] = 0; } } void update(TM1638* module, byte* mode) { byte buttons = module->getButtons(); unsigned long runningSecs =startt- ( (millis() - startTime) / 1000); // button pressed - change mode if (buttons != 0) { *mode = buttons >> 1; module->clearDisplay(); } rtc_get_count(); rtc_get_divider(); if (buttons ==2) {startt ++;} if (buttons ==4) {startt --;} if ((((runningSecs/60)/60)%60) <=9){ cach+="0";} cach +=((runningSecs/60)/60)%60; cach += "-"; if (((runningSecs/60)%60) <=9){ cach+="0";} cach +=(runningSecs/60)%60; cach += "-"; if ((runningSecs%60) <=9){ cach+="0";} cach +=runningSecs%60; module->setDisplayToString("001"); cach =""; blinkc++; blinkt++; if (runningSecs<=1){ } } void loop() { zeitreise(); for (int i = 0; i < NO_MODULES; i++) { update(modules[i], &modes[i]); } /* int i,n; Serial.print("Time + interrupt counts: "); Serial.print(rtc_get_count()); Serial.print("."); Serial.print(rtc_get_divider()); Serial.print(" ("); Serial.print(globSecCnt); Serial.print(", "); Serial.print(globOvCnt); Serial.print(", "); Serial.print(globAlmCnt); Serial.print(", "); Serial.print(specAlmCnt); Serial.println(")"); delay(1000); digitalWrite(BOARD_LED_PIN, 1); if ((lastSpecAlmCnt != specAlmCnt) || (lastGlobAlmCnt != globAlmCnt)){ lastGlobAlmCnt = globAlmCnt; lastSpecAlmCnt = specAlmCnt; Serial.println(" -- alarm -- "); for (i=0;i<3;i++) { digitalWrite(BOARD_LED_PIN, 0); delay(100); digitalWrite(BOARD_LED_PIN, 1); delay(100);} n = rtc_get_count() + 5; rtc_set_alarm(n); } delay(1000); digitalWrite(BOARD_LED_PIN, 0); */ } void zeitreise(void){ while ((millis()- maintime) >= 91) { if (ka==0){zeit2++; } if (ka==1){zeit2--; } zeit1++; if (frequ >=1) { frequ-=8;} if (zeit2 >=12&& ka==0) {ka=1; frequ=110;} if (zeit2 <=0&& ka==1) {ka=0; frequ=90;} maintime = millis(); } }