• 車種別
  • パーツ
  • 整備手帳
  • ブログ
  • みんカラ+

!ビアンキ!のブログ一覧

2018年02月25日 イイね!

Binary clock(二進数時計)にRTCモジュールDS1302

Binary clock(二進数時計)にRTCモジュールDS1302先日作成しました二進数時計ですが、実は1日で1分くらい遅れる時計でした。







それでRTCモジュールDS1302と言う水晶(クォーツ)を使った基板を付けたしました。
alt
それでも1日に数秒、ずれてしまいますけどね・・・

これをArduinoで使うにはDS1302のライブラリが必要です。
この辺がよくわからず苦労しましたが・・・

汚いソースコードですが・・・Arduino IDEでのプログラムです。(配線図が無いと意味ないけど)


//二進数時計

#include <DS1302RTC.h>

#include <Time.h>
#include <TimeLib.h>

// Init the DS1302
// Set pins: CE, IO,CLK
// Set pins: RST,DAT,CLK
DS1302RTC RTC(14, 15, 16);

time_t tokei;

const int buttonPinH = 19; //時を進めるボタン
const int buttonPinM = 18; //分を進めるボタン
const int buttonPinS = 17; //秒をリセットするボタン
int buttonState = 0;

//LEDの表示状態
int tb46[4][6] = {{HIGH, HIGH, HIGH, HIGH, HIGH, HIGH}, {HIGH, HIGH, HIGH, HIGH, HIGH, HIGH}, {HIGH, HIGH, HIGH, HIGH, HIGH, HIGH}, {HIGH, HIGH, HIGH, HIGH, HIGH, HIGH}};
//列のピン番号
int tb01[4] = {
11, 10, 9, 8
};
//行のピン番号
int tb02[6] = {
2, 3, 4, 5, 6, 7
};


void setup()
{
//ボタンを入力に設定
pinMode(buttonPinH, INPUT_PULLUP);
pinMode(buttonPinM, INPUT_PULLUP);
pinMode(buttonPinS, INPUT_PULLUP);

//LEDピンを出力に設定
for (int i = 0; i <= 3; i++)
{
pinMode(tb01[i], OUTPUT);
}
for (int i = 0; i <= 5; i++)
{
pinMode(tb02[i], OUTPUT);
}

// setTime(16,30,0,2,17,2018);
Serial.begin(9600);
if (RTC.haltRTC())
Serial.print("Clock stopped!");
else
Serial.print("Clock working.");
if (RTC.writeEN())
Serial.print("Write allowed.");
else
Serial.print("Write protected.");

setSyncProvider(RTC.get);
if (timeStatus() == timeSet)
Serial.print(" Ok!");
else
Serial.print(" FAIL!");
RTC.set(now());
}
void loop()
{
while ( tokei == now() ) {
dispTokei(); //LED表示
}

buttonState = digitalRead(buttonPinH); //時ボタン
if (buttonState == LOW) {
setTime(hour() + 1, minute() , second(), day(), month(), year());
RTC.set(now());
}
buttonState = digitalRead(buttonPinM); //分ボタン
if (buttonState == LOW) {
setTime(hour(), minute() + 1, second(), day(), month(), year());
RTC.set(now());
}
buttonState = digitalRead(buttonPinS); //秒ボタン
if (buttonState == LOW) {
setTime(hour(), minute() , 0, day(), month(), year());
RTC.set(now());
}

tokei = now();
digitalTokei(); //LEDセット
}

void digitalTokei() {
String thisString1;
String thisString2;
int a;
a = second(); //秒
thisString1 = String(a).charAt(0); //秒1桁目を取り出し
thisString2 = String(a).charAt(1); //秒2桁目
if (thisString2 == "") {
thisString2 = thisString1;
thisString1 = "0";
}
tbset(5, thisString2); //秒2桁目をLEDにセット
tbset(4, thisString1); //秒1桁目

a = minute(); //分
thisString1 = String(a).charAt(0);
thisString2 = String(a).charAt(1);
if (thisString2 == "") {
thisString2 = thisString1;
thisString1 = "0";
}
tbset(3, thisString2);
tbset(2, thisString1);

a = hour(); //時
thisString1 = String(a).charAt(0);
thisString2 = String(a).charAt(1);
if (thisString2 == "") {
thisString2 = thisString1;
thisString1 = "0";
}
tbset(1, thisString2);
tbset(0, thisString1);

}

//テーブルの内容を見てLED表示
void dispTokei() {
for (int i = 0; i <= 3; i++)
{
for (int j = 0; j <= 5; j++)
{
digitalWrite( tb01[i], tb46[i][j]);
digitalWrite( tb02[j], tb46[i][j]);
// delay(1);
digitalWrite( tb01[i], LOW);
digitalWrite( tb02[j], LOW);
}
}
}

//10進数を 2進数に変換しLEDにセット
void tbset(int tb46yoko, String thisString) {
if (thisString == "0") {
tb46[0][tb46yoko] = LOW;
tb46[1][tb46yoko] = LOW;
tb46[2][tb46yoko] = LOW;
tb46[3][tb46yoko] = LOW;
}
if (thisString == "1") {
tb46[0][tb46yoko] = HIGH;
tb46[1][tb46yoko] = LOW;
tb46[2][tb46yoko] = LOW;
tb46[3][tb46yoko] = LOW;
}
if (thisString == "2") {
tb46[0][tb46yoko] = LOW;
tb46[1][tb46yoko] = HIGH;
tb46[2][tb46yoko] = LOW;
tb46[3][tb46yoko] = LOW;
}
if (thisString == "3") {
tb46[0][tb46yoko] = HIGH;
tb46[1][tb46yoko] = HIGH;
tb46[2][tb46yoko] = LOW;
tb46[3][tb46yoko] = LOW;
}
if (thisString == "4") {
tb46[0][tb46yoko] = LOW;
tb46[1][tb46yoko] = LOW;
tb46[2][tb46yoko] = HIGH;
tb46[3][tb46yoko] = LOW;
}
if (thisString == "5") {
tb46[0][tb46yoko] = HIGH;
tb46[1][tb46yoko] = LOW;
tb46[2][tb46yoko] = HIGH;
tb46[3][tb46yoko] = LOW;
}
if (thisString == "6") {
tb46[0][tb46yoko] = LOW;
tb46[1][tb46yoko] = HIGH;
tb46[2][tb46yoko] = HIGH;
tb46[3][tb46yoko] = LOW;
}
if (thisString == "7") {
tb46[0][tb46yoko] = HIGH;
tb46[1][tb46yoko] = HIGH;
tb46[2][tb46yoko] = HIGH;
tb46[3][tb46yoko] = LOW;
}
if (thisString == "8") {
tb46[0][tb46yoko] = LOW;
tb46[1][tb46yoko] = LOW;
tb46[2][tb46yoko] = LOW;
tb46[3][tb46yoko] = HIGH;
}
if (thisString == "9") {
tb46[0][tb46yoko] = HIGH;
tb46[1][tb46yoko] = LOW;
tb46[2][tb46yoko] = LOW;
tb46[3][tb46yoko] = HIGH;
}

}



ついでに外装も作り直しスイッチを上部に3個付け足しました。

それぞれ時を進める、分を進める、秒を0にする役割を持たせました。

Posted at 2018/02/25 10:31:46 | コメント(0) | トラックバック(0) | 電子工作 | 趣味
2018年02月12日 イイね!

Binary clock(二進数時計)

Binary clock(二進数時計)昨年から電子工作にハマっている私です。
今回はArduino UNOで二進数の時計を作ってみました。

ArduinoはElegoo UNO キットって言う互換機で安いのを買いました。
各種センサーやらディスプレイモジュール等が付いていても三千円!

前に作った4*4*4LEDキューブは日本語で参考にするサイトがあったので、その通りに作ってできましたが・・・
今回のバイナリークロックの回路は4*4*4LEDキューブを参考に二次元にして組み直し、プログラムは一から新たに作ったので何回も失敗しました。




例えばこんな感じの表示だとして

0 1 0 0 0 0 : 8
0 0 1 0 0 1 : 4
0 0 0 1 1 1 : 2
1 1 0 0 0 1 : 1
------------
1 9:4 2:2 7 になります。

時間を確認するのに4と2を足して6時か~とか面倒ですwww
二進数を知らないと確認できない時計が出来上がりました!
Posted at 2018/02/12 11:28:15 | コメント(0) | トラックバック(0) | 電子工作 | 趣味
2018年02月03日 イイね!

Kodak スナップキッズのレンズで

Kodak スナップキッズのレンズでクローゼットの奥から出てきました「Kodak スナップキッズ」レンズ付きフィルム。

実は同時に「写ルンです」も見つかったのですが、「Kodak スナップキッズ」をググってみたらレンズが1枚じゃなく2 群2 枚と言うことで写りが気になり分解してみました。

レンズはEktanar 30㎜ F10(固定焦点. 2 群2 枚構成(プラスチック非球面レンズ仕様)

以前やった「CENTURIA撮りっきり」と同様にEマウントにして撮ってみました。


DSC04279(Kodak スナップキッズ)

DSC04284(Kodak スナップキッズ)

DSC04314(Kodak スナップキッズ)

DSC04331copy

1枚レンズの「CENTURIA撮りっきり」よりも若干、写りが良いような気もします。

周辺光量落ちは大好きです・・・
Posted at 2018/02/03 09:17:23 | コメント(0) | トラックバック(0) | カメラ | 趣味

プロフィール

「Technics SL-D4のゴムベルト交換 http://cvw.jp/b/155344/48460664/
何シテル?   05/31 19:50
ブログを始めた当初は車関係、今ではカメラ、電子工作、DIY等が中心ですが更新頻度も減りました。 2019年、中古のBMW MINI R56に乗り換えました。 ...
みんカラ新規会員登録

ユーザー内検索

<< 2018/2 >>

    12 3
45678910
11 121314151617
18192021222324
25262728   

リンク・クリップ

YouTube(電脳カラクリ) 
カテゴリ:その他(カテゴリ未設定)
2023/03/05 19:40:45
 

愛車一覧

スズキ ジムニー JA11 (スズキ ジムニー)
欲しくなって、欲しくなって、ジモティーで購入。 錆、凹み・・・ボロボロです。 でも運転 ...
ミニ MINI ミニ MINI
ペッパーホワイト、ブラックルーフ 中古で購入
日産 マーチ 日産 マーチ
妹から引き継いだ車
トヨタ カローラレビン トヨタ カローラレビン
最初の車
ヘルプ利用規約サイトマップ
© LY Corporation