Components and supplies
UTSOURCE Electronic Parts
Arduino UNO
Project description
Code
Code snippet #1
text
1//Youtube channel: engineer2you 2#include <Wire.h> 3#include "DS3231.h" 4 5RTClib RTC; 6DS3231 Clock; 7 8int hour; 9int minute; 10int second; 11 12const int nixie_0 = 2; 13const int nixie_1 = 3; 14const int nixie_2 = 4; 15const int nixie_3 = 5; 16const int nixie_4 = 6; 17const int nixie_5 = 7; 18const int nixie_6 = 8; 19const int nixie_7 = 9; 20const int nixie_8 = 10; 21const int nixie_9 = 11; 22 23const int row_1 = 0; 24const int row_2 = 1; 25const int row_3 = 14; 26const int row_4 = 15; 27const int row_5 = 16; 28const int row_6 = 17; 29 30const int time_on = 2; 31 32void setup() { 33 pinMode(nixie_0, OUTPUT); 34 pinMode(nixie_1, OUTPUT); 35 pinMode(nixie_2, OUTPUT); 36 pinMode(nixie_3, OUTPUT); 37 pinMode(nixie_4, OUTPUT); 38 pinMode(nixie_5, OUTPUT); 39 pinMode(nixie_6, OUTPUT); 40 pinMode(nixie_7, OUTPUT); 41 pinMode(nixie_8, OUTPUT); 42 pinMode(nixie_9, OUTPUT); 43 pinMode(row_1, OUTPUT); 44 pinMode(row_2, OUTPUT); 45 pinMode(row_3, OUTPUT); 46 pinMode(row_4, OUTPUT); 47 pinMode(row_5, OUTPUT); 48 pinMode(row_6, OUTPUT); 49 //Serial.begin(9600); //should NOT use seiral println, it will effect to output pin D0 & D1 50 Wire.begin(); 51} 52 53void loop() { 54 //-------------------get clock value--------------------------- 55 DateTime now = RTC.now(); 56 hour = now.hour(); 57 minute = now.minute(); 58 second = now.second(); 59 60 //-------------------show clock number ---------------------- 61 int j; //second number from right 62 int k; //first number from right 63 64 j = second/10; 65 k = second%10; 66 //-----------show first number of second 67 off_all(); 68 on_number(0,k+2); 69 delay(time_on); 70 //-----------show second number of second 71 off_all(); 72 on_number(1,j+2); 73 delay(time_on); 74 75 j = minute/10; 76 k = minute%10; 77 //-----------show first number of minute 78 off_all(); 79 on_number(14,k+2); 80 delay(time_on); 81 //-----------show second number of minute 82 off_all(); 83 on_number(15,j+2); 84 delay(time_on); 85 86 j = hour/10; 87 k = hour%10; 88 //-----------show first number of hour 89 off_all(); 90 on_number(16,k+2); 91 delay(time_on); 92 //-----------show second number of hour 93 off_all(); 94 on_number(17,j+2); 95 delay(time_on); 96} 97 98void on_number(int row, int nixie){ 99 digitalWrite(row, HIGH); 100 digitalWrite(nixie, HIGH); 101} 102 103void off_all(){ 104 digitalWrite(row_1, LOW); 105 digitalWrite(row_2, LOW); 106 digitalWrite(row_3, LOW); 107 digitalWrite(row_4, LOW); 108 digitalWrite(row_5, LOW); 109 digitalWrite(row_6, LOW); 110 digitalWrite(nixie_0, LOW); 111 digitalWrite(nixie_1, LOW); 112 digitalWrite(nixie_2, LOW); 113 digitalWrite(nixie_3, LOW); 114 digitalWrite(nixie_4, LOW); 115 digitalWrite(nixie_5, LOW); 116 digitalWrite(nixie_6, LOW); 117 digitalWrite(nixie_7, LOW); 118 digitalWrite(nixie_8, LOW); 119 digitalWrite(nixie_9, LOW); 120 121 delayMicroseconds(400); //to prevent "ghost" effect to other tube 122}
Comments
Only logged in users can leave comments
whitebank
0 Followers
•0 Projects
0