//A binary code representing one digit. typedef struct binCode { int nbr[4]; } binCode; binCode b_c_null = {1,1,1,1}; binCode b_c_0 = {0,0,0,0}; binCode b_c_1 = {0,0,0,1}; binCode b_c_2 = {0,0,1,0}; binCode b_c_3 = {0,0,1,1}; binCode b_c_4 = {0,1,0,0}; binCode b_c_5 = {0,1,0,1}; binCode b_c_6 = {0,1,1,0}; binCode b_c_7 = {0,1,1,1}; binCode b_c_8 = {1,0,0,0}; binCode b_c_9 = {1,0,0,1}; binCode b_c_10 = {1,0,1,0}; binCode b_c_11 = {1,0,1,1}; binCode b_c_12 = {1,1,0,0}; binCode b_c_13 = {1,1,0,1}; binCode b_c_14 = {1,1,1,0}; //At position x is the bincode for the ic to light up the nixie tube number x. static binCode bin_code_list_nixie_digits_0_to_9[10] = {b_c_4, b_c_9, b_c_1, b_c_0, b_c_8, b_c_10, b_c_2, b_c_6, b_c_14, b_c_12}; //Most significant bit : A B C D : Least significant bit. // __ // (b_c_1) 1_| |_16 (b_c_0) // (b_c_9) 2_| |_15 (b_c_8) // (A) 3_| |_14 (b_c_10) // (D) 4_| |_13 (b_c_2) // (_5V_) 5_| |_12 (_GND_) // (B) 6_| |_11 (b_c_6) // (C) 7_| |_10 (b_c_14) // (b_c_4) 8_|__|_9 (b_c_12) // // // PIN_13 6 _____ 5 PIN_14 // /FRONT\ // PIN_11 7 / \ 4 PIN_15 // / \ //PIN_10 8 | TOP | 3 PIN_16 // | | //PIN_9 9 \ / 2 PIN_1 // \ / // PIN_8 0 \_____/ 1 PIN_2 // . GND . //Out pin to chips static int h1_1 = 22; static int h1_2 = 23; static int h1_3 = 24; static int h1_4 = 25; static int h2_1 = 30; static int h2_2 = 31; static int h2_3 = 32; static int h2_4 = 33; static int m1_1 = 38; static int m1_2 = 39; static int m1_3 = 40; static int m1_4 = 41; static int m2_1 = 46; static int m2_2 = 47; static int m2_3 = 48; static int m2_4 = 49; //Time variables /* Starting time 13:59:45 */ static int h = 13; static int m = 23; static int s = 45; static float ms = millis(); static float cms; static int blinkOnOff = 0; //Jumpdirection variable, (1=forward, 0=backwards) static int jump_forward = 1; //Alarm variables static char alarmOn = '0'; //Obs CHAR static int alarmTime_h = 0; static int alarmTime_m = 0; static int alarmTime_s = 0; static int in_analog_A0 = 1; static int test_blink = 0; void setup(void) { // put your setup code here, to run once: Serial.begin(9600); Serial.println("Start"); // initialize digital pin 13 as an output. pinMode(13, OUTPUT); pinMode(52, OUTPUT); //Out pins for Nixie tubes pinMode(h1_1, OUTPUT); pinMode(h1_2, OUTPUT); pinMode(h1_3, OUTPUT); pinMode(h1_4, OUTPUT); pinMode(h2_1, OUTPUT); pinMode(h2_2, OUTPUT); pinMode(h2_3, OUTPUT); pinMode(h2_4, OUTPUT); pinMode(m1_1, OUTPUT); pinMode(m1_2, OUTPUT); pinMode(m1_3, OUTPUT); pinMode(m1_4, OUTPUT); pinMode(m2_1, OUTPUT); pinMode(m2_2, OUTPUT); pinMode(m2_3, OUTPUT); pinMode(m2_4, OUTPUT); } void loop(void) { Serial.print("A0 = "); Serial.print(analogRead(A0)); Serial.println("\n"); // Speed? if (analogRead(A0) <= 16) { //To be able to distinguish between two sequentiall button pushes. //And only switch the direction at a button push. while (analogRead(A0) <= 16) { if (jump_forward) { //Jump forward updateTime(20); //Increases the seconds by 20s. printTime(); //Prints time to PC updateNixieTubes(); Serial.println("Speeding"); test_print_A0(); } else { //Jump backwards updateTimeReverse(20); //Decreases the seconds by 20s. printTime(); //Prints time to PC updateNixieTubes(); Serial.println("Speeding backwards"); test_print_A0(); } ms = millis() - 1; //För att förhindra att klockan rusar / inte tickar fram alls. } //Switch the jump direction after we release the button. if (jump_forward == 0) { jump_forward = 1; } else { jump_forward = 0; } } cms = millis(); if ( (cms > ms ) && (analogRead(A0) != 1023) ) { //Control clock ms += 1000; updateTime(1); //Increases the seconds by 1. printTime(); //Prints time to PC updateNixieTubes(); } } void test_print_A0() { Serial.print("A0 = "); Serial.println(analogRead(A0)); } void updateTime(int T) { s += T; if ( s > 59 ) { m++; s = 0; } if ( m > 59 ) { h++; m = 0; } if ( h > 23) { h = 0; } } //Jumping backwards in time T seconds. void updateTimeReverse(int T) { s -= T; if (s < 0) { m--; s = 59; } if (m < 0) { h--; m = 59; } if (h < 0) { h = 23; } } void printTime() { Serial.print("hh:mm:ss = "); if (h < 10) { Serial.print(0); } Serial.print(h); Serial.print(":"); if (m < 10) { Serial.print(0); } Serial.print(m); Serial.print(":"); if (s < 10) { Serial.print(0); } Serial.println(s); } //Uppdatera nixierörsen. void updateNixieTubes() { //Print the time in binary code for now //Convert time to hh:mm:ss each a char. int h_1 = h / 10; int h_2 = h % 10; int m_1 = m / 10; int m_2 = m % 10; int s_1 = s / 10; int s_2 = s % 10; Serial.print(h_1); Serial.print(h_2); Serial.print(":"); Serial.print(m_1); Serial.print(m_2); Serial.print(":"); Serial.print(s_1); Serial.print(s_2); Serial.println("\n"); //Light the nixie tubes. light_up_binCode(1, bin_code_list_nixie_digits_0_to_9[h_1]); light_up_binCode(2, bin_code_list_nixie_digits_0_to_9[h_2]); light_up_binCode(3, bin_code_list_nixie_digits_0_to_9[m_1]); light_up_binCode(4, bin_code_list_nixie_digits_0_to_9[m_2]); //Test if (test_blink == 0) { Serial.print( "Lighting up test led 52.\n" ); digitalWrite(52, HIGH); } else { Serial.print( "Lighting down test led 52.\n" ); digitalWrite(52, LOW); } test_blink = (test_blink + 1) % 2; } void light_up_binCode (int tube, binCode b_c_x) { int starting_port = 0; //Which ports should be used. if (tube == 1) { starting_port = h1_1; } else if (tube == 2) { starting_port = h2_1; } else if (tube == 3) { starting_port = m1_1; } else if (tube == 4) { starting_port = m2_1; } //Set the port outputs. digitalWrite(starting_port++, b_c_x.nbr[0]); digitalWrite(starting_port++, b_c_x.nbr[1]); digitalWrite(starting_port++, b_c_x.nbr[2]); digitalWrite(starting_port++, b_c_x.nbr[3]); } void print_array (binCode b) { int x; for (x = 0; x < 4; ++x) { Serial.print( b.nbr[x] ); } }