Nixie clock ИН-12а

angersos
angersos аватар
Offline
Зарегистрирован: 09.06.2016

День добрый, прощу помощи у спецов. уже не знаю что поделать: собрана монтажная схема, залита программа, но часы не работают.

R1 3.3 kΩ
R2 3.3 kΩ
R3 3.3 kΩ
R4 470 kΩ
R5 470 kΩ
R6 470 kΩ
R7 15 kΩ
R8 15 kΩ
R9 15 kΩ
R10 100 kΩ
R11 100 kΩ
R12 100 kΩ
R13 2.2 kΩ
Q1 MPSA42 NPN
Q2 MPSA42 NPN
Q3 MPSA42 NPN
Q4 MPSA92 PNP
Q5 MPSA92 PNP
Q6 MPSA92 PNP

J12= PCF8563 но у меня  DS3231

J13=DHT22 его нет у меня

J10= Bluetooth RF transceiver HC-06 нет у меня

 
#include <Wire.h>
#include <Rtc_Pcf8563.h>
#include <DHT.h>

#define DHTPIN 13 
#define DHTTYPE DHT22  
DHT dht(DHTPIN, DHTTYPE);

//Library for multiplexing the Nixie clock
#include <NixieAS.h>

//int pinLayout[] = {PINA_IC1, PINB_IC1, PINC_IC1, PIND_IC1, PINA_IC2, PINB_IC2, PINC_IC2, PIND_IC2, PAIR1, PAIR2, PAIR3}; 
int pinLayout[] = {5, 3, 2, 4, 9, 7, 6, 8, 12, 11, 10};

NixieAS nix(&pinLayout[0]);
int nums[] = {1,3,3,7,0,0};
unsigned char time_raw[7];


//Variable handle for real time clock object
Rtc_Pcf8563 rtc;

int pre_sec = 0;
int cur_sec = 0;

/*For storeing time and date from user*/
/*unsigned char time_date_raw[13];
int pos = 0;
char byteRead;*/

void setup() {                
  Serial.begin(9600);
  
  rtc.initClock();
  rtc.setDate(1, 3, 3, 7, 10);
  rtc.setTime(1, 13, 37);
  
  dht.begin();
  
}

void updRtcTime(){
  rtc.getTime();
  byte ss = rtc.getSecond();
  byte mm = rtc.getMinute();
  byte hh = rtc.getHour();
  nums[0] = hh / 10;
  nums[1]  = hh % 10;
  nums[2]  = mm / 10;
  nums[3]  = mm % 10;
  nums[4]  = ss / 10;
  nums[5]  = ss % 10;
}

void setRTC(){
  int dateTime[3];
  
  //Check if 0 in front of single day/month/year/hh/mm/ss . Ex: 01 02 03
   for(int i=0; i<3; i++){
   
      if(time_raw[2*i] == '0'){
        dateTime[i] = time_raw[2*i+1]-'0';
      }else{
        //Convert char to int with - '0'
        dateTime[i] = 10*(time_raw[2*i]-'0')+(time_raw[2*i+1]-'0');
      }     
   } 
  
   //rtc.setDate(dateTime[0], 0, dateTime[1], 0, dateTime[2]);
   rtc.setTime(dateTime[0], dateTime[1], dateTime[2]);  
   
   for(int i=0; i < 30; i++){
      nums[0] = random(0, 10);
      nums[1] = random(0, 10);
      nums[2] = random(0, 10);
      nums[3] = random(0, 10);
      nums[4] = random(0, 10);
      nums[5] = random(0, 10);
      nix.showDigits(&nums[0],1);
   }
     
}

void displayTempHumid(){
 
   int temp = (int)dht.readTemperature();
   int humi = (int)dht.readHumidity();
   
   for(int i=0; i < 180; i++){
      nums[0] = humi/10;
      nums[1] = humi%10;
      nums[2] = nums[2] = 0;
      nums[3] = nums[2] = 0;
      nums[4] = temp/10;
      nums[5] = temp%10;
      nix.showDigits(&nums[0],2);
   }
  
}

void readBluetooth(){
  int pos = 0;
  char byteRead;
  //Listen for user commands
  if(Serial.available()) {
    /* read the most recent byte */
    byteRead = Serial.read();
    //Trigger and capture data when char '#' is found
    if(byteRead == '#'){
      while(pos < 7 && Serial.available() > 0){
        byteRead = Serial.read();
        time_raw[pos] = byteRead;
        pos++;
        time_raw[pos] = '\0'; //Null terminate string - indicates end of string
      }      
      //Set the time and date after recieving all data from user
      setRTC();  
     }   
  }
  
}

void loop() { 
  
   
  //Se if bluetooth instructions are available
  readBluetooth();
  
  //Update digits for nixie based on RTC IC
  updRtcTime();
  
  
  //Display temperature and humidity every 15 sec
  
  if(abs((nums[4]*10+nums[5])-pre_sec) > 30){
    displayTempHumid();
    updRtcTime();
    pre_sec = (nums[4]*10+nums[5]);
  }
  
  //Call showDigits that will display nums. Every digit will be on for 2 ms
  nix.showDigits(&nums[0],2);
  
}

 

andriano
andriano аватар
Offline
Зарегистрирован: 20.06.2015

А что именно не работает?

И может ли быть, что не работает именно из-за отсутствующих деталей?

angersos
angersos аватар
Offline
Зарегистрирован: 09.06.2016

Я даже не знаю, может программное запустить часы?

andriano
andriano аватар
Offline
Зарегистрирован: 20.06.2015

А Вы проверяли, насколько PCF8563 и  DS3231 совпадают по управлению?

Может, лучше использовать библиотеку от DS3231?

angersos
angersos аватар
Offline
Зарегистрирован: 09.06.2016

В общем так

 
#include <Wire.h>
#include <DS1307.h>
#include <DHT.h>

#define DHTPIN 13 
#define DHTTYPE DHT22  
DHT dht(DHTPIN, DHTTYPE);

//Library for multiplexing the Nixie clock
#include <NixieAS.h>

//int pinLayout[] = {PINA_IC1, PINB_IC1, PINC_IC1, PIND_IC1, PINA_IC2, PINB_IC2, PINC_IC2, PIND_IC2, PAIR1, PAIR2, PAIR3}; 
int pinLayout[] = {5, 3, 2, 4, 9, 7, 6, 8, 12, 11, 10};

NixieAS nix(&pinLayout[0]);
int nums[] = {1,3,3,7,0,0};
unsigned char time_raw[7];


//Variable handle for real time clock object
DS1307 rtc;

int pre_sec = 0;
int cur_sec = 0;

/*For storeing time and date from user*/
/*unsigned char time_date_raw[13];
int pos = 0;
char byteRead;*/

void setup() {                
  Serial.begin(9600);
  
  rtc.initClock();
  rtc.setDate(1, 3, 3, 7, 10);
  rtc.setTime(1, 13, 37);
  
  dht.begin();
  
}

void updRtcTime(){
  rtc.getTime();
  byte ss = rtc.getSecond();
  byte mm = rtc.getMinute();
  byte hh = rtc.getHour();
  nums[0] = hh / 10;
  nums[1]  = hh % 10;
  nums[2]  = mm / 10;
  nums[3]  = mm % 10;
  nums[4]  = ss / 10;
  nums[5]  = ss % 10;
}

void setRTC(){
  int dateTime[3];
  
  //Check if 0 in front of single day/month/year/hh/mm/ss . Ex: 01 02 03
   for(int i=0; i<3; i++){
   
      if(time_raw[2*i] == '0'){
        dateTime[i] = time_raw[2*i+1]-'0';
      }else{
        //Convert char to int with - '0'
        dateTime[i] = 10*(time_raw[2*i]-'0')+(time_raw[2*i+1]-'0');
      }     
   } 
  
   //rtc.setDate(dateTime[0], 0, dateTime[1], 0, dateTime[2]);
   rtc.setTime(dateTime[0], dateTime[1], dateTime[2]);  
   
   for(int i=0; i < 30; i++){
      nums[0] = random(0, 10);
      nums[1] = random(0, 10);
      nums[2] = random(0, 10);
      nums[3] = random(0, 10);
      nums[4] = random(0, 10);
      nums[5] = random(0, 10);
      nix.showDigits(&nums[0],1);
   }
     
}

void displayTempHumid(){
 
   int temp = (int)dht.readTemperature();
   int humi = (int)dht.readHumidity();
   
   for(int i=0; i < 180; i++){
      nums[0] = humi/10;
      nums[1] = humi%10;
      nums[2] = nums[2] = 0;
      nums[3] = nums[2] = 0;
      nums[4] = temp/10;
      nums[5] = temp%10;
      nix.showDigits(&nums[0],2);
   }
  
}

void readBluetooth(){
  int pos = 0;
  char byteRead;
  //Listen for user commands
  if(Serial.available()) {
    /* read the most recent byte */
    byteRead = Serial.read();
    //Trigger and capture data when char '#' is found
    if(byteRead == '#'){
      while(pos < 7 && Serial.available() > 0){
        byteRead = Serial.read();
        time_raw[pos] = byteRead;
        pos++;
        time_raw[pos] = '\0'; //Null terminate string - indicates end of string
      }      
      //Set the time and date after recieving all data from user
      setRTC();  
     }   
  }
  
}

void loop() { 
  
   
  //Se if bluetooth instructions are available
  readBluetooth();
  
  //Update digits for nixie based on RTC IC
  updRtcTime();
  
  
  //Display temperature and humidity every 15 sec
  
  if(abs((nums[4]*10+nums[5])-pre_sec) > 30){
    displayTempHumid();
    updRtcTime();
    pre_sec = (nums[4]*10+nums[5]);
  }
  
  //Call showDigits that will display nums. Every digit will be on for 2 ms
  nix.showDigits(&nums[0],2);
  
}

Выдает ошибку, но эту библиотеку уже использовал нормально.

Arduino: 1.6.9 (Windows 7), Плата:"Arduino Nano, ATmega328"

sketch_jun10a.ino.ino:22: error: no matching function for call to 'DS1307::DS1307()'

C:\Users\РђРґРјРёРЅ\Documents\Arduino\sketch_jun10a\sketch_jun10a.ino\sketch_jun10a.ino.ino\sketch_jun10a.ino.ino.ino:22:8: note: candidates are:

In file included from C:\Users\РђРґРјРёРЅ\Documents\Arduino\sketch_jun10a\sketch_jun10a.ino\sketch_jun10a.ino.ino\sketch_jun10a.ino.ino.ino:3:0:

C:\Users\Админ\Documents\Arduino\libraries\DS1307/DS1307.h:86:3: note: DS1307::DS1307(uint8_t, uint8_t)

   DS1307(uint8_t data_pin, uint8_t sclk_pin);

   ^

C:\Users\Админ\Documents\Arduino\libraries\DS1307/DS1307.h:86:3: note:   candidate expects 2 arguments, 0 provided

C:\Users\Админ\Documents\Arduino\libraries\DS1307/DS1307.h:83:7: note: constexpr DS1307::DS1307(const DS1307&)

 class DS1307

       ^

C:\Users\Админ\Documents\Arduino\libraries\DS1307/DS1307.h:83:7: note:   candidate expects 1 argument, 0 provided

C:\Users\Админ\Documents\Arduino\libraries\DS1307/DS1307.h:83:7: note: constexpr DS1307::DS1307(DS1307&&)

C:\Users\Админ\Documents\Arduino\libraries\DS1307/DS1307.h:83:7: note:   candidate expects 1 argument, 0 provided

C:\Users\РђРґРјРёРЅ\Documents\Arduino\sketch_jun10a\sketch_jun10a.ino\sketch_jun10a.ino.ino\sketch_jun10a.ino.ino.ino: In function 'void setup()':

sketch_jun10a.ino.ino:35: error: 'class DS1307' has no member named 'initClock'

sketch_jun10a.ino.ino:36: error: no matching function for call to 'DS1307::setDate(int, int, int, int, int)'

C:\Users\РђРґРјРёРЅ\Documents\Arduino\sketch_jun10a\sketch_jun10a.ino\sketch_jun10a.ino.ino\sketch_jun10a.ino.ino.ino:36:29: note: candidate is:

In file included from C:\Users\РђРґРјРёРЅ\Documents\Arduino\sketch_jun10a\sketch_jun10a.ino\sketch_jun10a.ino.ino\sketch_jun10a.ino.ino.ino:3:0:

C:\Users\Админ\Documents\Arduino\libraries\DS1307/DS1307.h:89:7: note: void DS1307::setDate(uint8_t, uint8_t, uint16_t)

  void setDate(uint8_t date, uint8_t mon, uint16_t year);

       ^

C:\Users\Админ\Documents\Arduino\libraries\DS1307/DS1307.h:89:7: note:   candidate expects 3 arguments, 5 provided

C:\Users\РђРґРјРёРЅ\Documents\Arduino\sketch_jun10a\sketch_jun10a.ino\sketch_jun10a.ino.ino\sketch_jun10a.ino.ino.ino: In function 'void updRtcTime()':

sketch_jun10a.ino.ino:45: error: 'class DS1307' has no member named 'getSecond'

sketch_jun10a.ino.ino:46: error: 'class DS1307' has no member named 'getMinute'

sketch_jun10a.ino.ino:47: error: 'class DS1307' has no member named 'getHour'

exit status 1
no matching function for call to 'DS1307::DS1307()'
 С уважением от Дмитрия.

angersos
angersos аватар
Offline
Зарегистрирован: 09.06.2016

А при библиотеке

#include <DS3231.h>

Arduino: 1.6.9 (Windows 7), Плата:"Arduino Nano, ATmega328"

sketch_jun10a.ino.ino:22: error: no matching function for call to 'DS3231::DS3231()'

C:\Users\РђРґРјРёРЅ\Documents\Arduino\sketch_jun10a\sketch_jun10a.ino\sketch_jun10a.ino.ino\sketch_jun10a.ino.ino.ino:22:8: note: candidates are:

In file included from C:\Users\РђРґРјРёРЅ\Documents\Arduino\sketch_jun10a\sketch_jun10a.ino\sketch_jun10a.ino.ino\sketch_jun10a.ino.ino.ino:3:0:

C:\Users\Админ\Documents\Arduino\libraries\DS3231/DS3231.h:80:3: note: DS3231::DS3231(uint8_t, uint8_t)

   DS3231(uint8_t data_pin, uint8_t sclk_pin);

   ^

C:\Users\Админ\Documents\Arduino\libraries\DS3231/DS3231.h:80:3: note:   candidate expects 2 arguments, 0 provided

C:\Users\Админ\Documents\Arduino\libraries\DS3231/DS3231.h:77:7: note: constexpr DS3231::DS3231(const DS3231&)

 class DS3231

       ^

C:\Users\Админ\Documents\Arduino\libraries\DS3231/DS3231.h:77:7: note:   candidate expects 1 argument, 0 provided

C:\Users\Админ\Documents\Arduino\libraries\DS3231/DS3231.h:77:7: note: constexpr DS3231::DS3231(DS3231&&)

C:\Users\Админ\Documents\Arduino\libraries\DS3231/DS3231.h:77:7: note:   candidate expects 1 argument, 0 provided

C:\Users\РђРґРјРёРЅ\Documents\Arduino\sketch_jun10a\sketch_jun10a.ino\sketch_jun10a.ino.ino\sketch_jun10a.ino.ino.ino: In function 'void setup()':

sketch_jun10a.ino.ino:35: error: 'class DS3231' has no member named 'initClock'

sketch_jun10a.ino.ino:36: error: no matching function for call to 'DS3231::setDate(int, int, int, int, int)'

C:\Users\РђРґРјРёРЅ\Documents\Arduino\sketch_jun10a\sketch_jun10a.ino\sketch_jun10a.ino.ino\sketch_jun10a.ino.ino.ino:36:29: note: candidate is:

In file included from C:\Users\РђРґРјРёРЅ\Documents\Arduino\sketch_jun10a\sketch_jun10a.ino\sketch_jun10a.ino.ino\sketch_jun10a.ino.ino.ino:3:0:

C:\Users\Админ\Documents\Arduino\libraries\DS3231/DS3231.h:84:8: note: void DS3231::setDate(uint8_t, uint8_t, uint16_t)

   void setDate(uint8_t date, uint8_t mon, uint16_t year);

        ^

C:\Users\Админ\Documents\Arduino\libraries\DS3231/DS3231.h:84:8: note:   candidate expects 3 arguments, 5 provided

C:\Users\РђРґРјРёРЅ\Documents\Arduino\sketch_jun10a\sketch_jun10a.ino\sketch_jun10a.ino.ino\sketch_jun10a.ino.ino.ino: In function 'void updRtcTime()':

sketch_jun10a.ino.ino:45: error: 'class DS3231' has no member named 'getSecond'

sketch_jun10a.ino.ino:46: error: 'class DS3231' has no member named 'getMinute'

sketch_jun10a.ino.ino:47: error: 'class DS3231' has no member named 'getHour'

exit status 1
no matching function for call to 'DS3231::DS3231()'

Этот отчёт будет иметь больше информации с
включенной опцией Файл -> Настройки ->
"Показать подробный вывод во время компиляции"
 

andriano
andriano аватар
Offline
Зарегистрирован: 20.06.2015

Сравните то, как вызывается конструктор класса в файле DS3231.h с тем, как Вы описывавете его в своей программе.

angersos
angersos аватар
Offline
Зарегистрирован: 09.06.2016

Надо 21 строку назвать rts?

andriano
andriano аватар
Offline
Зарегистрирован: 20.06.2015

Вы прочитайте сообщения об ошибках - компилятор не может понять, какой конструктор ему нужно использовать. Между собой он различает их по количеству и типу параметров. Вот и опишите rts по однму из тех шаблонов, что приведены в файле DS3231.h.

angersos
angersos аватар
Offline
Зарегистрирован: 09.06.2016

О боже как все сложно( мозги кипят...

andriano
andriano аватар
Offline
Зарегистрирован: 20.06.2015

А никто иного и не обещал.

Если беспорядочно стучать по клавишам, "Война и мир" не получится. Для отладки программы просто необдходимо внимательно читать, что Вам сообщает компилятор.

angersos
angersos аватар
Offline
Зарегистрирован: 09.06.2016

А не подскажите что имеено менять?

andriano
andriano аватар
Offline
Зарегистрирован: 20.06.2015

Я бы в первую очередь посмотрел в сторону строки 21.

angersos
angersos аватар
Offline
Зарегистрирован: 09.06.2016

Правильно?


 DS3231 rtc(A4, A5);
  
  Time  t;
  int sh; //часы
  int mn; //минуты
  int sc; //секунды

 

angersos
angersos аватар
Offline
Зарегистрирован: 09.06.2016

Не подскажите где библиот. взять и пример для теста часов взять проверить модуль?

angersos
angersos аватар
Offline
Зарегистрирован: 09.06.2016
 Ошибка на 43 строке
#include <Wire.h>
#include <DS1307.h>
#include <DHT.h>

#define DHTPIN 13 
#define DHTTYPE DHT22  
DHT dht(DHTPIN, DHTTYPE);

//Library for multiplexing the Nixie clock
#include <NixieAS.h>

//int pinLayout[] = {PINA_IC1, PINB_IC1, PINC_IC1, PIND_IC1, PINA_IC2, PINB_IC2, PINC_IC2, PIND_IC2, PAIR1, PAIR2, PAIR3}; 
int pinLayout[] = {5, 3, 2, 4, 9, 7, 6, 8, 12, 11, 10};

NixieAS nix(&pinLayout[0]);
int nums[] = {1,3,3,7,0,0};
unsigned char time_raw[7];


//Variable handle for real time clock object
DS1307 rtc(A4, A5);

int pre_sec = 0;
int cur_sec = 0;

/*For storeing time and date from user*/
/*unsigned char time_date_raw[13];
int pos = 0;
char byteRead;*/

void setup() {                
  Serial.begin(9600);
  
  rtc.setDOW(SUNDAY); 
  rtc.setTime(19, 0, 0);
  rtc.setDate(24, 07, 2016);   
  dht.begin();
  
}

void updRtcTime(){
  rtc.getTime();
  byte ss = rtc.getSecond();
  byte mm = rtc.getMinute();
  byte hh = rtc.getHour();
  nums[0] = hh / 10;
  nums[1]  = hh % 10;
  nums[2]  = mm / 10;
  nums[3]  = mm % 10;
  nums[4]  = ss / 10;
  nums[5]  = ss % 10;
}

void setRTC(){
  int dateTime[3];
  
  //Check if 0 in front of single day/month/year/hh/mm/ss . Ex: 01 02 03
   for(int i=0; i<3; i++){
   
      if(time_raw[2*i] == '0'){
        dateTime[i] = time_raw[2*i+1]-'0';
      }else{
        //Convert char to int with - '0'
        dateTime[i] = 10*(time_raw[2*i]-'0')+(time_raw[2*i+1]-'0');
      }     
   } 
  
   //rtc.setDate(dateTime[0], 0, dateTime[1], 0, dateTime[2]);
   rtc.setTime(dateTime[0], dateTime[1], dateTime[2]);  
   
   for(int i=0; i < 30; i++){
      nums[0] = random(0, 10);
      nums[1] = random(0, 10);
      nums[2] = random(0, 10);
      nums[3] = random(0, 10);
      nums[4] = random(0, 10);
      nums[5] = random(0, 10);
      nix.showDigits(&nums[0],1);
   }
     
}

void displayTempHumid(){
 
   int temp = (int)dht.readTemperature();
   int humi = (int)dht.readHumidity();
   
   for(int i=0; i < 180; i++){
      nums[0] = humi/10;
      nums[1] = humi%10;
      nums[2] = nums[2] = 0;
      nums[3] = nums[2] = 0;
      nums[4] = temp/10;
      nums[5] = temp%10;
      nix.showDigits(&nums[0],2);
   }
  
}

void readBluetooth(){
  int pos = 0;
  char byteRead;
  //Listen for user commands
  if(Serial.available()) {
    /* read the most recent byte */
    byteRead = Serial.read();
    //Trigger and capture data when char '#' is found
    if(byteRead == '#'){
      while(pos < 7 && Serial.available() > 0){
        byteRead = Serial.read();
        time_raw[pos] = byteRead;
        pos++;
        time_raw[pos] = '\0'; //Null terminate string - indicates end of string
      }      
      //Set the time and date after recieving all data from user
      setRTC();  
     }   
  }
  
}

void loop() { 
  
   
  //Se if bluetooth instructions are available
  readBluetooth();
  
  //Update digits for nixie based on RTC IC
  updRtcTime();
  
  
  //Display temperature and humidity every 15 sec
  
  if(abs((nums[4]*10+nums[5])-pre_sec) > 30){
    displayTempHumid();
    updRtcTime();
    pre_sec = (nums[4]*10+nums[5]);
  }
  
  //Call showDigits that will display nums. Every digit will be on for 2 ms
  nix.showDigits(&nums[0],2);
  
}

Arduino: 1.6.9 (Windows 7), Плата:"Arduino Nano, ATmega328"

C:\Users\РђРґРјРёРЅ\Documents\Arduino\sketch_jun10a\sketch_jun10a.ino\sketch_jun10a.ino.ino\sketch_jun10a.ino.ino.ino: In function 'void updRtcTime()':

sketch_jun10a.ino.ino:47: error: 'class DS1307' has no member named 'getSecond'

sketch_jun10a.ino.ino:48: error: 'class DS1307' has no member named 'getMinute'

sketch_jun10a.ino.ino:49: error: 'class DS1307' has no member named 'getHour'

exit status 1
'class DS1307' has no member named 'getSecond'

 

andriano
andriano аватар
Offline
Зарегистрирован: 20.06.2015

Ну та загляните в DS1307.h и посмотрите, какие методы этой библиотеки делают то же самое, что отсутствующие getSecond, getMinute и getHour.

Кроме того, Вы писали, что у Вас не 1307, а 3231. Зачем использовать библиотеку, написанную для другого железа?

angersos
angersos аватар
Offline
Зарегистрирован: 09.06.2016

Я уже не знаю, что менять. Насчет 1307 там особой разницы нет с 3231.

andriano
andriano аватар
Offline
Зарегистрирован: 20.06.2015

Вы можете написать здесь список методов (функций), имеющихся в классе 1307 (или 3231, если нет разницы)?

angersos
angersos аватар
Offline
Зарегистрирован: 09.06.2016

С примера библиот.

Adriano можно с вами связаться ?

#include <DS1307.h>

// Init the DS1307
DS1307 rtc(4, 5);

void setup()
{
  // Set the clock to run-mode
  rtc.halt(false);
  
  // Setup Serial connection
  Serial.begin(57600);

  // The following lines can be commented out to use the values already stored in the DS1307
  rtc.setDOW(SUNDAY);        // Set Day-of-Week to SUNDAY
  rtc.setTime(12, 0, 0);     // Set the time to 12:00:00 (24hr format)
  rtc.setDate(3, 10, 2010);   // Set the date to October 3th, 2010
}

void loop()
{
  // Send Day-of-Week
  Serial.print(rtc.getDOWStr());
  Serial.print(" ");
  
  // Send date
  Serial.print(rtc.getDateStr());
  Serial.print(" -- ");

  // Send time
  Serial.println(rtc.getTimeStr());
  
  // Wait one second before repeating :)
  delay (1000);
}

 

andriano
andriano аватар
Offline
Зарегистрирован: 20.06.2015

Еще раз: не надо никаких примеров. Тем более и пример нашли неподходящий: Вам нужны функции возвращающие число, а в примере используются функции, возвращающие строку.

Учитесь добывать данные из самой библиотеки. Описание класса содержится в файле DS1307.h. Найдите там его и процитируйте здесь.

angersos
angersos аватар
Offline
Зарегистрирован: 09.06.2016

Как этот файл открыть?

andriano
andriano аватар
Offline
Зарегистрирован: 20.06.2015

Приплыли...

 

 

Хотя бы Notepad'ом.

angersos
angersos аватар
Offline
Зарегистрирован: 09.06.2016
public:
		DS1307(uint8_t data_pin, uint8_t sclk_pin);
	Time	getTime();
	void	setTime(uint8_t hour, uint8_t min, uint8_t sec);
	void	setDate(uint8_t date, uint8_t mon, uint16_t year);
	void	setDOW(uint8_t dow);

	char	*getTimeStr(uint8_t format=FORMAT_LONG);
	char	*getDateStr(uint8_t slformat=FORMAT_LONG, uint8_t eformat=FORMAT_LITTLEENDIAN, char divider='.');
	char	*getDOWStr(uint8_t format=FORMAT_LONG);
	char	*getMonthStr(uint8_t format=FORMAT_LONG);

	void	halt(bool value);
	void	setOutput(bool enable);
	void	enableSQW(bool enable);
	void	setSQWRate(int rate);

	void		writeBuffer(DS1307_RAM r);
	DS1307_RAM	readBuffer();
	void		poke(uint8_t addr, uint8_t value);
	uint8_t		peek(uint8_t addr);

 

andriano
andriano аватар
Offline
Зарегистрирован: 20.06.2015

Ну вот смотрите: в Ваш скетч пытается обратиться к функциям возвращающим часы, минуты и секунды. А таковых, как мы видим, в данной библиотеке нет. Зато есть некая getTime(), которая возвращает переменную типа Time. Видимо, из этой Time можно как-то получить интересующие нас величины. Только как? Что такое Time? Ответ на этот вопрос можно найти в том же самом файле немного выше. Там должна быть описана структура (или класс - не знаю) Time. Ее бы тоже хорошо было посмотреть.

angersos
angersos аватар
Offline
Зарегистрирован: 09.06.2016
#ifndef DS1307_h
#define DS1307_h

#if defined(ARDUINO) && ARDUINO >= 100
	#include "Arduino.h"
#else
	#include "WProgram.h"
#endif

#define DS1307_ADDR_R	209
#define DS1307_ADDR_W	208

#define FORMAT_SHORT	1
#define FORMAT_LONG		2

#define FORMAT_LITTLEENDIAN	1
#define FORMAT_BIGENDIAN	2
#define FORMAT_MIDDLEENDIAN	3

#define MONDAY		1
#define TUESDAY		2
#define WEDNESDAY	3
#define THURSDAY	4
#define FRIDAY		5
#define SATURDAY	6
#define SUNDAY		7

#define SQW_RATE_1		0
#define SQW_RATE_4K		1
#define SQW_RATE_8K		2
#define SQW_RATE_32K	3

class Time
{
public:
	uint8_t		hour;
	uint8_t		min;
	uint8_t		sec;
	uint8_t		date;
	uint8_t		mon;
	uint16_t	year;
	uint8_t		dow;

		Time();
};

class DS1307_RAM
{
public:
	byte	cell[56];

		DS1307_RAM();
};

class DS1307
{
public:
		DS1307(uint8_t data_pin, uint8_t sclk_pin);
	Time	getTime();
	void	setTime(uint8_t hour, uint8_t min, uint8_t sec);
	void	setDate(uint8_t date, uint8_t mon, uint16_t year);
	void	setDOW(uint8_t dow);

	char	*getTimeStr(uint8_t format=FORMAT_LONG);
	char	*getDateStr(uint8_t slformat=FORMAT_LONG, uint8_t eformat=FORMAT_LITTLEENDIAN, char divider='.');
	char	*getDOWStr(uint8_t format=FORMAT_LONG);
	char	*getMonthStr(uint8_t format=FORMAT_LONG);

	void	halt(bool value);
	void	setOutput(bool enable);
	void	enableSQW(bool enable);
	void	setSQWRate(int rate);

	void		writeBuffer(DS1307_RAM r);
	DS1307_RAM	readBuffer();
	void		poke(uint8_t addr, uint8_t value);
	uint8_t		peek(uint8_t addr);

private:
	uint8_t _scl_pin;
	uint8_t _sda_pin;
	uint8_t _burstArray[8];

	void	_sendStart(byte addr);
	void	_sendStop();
	void	_sendAck();
	void	_sendNack();
	void	_waitForAck();
	uint8_t	_readByte();
	void	_writeByte(uint8_t value);
	void	_burstRead();
	uint8_t	_readRegister(uint8_t reg);
	void 	_writeRegister(uint8_t reg, uint8_t value);
	uint8_t	_decode(uint8_t value);
	uint8_t	_decodeH(uint8_t value);
	uint8_t	_decodeY(uint8_t value);
	uint8_t	_encode(uint8_t vaule);
};
#endif

 

andriano
andriano аватар
Offline
Зарегистрирован: 20.06.2015

Ну вот и отлично: вместо трех запросов отдельно часов, отдельно минут один раз спрашиваете getTime, после чего проводите следующие ниже манипуляции уже с его полями.

angersos
angersos аватар
Offline
Зарегистрирован: 09.06.2016

Вы меня радуете)) Еще понять как это сделать?

andriano
andriano аватар
Offline
Зарегистрирован: 20.06.2015

Для этого нужно:

1. Научиться работать с компьютером.

2. Приобрести хотя бы начальные навыки в программировании.

3. Ознакомиться с языками программирования С/С++.

Есть и более быстрый способ: обратиться в раздел "Ищу исполнителя".

angersos
angersos аватар
Offline
Зарегистрирован: 09.06.2016

Тут не навыки, я даже скажу болеше надо знать.

angersos
angersos аватар
Offline
Зарегистрирован: 09.06.2016

В общем нашел иностранный сайт с готовыми проектами, обьясните почему на лампы аноды идут 4 провода место 3?

http://www.hazardousphysics.com/main/rlbclock/RLB_Designs_Nixie_Tube_Clock_1.html

roman2712@mail.ru
Offline
Зарегистрирован: 16.01.2014

Учитывая что там 2 к155ид1, для индикации 6 цифр надо 6 / 2 = 3 анодных. Четвертый, если подключить к неонке, можно заставить мигать в такт секундам.

в коде ledPin_a_1 только назначается на выход и в дальнейшем не используется.

angersos
angersos аватар
Offline
Зарегистрирован: 09.06.2016

roman2712@mail.ru пишет:

Учитывая что там 2 к155ид1, для индикации 6 цифр надо 6 / 2 = 3 анодных. Четвертый, если подключить к неонке, можно заставить мигать в такт секундам.

в коде ledPin_a_1 только назначается на выход и в дальнейшем не используется.

Ясно.

/*
 * Program for a 6-digit, SN74141-based alarm clock;
 * coding by Robin Birtles and Chris Gerekos ( based on <a href="http://arduinix.com/Main/Code/ANX-6Tube-Clock-Crossfade.txt" rel="nofollow">http://arduinix.com/Main/Code/ANX-6Tube-Clock-Crossfade.txt</a> );
 * for RLB Designs ( <a href="http://www.rlb-designs.com/" rel="nofollow">http://www.rlb-designs.com/</a> ).
 * For Ver5.0 Driver Boards Only
 */


#include "pitches.h"
#include <EEPROM.h>
#include <Wire.h>
#include <RTClib.h>
RTC_DS1307 RTC; 

// SN74141 : Truth Table
//D C B A #
//L,L,L,L 0
//L,L,L,H 1
//L,L,H,L 2
//L,L,H,H 3
//L,H,L,L 4
//L,H,L,H 5
//L,H,H,L 6
//L,H,H,H 7
//H,L,L,L 8
//H,L,L,H 9

// SN74141 (1)
int ledPin_0_a = 2;                
int ledPin_0_b = 3;
int ledPin_0_c = 4;
int ledPin_0_d = 5;

// SN74141 (2)
int ledPin_1_a = 6;                
int ledPin_1_b = 7;
int ledPin_1_c = 8;
int ledPin_1_d = 9;

// anode pins
//int ledPin_a_1 = 10; now used for Alarm output
int ledPin_a_2 = 11;
int ledPin_a_3 = 12;
int ledPin_a_4 = 13;

// notes in the melody
int melody[] = {
  NOTE_C7, NOTE_C7, NOTE_C7, NOTE_C7, NOTE_C7 };
  
// note duration: 4 =quater note, 8 = eight note, ect.:
int noteDurations[] = {
  2, 2, 2, 2, 2 };

void setup() 
{
  Serial.begin(57600);
  Wire.begin();
  RTC.begin();
  if (! RTC.isrunning()){
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    RTC.adjust(DateTime(__DATE__, __TIME__));
  }
  
  pinMode(ledPin_0_a, OUTPUT);      
  pinMode(ledPin_0_b, OUTPUT);      
  pinMode(ledPin_0_c, OUTPUT);      
  pinMode(ledPin_0_d, OUTPUT);    
  
  pinMode(ledPin_1_a, OUTPUT);      
  pinMode(ledPin_1_b, OUTPUT);      
  pinMode(ledPin_1_c, OUTPUT);      
  pinMode(ledPin_1_d, OUTPUT);      
   
  pinMode(ledPin_a_2, OUTPUT);      
  pinMode(ledPin_a_3, OUTPUT);
  pinMode(ledPin_a_4, OUTPUT);  
 
  // NOTE: All analog pins as digital inputs with pull-up resistor activated.
  
  pinMode(A1, INPUT_PULLUP); // Mode swicth  
  pinMode(A0, INPUT_PULLUP); // Set (Press for >3sec)
  pinMode(A6, INPUT_PULLUP); // Alarm arming
  pinMode(A3, INPUT_PULLUP); // increase
  pinMode(A2, INPUT_PULLUP); // decrease
  pinMode(10, OUTPUT);       // Alarm tone will be sent there 
  
}


void SetSN74141Chips( int num2, int num1 )
{
  int a,b,c,d;
  
  // set defaults.
  a=0;b=0;c=0;d=0; // will display a zero.
  
  // Load the a,b,c,d.. to send to the SN74141 IC (1)
  switch( num1 )
  {
    case 0: a=0;b=0;c=0;d=0;break;
    case 1: a=1;b=0;c=0;d=0;break;
    case 2: a=0;b=1;c=0;d=0;break;
    case 3: a=1;b=1;c=0;d=0;break;
    case 4: a=0;b=0;c=1;d=0;break;
    case 5: a=1;b=0;c=1;d=0;break;
    case 6: a=0;b=1;c=1;d=0;break;
    case 7: a=1;b=1;c=1;d=0;break;
    case 8: a=0;b=0;c=0;d=1;break;
    case 9: a=1;b=0;c=0;d=1;break;
    default: a=1;b=1;c=1;d=1;
    break;
  }  
  
  // Write to output pins.
  digitalWrite(ledPin_0_d, d);
  digitalWrite(ledPin_0_c, c);
  digitalWrite(ledPin_0_b, b);
  digitalWrite(ledPin_0_a, a);

  // Load the a,b,c,d.. to send to the SN74141 IC (2)
  switch( num2 )
  {
    case 0: a=0;b=0;c=0;d=0;break;
    case 1: a=1;b=0;c=0;d=0;break;
    case 2: a=0;b=1;c=0;d=0;break;
    case 3: a=1;b=1;c=0;d=0;break;
    case 4: a=0;b=0;c=1;d=0;break;
    case 5: a=1;b=0;c=1;d=0;break;
    case 6: a=0;b=1;c=1;d=0;break;
    case 7: a=1;b=1;c=1;d=0;break;
    case 8: a=0;b=0;c=0;d=1;break;
    case 9: a=1;b=0;c=0;d=1;break;
    default: a=1;b=1;c=1;d=1;
    break;
  }
  
  // Write to output pins
  digitalWrite(ledPin_1_d, d);
  digitalWrite(ledPin_1_c, c);
  digitalWrite(ledPin_1_b, b);
  digitalWrite(ledPin_1_a, a);
}


float fadeMax = 5.0f;
float fadeStep = 1.0f;
int NumberArray[6]={0,0,0,0,0,0};
int currNumberArray[6]={0,0,0,0,0,0};
float NumberArrayFadeInValue[6]={0.0f,0.0f,0.0f,0.0f,0.0f,0.0f};
float NumberArrayFadeOutValue[6]={8.0f,8.0f,8.0f,8.0f,8.0f,8.0f};


void DisplayFadeNumberString()
{
 
  // Anode channel 1 - numerals 0,3
  SetSN74141Chips(currNumberArray[0],currNumberArray[3]);   
  digitalWrite(ledPin_a_2, HIGH);   
  delay(NumberArrayFadeOutValue[0]);
  SetSN74141Chips(NumberArray[0],NumberArray[3]);   
  delay(NumberArrayFadeInValue[0]);
  digitalWrite(ledPin_a_2, LOW);
  
  // Anode channel 2 - numerals 1,4
  SetSN74141Chips(currNumberArray[1],currNumberArray[4]);   
  digitalWrite(ledPin_a_3, HIGH);   
  delay(NumberArrayFadeOutValue[1]);
  SetSN74141Chips(NumberArray[1],NumberArray[4]);   
  delay(NumberArrayFadeInValue[1]);
  digitalWrite(ledPin_a_3, LOW);
  
   // Anode channel 3 - numerals 2,5
  SetSN74141Chips(currNumberArray[2],currNumberArray[5]);   
  digitalWrite(ledPin_a_4, HIGH);   
  delay(NumberArrayFadeOutValue[2]);
  SetSN74141Chips(NumberArray[2],NumberArray[5]);   
  delay(NumberArrayFadeInValue[2]);
  digitalWrite(ledPin_a_4, LOW);
  
  // Loop thru and update all the arrays, and fades.
  for( int i = 0 ; i < 6 ; i ++ )
  {
    if( NumberArray[i] != currNumberArray[i] )
    {
      NumberArrayFadeInValue[i] += fadeStep;
      NumberArrayFadeOutValue[i] -= fadeStep;
  
      if( NumberArrayFadeInValue[i] >= fadeMax )
      {
        NumberArrayFadeInValue[i] = 0.0f;
        NumberArrayFadeOutValue[i] = fadeMax;
        currNumberArray[i] = NumberArray[i];
      }
    }
  }  
}

//Read the EEPROM just at switch-on.
int ClockHourSet = word(EEPROM.read(1), EEPROM.read(0));  //Reconstruction the integer form the two bytes saved on the EEPROM.
int ClockMinSet = word(EEPROM.read(3), EEPROM.read(2));   
int ClockSecSet = word(EEPROM.read(5), EEPROM.read(4));   
int ClockDaySet = word(EEPROM.read(7), EEPROM.read(6));  
int ClockMonthSet = word(EEPROM.read(9), EEPROM.read(8));  
int ClockYearSet = word(EEPROM.read(11), EEPROM.read(10));
int AlmHours = word(EEPROM.read(13), EEPROM.read(12));
int AlmMins = word(EEPROM.read(15), EEPROM.read(14));

byte Mode = 1;  //1: time, 2: date, 3: alarm
byte ModeButtonPressed = false;
byte Set = 1;   //1: left, 2: middle, 3: right
long SetTimer = 0;
byte SETMODE = false;
byte SETMODEentered = false;
byte SetButtonPressed = false;
byte IncreaseButtonPressed = false;
byte DecreaseButtonPressed = false;
byte AlmButtonPressed = false;
int nixState = HIGH;
int toneState = LOW;
long previousTimeBlink = 0;
long previousTimeTone= 0;
byte AlmArmed=false;  // Used as flag as well as indicator on the tube themselves (0 or 1).
byte AlmPlaying=false;

void loop(){
  // Get milliseconds.
  unsigned long runTime = millis();  

// MODE SELECTION ///////////////////////////////////
/////////////////////////////////////////////////////  
  byte ModeInput = digitalRead(A1);
  if(ModeInput==0)  ModeButtonPressed = true;
  
  if (Mode==1 && ModeButtonPressed==true && ModeInput==1)
  {
    Mode = 2;    //Switching from Time to Date mode
    ModeButtonPressed = false;
  }
  if (Mode==2 && ModeButtonPressed==true && ModeInput==1)
  {
    Mode = 3;    //Switching from Date to Alarm mode
    ModeButtonPressed = false;
  }
  if (Mode==3 && ModeButtonPressed==true && ModeInput==1)
  {
    Mode = 1;    //Switching from Alarm to Time mode
    ModeButtonPressed = false;
  }

// SETTING //////////////////////////////////////////
///////////////////////////////////////////////////// 
  byte SetInput = digitalRead(A0);
  if(SetInput==0)  SetButtonPressed = true;
  while(SetInput==0){
    SetTimer++;
    delay(10);
    SetInput = digitalRead(A0);
  } 
  
  if(SetTimer>=70){
    if(SETMODE==false)  SETMODE=true;  //A long press will either enter or exit the setting mode option.
    else SETMODE=false;
  }
  SetTimer=0;  //Reinitializing.
  
  if(SETMODE==true){
    SETMODEentered=true;
    if (Set==1 && SetButtonPressed==true && SetInput==1)
    {
      Set = 2;    //Switching from left to middle pair available for setting.
      SetButtonPressed = false;
    }
    if (Set==2 && SetButtonPressed==true && SetInput==1)
    {
      Set = 3;    //Switching from middle to right pair available for setting.
      SetButtonPressed = false;
    }
    if (Set==3 && SetButtonPressed==true && SetInput==1)
    {
      Set = 1;    //Switching from right to left pair available for setting.
      SetButtonPressed = false;
    }
 
    //Now we set the selected the pair of tube, let's modify its value:  
    int IncreaseInput = digitalRead(A3);
    int DecreaseInput = digitalRead(A2);
  
    if(DecreaseInput==0)    DecreaseButtonPressed = true;
    if(IncreaseInput==0)    IncreaseButtonPressed = true;
    
    if(DecreaseButtonPressed==true && DecreaseInput==1)
    {
      if(Set==1){
        if(Mode==1)  ClockHourSet--;
        if(Mode==2)  ClockDaySet--;
        if(Mode==3)  AlmHours--;
      }
      if(Set==2){
        if(Mode==1)  ClockMinSet--;
        if(Mode==2)  ClockMonthSet--;
        if(Mode==3)  AlmMins--;
      }
      if(Set==3){
        if(Mode==1)  ClockSecSet--;
        if(Mode==2)  ClockYearSet--;
      }
      DecreaseButtonPressed = false;
    }
    if(IncreaseButtonPressed==true && IncreaseInput==1)
    {
      if(Set==1){
        if(Mode==1)  ClockHourSet++;
        if(Mode==2)  ClockDaySet++;
        if(Mode==3)  AlmHours++;
      }
      if(Set==2){
        if(Mode==1)  ClockMinSet++;
        if(Mode==2)  ClockMonthSet++;
        if(Mode==3)  AlmMins++;
      }
      if(Set==3){
        if(Mode==1)  ClockSecSet++;
        if(Mode==2)  ClockYearSet++;
      }
      IncreaseButtonPressed = false;
    }
  }
  
  //Saving to EEPROM after exiting the SETMODE
  if(SETMODE==false && SETMODEentered==true){
    SETMODEentered=false;
    
    byte lowCHS = lowByte(ClockHourSet);    //Split the 2-bytes integer into the respecting "high" and "low" parts in order to save them on the EEPROM.
    byte highCHS = highByte(ClockHourSet);
    byte lowCMS = lowByte(ClockMinSet);
    byte highCMS = highByte(ClockMinSet);
    byte lowCSS = lowByte(ClockSecSet);
    byte highCSS = highByte(ClockSecSet);
    byte lowCDS = lowByte(ClockDaySet);
    byte highCDS = highByte(ClockDaySet);
    byte lowCOS = lowByte(ClockMonthSet);
    byte highCOS = highByte(ClockMonthSet);
    byte lowCYS = lowByte(ClockYearSet);
    byte highCYS = highByte(ClockYearSet);
    byte lowAH = lowByte(AlmHours);
    byte highAH = highByte(AlmHours);
    byte lowAM = lowByte(AlmMins);
    byte highAM = highByte(AlmMins);
    
    EEPROM.write(0, lowCHS);  EEPROM.write(1, highCHS); //Saving
    EEPROM.write(2, lowCMS);  EEPROM.write(3, highCMS);
    EEPROM.write(4, lowCSS);  EEPROM.write(5, highCSS);
    EEPROM.write(6, lowCDS);  EEPROM.write(7, highCDS);
    EEPROM.write(8, lowCOS);  EEPROM.write(9, highCOS);
    EEPROM.write(10, lowCYS);  EEPROM.write(11, highCYS);
    EEPROM.write(12, lowAH);  EEPROM.write(13, highAH);
    EEPROM.write(14, lowAM);  EEPROM.write(15, highAM);
  }
 

// ALARM ARMING /////////////////////////////////////
/////////////////////////////////////////////////////
  if(Mode==3 && AlmPlaying==false){
    int AlmInput = analogRead(A6);
    if(AlmInput==0)  AlmButtonPressed = true;
    
    if(AlmButtonPressed==true && AlmInput>250){
      if(AlmArmed==true)  AlmArmed=false;
      else  AlmArmed=true;
      AlmButtonPressed = false;
    }
  }
  
  
// TIME CALCULATION /////////////////////////////////
/////////////////////////////////////////////////////

  DateTime now = RTC.now();

  unsigned long time = now.unixtime() - 1401000000; 
  time += (long) ClockSecSet + 60* (long) ClockMinSet + 3600* (long) ClockHourSet + 86400* (long) ClockDaySet;    //time in seconds, based on offset

  // Convert time to days,hours,mins,seconds
  long days  = time / 86400;    time -= days  * 86400; 
  long hours = time / 3600;   time -= hours * 3600; 
  long minutes  = time / 60;    time -= minutes  * 60; 
  long seconds  = time; 

  // Get the high and low order values for hours,min,seconds. 
  byte lowerHours = hours % 10;
  byte upperHours = hours - lowerHours;
  byte lowerMins = minutes % 10;
  byte upperMins = minutes - lowerMins;
  byte lowerSeconds = seconds % 10;
  byte upperSeconds = seconds - lowerSeconds;
  if( upperSeconds >= 10 )   upperSeconds = upperSeconds / 10;
  if( upperMins >= 10 )      upperMins = upperMins / 10;
  if( upperHours >= 10 )     upperHours = upperHours / 10;

// DATE CALCULATION /////////////////////////////////
/////////////////////////////////////////////////////

  int Day = days;
  int Month = ClockMonthSet;
  int Year = abs(ClockYearSet%100);

    //Defining years incrementation.
  if(Month>=13){
   Year++;
   Month=Month-12;
  }
  if(Month<=0){
   Year--;
   Month=Month+12;
  }

  //Number of days in a month:
  byte February;
  if(Year%4==0) February=29;
  else February=28;
  byte MonthArray[13] = {0,31,February,31,30,31,30,31,31,30,31,30,31};  //we'll skip the first entry, so we can use the array's index directly.

  //Defining Month incrementation.
  for(byte i=1;i<13;i++){
    if(Month==i){
      if(Day>MonthArray[i]){  //If "Day" exceeds the number of days in the present month, it is resetted to 1 and we step into the next month.
        Day -= MonthArray[i];
        Month++;
      }
      if(Day<1){  //Similarly if "Day" is to become 0.
        if(i-1==0) i=13;  //Before January comes December.
        Day += MonthArray[i-1];
        Month--;
      }
    }
  }

  // Splitting date. 
  byte lowerYears = Year % 10;
  byte upperYears = Year - lowerYears;
  byte lowerMonths = Month % 10;
  byte upperMonths = Month - lowerMonths;
  byte lowerDays = Day % 10;
  byte upperDays = Day - lowerDays;
  if( upperDays >= 10 ) upperDays = upperDays / 10;
  if( upperMonths >= 10 ) upperMonths = upperMonths / 10; 
  if( upperYears >= 10 ) upperYears = upperYears / 10;

// ALM RULES /////////////////////////////////
////////////////////////////////////////////// 
  if(AlmHours>23)  AlmHours=AlmHours-24;  //After 23:00 comes 00:00
  if(AlmHours<0)  AlmHours=AlmHours+23;   //vice-versa
  if(AlmMins>59)  AlmMins=AlmMins-60;   //same thing
  if(AlmMins<0)  AlmMins=AlmMins+59;
  
   // Splitting.    
  byte lowerAlmHours = AlmHours % 10;
  byte upperAlmHours = AlmHours - lowerAlmHours;
  byte lowerAlmMins = AlmMins % 10;
  byte upperAlmMins = AlmMins - lowerAlmMins;
  if( upperAlmMins >= 10 )      upperAlmMins = upperAlmMins / 10;
  if( upperAlmHours >= 10 )     upperAlmHours = upperAlmHours / 10;
  
  //Alm actions:
  if(AlmArmed==true){
    if(upperAlmHours==upperHours && lowerAlmHours==lowerHours && upperAlmMins==upperMins && lowerAlmMins==lowerMins && upperSeconds==0 && lowerSeconds==0){
      AlmPlaying = true;  //Alarm rings when the time matches the pre-entered alarm values.
    }
  }
  
  if(AlmPlaying==true){
    if(runTime-previousTimeTone > 2000){    //Play an intermitten (1s period) tune.
      previousTimeTone = runTime;
      if(toneState == HIGH){
        for (int thisNote = 0; thisNote < 5; thisNote++) {
    int noteDuration = 1000/noteDurations[thisNote];
     tone(10, melody[thisNote], noteDuration);
      int pauseBetweenNotes = noteDuration * 1.30;
     delay(pauseBetweenNotes);
        toneState=LOW;
      }
      }
      else{
        noTone(10);
        toneState=HIGH;
      }
    }
    if(digitalRead(A0)==LOW || digitalRead(A1)==LOW || digitalRead(A2)==LOW || digitalRead(A3)==LOW)  AlmPlaying=false;  //Press anything to stop it.
  }
  else  noTone(10);
  
  
// SHOWTIME /////////////////////////////////////////
///////////////////////////////////////////////////// 
// Fill in the Number array used to display on the tubes following the Mode.
  if(Mode==1){
    if(SETMODE==true){
      if(Set==1){
        if(runTime-previousTimeBlink > 500){  //Blinking these digits while in setmode.
          previousTimeBlink = runTime;
          if(nixState == LOW){
            NumberArray[5] = 11;  //Turning this pair off.
            NumberArray[1] = 11;
            nixState = HIGH;
          }
          else{
            NumberArray[5] = upperHours;  //Turning this pair on again.
            NumberArray[1] = lowerHours;
            nixState = LOW;
          }
        }
        NumberArray[3] = upperMins;    //Makes sure no pair stays off even if left in that state in the previous set mode.
        NumberArray[2] = lowerMins;
        NumberArray[4] = upperSeconds;
        NumberArray[0] = lowerSeconds;
      }
      if(Set==2){
        if(runTime-previousTimeBlink > 500){  //Blinking these digits while in setmode.
          previousTimeBlink = runTime;
          if(nixState == LOW){
            NumberArray[3] = 11;
            NumberArray[2] = 11;
            nixState = HIGH;
          }
          else{
            NumberArray[3] = upperMins;
            NumberArray[2] = lowerMins;
            nixState = LOW;
          }
        }
        NumberArray[5] = upperHours;
        NumberArray[1] = lowerHours;
        NumberArray[4] = upperSeconds;
        NumberArray[0] = lowerSeconds;
      }
      if(Set==3){
        if(runTime-previousTimeBlink > 500){  //Blinking these digits while in setmode.
          previousTimeBlink = runTime;
          if(nixState == LOW){
            NumberArray[4] = 11;
            NumberArray[0] = 11;
            nixState = HIGH;
          }
          else{
            NumberArray[4] = upperSeconds;
            NumberArray[0] = lowerSeconds;
            nixState = LOW;
          }
        }
        NumberArray[5] = upperHours;
        NumberArray[1] = lowerHours;
        NumberArray[3] = upperMins;
        NumberArray[2] = lowerMins;
      }
    }
    else{  //Fill the digits normally.
      NumberArray[5] = upperHours;
      NumberArray[1] = lowerHours;
      NumberArray[3] = upperMins;
      NumberArray[2] = lowerMins;
      NumberArray[4] = upperSeconds;
      NumberArray[0] = lowerSeconds;
    }

     DisplayFadeNumberString();// Display time.

      if((lowerMins==5)&&upperSeconds==0&&lowerSeconds==1)//lighting all the numbers every 10min to prevent cathode poisining.
      {
        for(int j=-1; j<11; j++){//alternating to make it more beautiful. the -1 and 11 value will turn the digits off to mark a short pause.
         NumberArray[5] = j; 
         NumberArray[1] = 9-j;
         NumberArray[3] = j;
         NumberArray[2] = 9-j;
         NumberArray[4] = j;
         NumberArray[0] = 9-j;
         int k = 0;
         while(k<10){
           DisplayFadeNumberString();// Clean each nixie digits for 2 seconds.
           k++;
           delay(1);
         }
        }
      }
      if(lowerMins==3 && upperSeconds==0 && lowerSeconds==1){ //Display date only on every (03,13,23,33) mins.
        NumberArray[5] = upperDays;
        NumberArray[1] = lowerDays;
        NumberArray[3] = upperMonths;
        NumberArray[2] = lowerMonths;
        NumberArray[4] = upperYears;
        NumberArray[0] = lowerYears;
        int k = 0;
        while(k<550){          // Display date for 10 seconds (50 = 1sec).
          DisplayFadeNumberString(); // Display date.
          k++;
          delay(1);
        }
      }
  }
  
  if(Mode==2){
    if(SETMODE==true){
      if(Set==1){
        if(runTime-previousTimeBlink > 500){  //Blinking these digits while in setmode.
          previousTimeBlink = runTime;
          if(nixState == LOW){
            NumberArray[5] = 11;  //Turning this pair off.
            NumberArray[1] = 11;
            nixState = HIGH;
          }
          else{
            NumberArray[5] = upperDays;
            NumberArray[1] = lowerDays;
            nixState = LOW;
          }
        }
        NumberArray[3] = upperMonths;
        NumberArray[2] = lowerMonths;
        NumberArray[4] = upperYears;
        NumberArray[0] = lowerYears;
      }
      if(Set==2){
        if(runTime-previousTimeBlink > 500){  //Blinking these digits while in setmode.
          previousTimeBlink = runTime;
          if(nixState == LOW){
            NumberArray[3] = 11;
            NumberArray[2] = 11;
            nixState = HIGH;
          }
          else{
            NumberArray[3] = upperMonths;
            NumberArray[2] = lowerMonths;
            nixState = LOW;
          }
        }
        NumberArray[5] = upperDays;
        NumberArray[1] = lowerDays;
        NumberArray[4] = upperYears;
        NumberArray[0] = lowerYears;
      }
      if(Set==3){
        if(runTime-previousTimeBlink > 500){  //Blinking these digits while in setmode.
          previousTimeBlink = runTime;
          if(nixState == LOW){
            NumberArray[4] = 11;
            NumberArray[0] = 11;
            nixState = HIGH;
          }
          else{
            NumberArray[4] = upperYears;
            NumberArray[0] = lowerYears;
            nixState = LOW;
          }
        }
        NumberArray[5] = upperDays;
        NumberArray[1] = lowerDays;
        NumberArray[3] = upperMonths;
        NumberArray[2] = lowerMonths;
      }
    }
    else{  //Fill the digits normally.
     NumberArray[5] = upperDays;
     NumberArray[1] = lowerDays;
     NumberArray[3] = upperMonths;
     NumberArray[2] = lowerMonths;
     NumberArray[4] = upperYears;
     NumberArray[0] = lowerYears;
    }

     DisplayFadeNumberString();  // Display date.
  }
  
  if(Mode==3){
    if(SETMODE==true){
      if(Set==1){
        if(runTime-previousTimeBlink > 500){  //Blinking these digits while in setmode.
          previousTimeBlink = runTime;
          if(nixState == LOW){
            NumberArray[5] = 11;  //Turning this pair off.
            NumberArray[1] = 11;
            nixState = HIGH;
          }
          else{
            NumberArray[5] = upperAlmHours;
            NumberArray[1] = lowerAlmHours;
            nixState = LOW;
          }
        }
        NumberArray[3] = upperAlmMins;
        NumberArray[2] = lowerAlmMins;
        NumberArray[0] = AlmArmed;  //1: armed, 0: not armed
      }
      if(Set==2){
        if(runTime-previousTimeBlink > 500){  //Blinking these digits while in setmode.
          previousTimeBlink = runTime;
          if(nixState == LOW){
            NumberArray[3] = 11;
            NumberArray[2] = 11;
            nixState = HIGH;
          }
          else{
            NumberArray[3] = upperAlmMins;
            NumberArray[2] = lowerAlmMins;
            nixState = LOW;
          }
        }
        NumberArray[5] = upperAlmHours;
        NumberArray[1] = lowerAlmHours;
        NumberArray[0] = AlmArmed;
      }
    if(Set==3)  Set=1;  //Dirty fix to convert a 3-cycle into a 2-cycle.
    }
    else{ //Fill the digits normally.
     NumberArray[5] = upperAlmHours;
     NumberArray[1] = lowerAlmHours;
     NumberArray[3] = upperAlmMins;
     NumberArray[2] = lowerAlmMins;
     NumberArray[0] = AlmArmed;
    }
     NumberArray[4] = 11;     //Eleven will turn off the tube
     DisplayFadeNumberString();   // Display alarm.
  }
 
}

 

angersos
angersos аватар
Offline
Зарегистрирован: 09.06.2016

У меня к вам вопрос, с цифрового сигнала D11 у меня напряжение 1в разве не должно 5 в?