// RTC clock mini & big ver 17
// mini トランジスタアレイ使わない
// Big トランジスタアレイ使う
// SEG[] の書き換え 始めから7つめまで miniは反転 BIGはそのまま 最後の一つ右端はともに0
// miniとBigで表示のオンOFF逆転
// ライブラリはインターネット上からget
#include <Wire.h>
#include <TimeLib.h>
#include <EEPROM.h>
#include <DS1307RTC.h>
// Include the libraries we need
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into port 2 on the Arduino //port2をport13に変更
#define ONE_WIRE_BUS 7 // #define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
float TempValue;
#define MINI true //miniは true にする bigは false にする
#define DEBUG 0
// PORTB |= _BV(1) ; ポートBの1ビット目に’1’を出力
// PORTB &= ~_BV(1);ポートBの1ビット目に’0’を出力
#define setpb1( addr, bit) addr |= _BV(bit) // setpb1(PORTB,PB3) なら PB3を1、他はそのまま
#define setpb0( addr, bit) addr &= ~_BV(bit) // setpb0(PORTC,PC5) なら PC5を0、他はそのまま
#define LED1 0
#define LED2 1
#define LED3 4
#define LED4 5
#define LEDDP 6
#define DOT3 8 // 変更した 20210712
#define MODEBT 2
#define SETBT 3
const byte DOWNBT = 15;
const byte UPBT = 16;
const byte ONOFFBT = 14;
const byte OFST = 14;
#define SUND 17
// aruduino の ピン 13,12,11,10,9 は7セグメント表示器の C,D,E,F,G に割り当てている
// PB5 から PB1
// PB6,PB7 を利用。DDRB や PORTB を利用、Arduinoでは、クロックで利用しているport。
// 7セグメント表示器のB,Aに PB6,PB7を割り当てている。
// PB0(Arduinoの8)は7セグメント右下のDotに割り当て
// つまりPORTBは 7セグメントプラスDot に割り当て
// PD7(arduinoの7) は 温度用onwire通信として利用。
// PD6(arduinoの6) は 複数のDOTのcommonとして利用(電源側)。
// PB0(arduinoの8) は 文字右下のdot表示の出力用として利用(GND側)。PD6とともに。
// arduino ピン7は 温度計の onewire 通信で使用
// 7の端子は #define ONE_WIRE_BUS 7 で、既に定義済み
// Arduinoの18,19はSCL,SDAとして,RTCとの通信に利用
#define LEDON 1
#define LEDOFF 0
volatile byte btchk[3] = {false, false, false}; //false=0 信号なかった true=1 信号あった
volatile byte btcon[3] = {false, false, false}; //LOW=0 押されている true=1 押されていない、pullup抵抗実施
//volatile byte btLong = false; //ボタン長押し されていないがfalse されているがtrue
volatile byte btLong[3] = {false, false, false}; //ボタン長押し されていないがfalse されているがtrue 20210709
volatile byte setbtFg = false; //false=0押されていない、信号ない true=1 押されている、信号あり
volatile byte modebtFg = false; //false=0押されていない、信号ない true=1 押されている、信号あり
int dispCnt = 0; //mode 0 0 、メイン表示のとき一時的表示に使うカウンタ
// byte stt = LOW; //真ん中の2つのドット、表示する HIGH=1 表示しない LOW=0
byte upDisp = HIGH; //うえの2つの数字表示止めるか否か HIGH:表示 LOW:表示停止
volatile byte mainmode = 0;
volatile byte submode[4] = {0, 0, 0, 0};
int setHour = 0; //RTCに時間設定するとき
int setMin = 0;
int setYear = 0;
int setMonth = 0;
int setDay = 0;
int setScnd = 0;
volatile unsigned long nowTimeM;
volatile unsigned long prevTimeM;
volatile unsigned long nowTimeS;
volatile unsigned long prevTimeS;
const unsigned long timeChat = 20;
const int timeChk = 20;
const int timesModeSet = 160;
volatile byte conM = HIGH;
volatile byte conS = HIGH;
//int conChk;
int yr = 0;
int mh = 0;
int dy = 0;
int h = 0;
int m = 0;
int h1 = h / 10;
int sd = 0;
volatile byte dspF = 2; // 年=0 月・日=1 時・分=2 分・秒=3 の表示 アラーム時刻=4 も表示
// 11~ 調節モード 11調節値 12調節間隔秒 13調節間隔分 14調節間隔時 15調節間隔日
byte tmpfg = HIGH; //時間表示10以下 0 表示する=HIGH しない=LOW
byte DispOnFlg =true;
int alH = 0;
int alM = 0;
int alFg = false;
int snzFg = false;
int alStopTm;
int alPassTm;
int snzI = 0;
int snzIMax = 20; //もとは30 20190923
byte snzDspFg = true;
byte snzDspIdx = 2;
byte k[9] = {false, false, false, false, false, false, false, false, false};
byte adjTS = 0;
byte adjTM = 0;
byte adjTH = 0;
byte adjTD = 0;
int adjVlue = 0;
byte adjVV = 0;
byte adjVF = 0;
int adjRmS = 0;
int adjRmM = 0;
int adjRmH = 0;
int adjRmD = 0;
int adjTgS = 0;
int adjTgM = 0;
int adjTgH = 0;
int adjCntD = 0;
int prvD;
byte adjSetF = false;
byte adjF = false;
byte dp1 = 0;
byte dp2 = 0;
byte dp3 = 0;
byte dp4 = 0;
int dispH = 0; //表示用
int dispM = 0;
int dispD = 0;
int dispIx = 0;
int nowH; //タイマー用 スタート時刻
int nowM;
int nowS;
int tgH; //終わる時刻
int tgM;
int tgS;
int tmrH = 0; //設定した時間と分と秒
int tmrM = 0;
int tmrS = 0;
int rmH = 0; //残り時間
int rmM = 0;
int rmS = 0;
int rmH_3 = 0;
int rmM_3 = 0;
int rmS_3 = 0;
int krH = 0; //計算に使う
int krM = 0;
int krS = 0;
int krH_3 = 0; //計算に使う
int krM_3 = 0;
int krS_3 = 0;
int rptBb3 = 0; //リピート 鳴らす時 使用
int rptBb4 = 0;
int mmMmode; // タイマーチェック時 mainmode記憶
int mmSmode; // submode記憶
int tmOnFg = false; // タイマーOnのフラグ
int tmEnd = false; // タイマー鳴らした
int rptTmFg = false; // リピートタイマーのフラグ
int rptDpIx = 0; // リピートタイマー時の真ん中の点のちかちか表示用
int swSH = 0; //ストップウォッチ用 始まり時刻
int swSM = 0;
int swSS = 0;
int swNH = 0; //そのときまでの経過時間
int swNM = 0;
int swNS = 0;
int swOfH = 0; //一時ストップ後の足す時間
int swOfM = 0;
int swOfS = 0;
int oeSH = 0; //長時間表示そのまま、何かのエラー その時表示を時計に戻す用 始まり時刻
int oeSM = 0;
int oeSS = 0;
int oeOfH = 0; //時計表示に戻す時刻
int oeOfM = 0;
int oeOfS = 0;
byte mMmainmode; //volatile 長時間表示そのまま、何かのエラー対策 記憶mainmode
byte mMsubmode; //volatile 同上 記憶submode
// int clcY,clcY1,clcY2 = 0;
// int clcM,clcM1,clcM2 = 0;
// int clcD clcD1,clcD2 = 0;
int clcD = 0;
int clcH, clcH1, clcH2 = 0 ;
int clcM, clcM1, clcM2 = 0;
int clcS, clcS1, clcS2 = 0;
int bbflg = 0; //どのbeebeeを鳴らすかのフラグ
const byte dispChKagi = 10;
const byte dispChMinus = 11;
const byte dispChPlus1 = 12;
const byte dispChPlus2 = 13;
const byte dispChScnd = 14;
const byte dispChMin = 15;
const byte dispChHour = 16;
const byte dispChDay = 17;
const byte dispChEql = 18;
const byte dispChNone = 19;
const byte dispChA = 20;
const byte dispChb = 21;
const byte dispChC = 22;
#if MINI
// for mini
byte Seg[] = {B00000011, B10011111, B00100101, B00001101, B10011001, B01001001, B01000001, B00011111, B00000001, B00001001,
B00111111, B11111101, B10011101, B11110001, B11011001, B11010101, B10010001, B10000101, B11101101, B11111111,
B00010001, B11000001, B01100011,
};
// 0 1 2 3 4 5 6 7 8 9 「 - + + s m H d = A b C
byte DpAdd[] = {B11111111,B11111110};
byte DpDisp[] = {B00111111, B01111111, B10111111, B11111111};
byte AlLed[] = {B11111111,B11110111};
byte OpLed[] = {B11111111,B11101111};
// 0は表示、1は非表示 0はGND,commonは+ で電流流れる
#define OPRT &
#else
// for BIG
byte Seg[] = {B11111100,B01100000,B11011010,B11110010,B01100110,B10110110,B10111110,B11100000,B11111110,B11110110,
B11000000,B00000010,B01100010,B00001110,B00100110,B00101010,B01101110,B01111010,B00010010,B00000000,
B11101110,B00111110,B10011100,
};
// 0 1 2 3 4 5 6 7 8 9 「 - + + s m H d = A b C
byte DpAdd[] = {B00000000,B00000001};
byte DpDisp[] = {B11000000, B10000000, B01000000, B00000000};
byte AlLed[] = {B00000000,B00001000};
byte OpLed[] = {B00000000,B00010000};
#define OPRT |
// 1は表示、0は非表示
#endif
byte DpD = DpDisp[3];
byte AlL = AlLed[0];
byte OpL = OpLed[0];
byte DpDAO;
// DpDAO = DpD OPRT AlL OPRT OpL をして portBに出力、LEDDP をon
byte DpA =DpAdd[0];
// int DpA = DpAdd[0]; 変更 20210713 //ONOFFBT長押しの時表示するため PORTB に加える
// const char *monthName[12] = {
// "Jan", "Feb", "Mar", "Apr", "May", "Jun",
// "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
// };
int DS1307_ADDRESS = 0x68;
tmElements_t tm;
void setup() {
bool parse = false;
bool config = false;
if (! RTC.isRunning()) {
// get the date and time the compiler was run
if (getDate(__DATE__) && getTime(__TIME__)) {
parse = true;
// and configure the RTC with this info
if (RTC.write(tm)) {
config = true;
}
}
}
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
pinMode(LEDDP, OUTPUT);
pinMode(MODEBT, INPUT_PULLUP);
pinMode(SETBT, INPUT_PULLUP);
pinMode(DOWNBT, INPUT_PULLUP);
pinMode(UPBT, INPUT_PULLUP);
pinMode(ONOFFBT, INPUT_PULLUP);
// pinMode(ALLED, OUTPUT);
// pinMode(OPLED, OUTPUT); //DDRBで設定するからいらないか?
DDRB = B11111111; //portBの0~7 (pin8~13)とPB6,PB7を設定 1はoutput PB6,PB7はもとはクロック。
PORTB = B11111111; //portB(pin8~13)PB6,PB7をHIGHに設定。commonで+を与え、それぞれがGNDと接続すると電流流れる。なので、HIGHにし、電流が流れないようにする
pinMode(SUND, OUTPUT);
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
//digitalWrite(ALLED, LEDOFF);
AlL=AlLed[1];
//digitalWrite(OPLED, LEDOFF);
OpL=OpLed[1];
//dispD = 0; 定義部分で設定済み
DpD =DpDisp[dispD];
DpDAO=DpD OPRT AlL OPRT OpL;
PORTB = DpDAO;
sensors.requestTemperatures();
TempValue=(sensors.getTempCByIndex(0)) * 10;
digitalWrite(LEDDP,HIGH);
digitalWrite(SUND, LOW);
delay(2000);
tone(SUND, 600, 1000);
sensors.requestTemperatures();
TempValue=(sensors.getTempCByIndex(0)) * 10;
digitalWrite(LEDDP,LOW);
AlL=AlLed[0];
//digitalWrite(OPLED, LEDOFF);
OpL=OpLed[0];
dispD = 3;
//TempChk();
adjTS = EEPROM.read(0);
if (adjTS > 59) adjTS = 0;
adjRmS = adjTS;
adjTM = EEPROM.read(1);
if (adjTM > 59) adjTM = 0;
adjRmM = adjTM;
adjTH = EEPROM.read(2);
if (adjTH > 23) adjTH = 0;
adjRmH = adjTH;
adjTD = EEPROM.read(3);
if (adjTD > 99) adjTD = 0;
adjRmD = adjTD;
adjVV = EEPROM.read(4);
if (adjVV > 29) {
adjVV = 0;
}
adjVF = EEPROM.read(5);
if (adjVF == 0) {
adjVlue = adjVV;
} else {
adjVlue = (-1) * adjVV;
}
attachInterrupt(0, intpros0, CHANGE);
attachInterrupt(1, intpros1, CHANGE);
if (RTC.read(tm)) {
yr = tm.Year + 1970 - 2000 ; //1970年が基準でRTCの内部で処理されている
mh = tm.Month;
dy = tm.Day;
h = tm.Hour;
m = tm.Minute;
sd = tm.Second;
prvD = dy;
setAdjT();
}
// nowTimeM = millis();
// randomSeed( nowTimeM );
}
0コメント