Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- #include <DS3231.h>
- DS3231 rtc(SDA, SCL);
- Time t;
- //
- // Use convention of N1N2N2N4 (reading the Nixie tubes left to right in display) and
- // for the time use Hh:Mm
- // These pins wiring drive the Nixie Driver chips ABCD inputs
- #define N1C 28 //C - Hour tens digit
- #define N1B 26 //B
- #define N1D 24 //D
- #define N1A 22 //A
- #define N2C 36 //hour ones digit
- #define N2B 34
- #define N2D 32
- #define N2A 30
- #define N3C 44 //minutes tens digit
- #define N3B 42
- #define N3D 40
- #define N3A 38
- #define N4C 52 //minutes ones digit
- #define N4B 50
- #define N4D 48
- #define N4A 46
- //
- //................Define the pushbutton panel Analog Inputs .................
- const int but0 = 62; // Assign variable names of button numbers to inputs.
- const int but1 = 63;
- const int but2 = 64;
- const int but3 = 65;
- const int but4 = 66;
- const int but5 = 67;
- const int but6 = 68;
- const int but7 = 69;
- //
- int but0state = 0; // define a variable to follow if button is being pushed.
- int but1state = 0;
- int but2state = 0;
- int but3state = 0;
- int but4state = 0;
- int but5state = 0;
- int but6state = 0;
- int but7state = 0;
- //
- byte nowHour, nowMinute,nowSecond;
- byte dig1, dig2, dig3, dig4;
- float fahrenheit;
- // ----------------------------------- End of Clock Initialization -----------------------
- //
- // ------------------------------------Initialize Humidity Sensor -------------------------
- #include <Adafruit_Sensor.h>
- #include <DHT.h>
- #include <DHT_U.h>
- #define DHTPIN 56 // Pin which is connected to the DHT sensor.
- #define DHTTYPE DHT22 // DHT 22 (AM2302)
- DHT dht(DHTPIN, DHTTYPE);
- //uint32_t delayMS;
- //
- // ------------------------------------End Initialization of Humidity Sensor --------------
- //
- // ----------------------------------- Initializing for the Temperature / Pressure BME280 Sensor ---------------------------------
- #include <stdint.h>
- #include "SparkFunBME280.h"
- // Initializing the I2C communications for the BME280
- #include "Wire.h"
- BME280 mySensor; //Global sensor object
- #include <math.h>
- #include "Servo.h"
- Servo servo1;
- // -------------------------- End of Temp & Pressure BME280 Sensor Initialization --------------------
- //
- void setup() {
- //
- servo1.attach(61);
- // Establish the pins as outputs. Drive the Nixie Driver chip in Binary
- // Reference the truth table of the chip driver for how the pattern of ABCD turns on the respective output
- // A = 2**0 Least Significant Bit (LSB)
- // B = 2**1
- // C = 2**2
- // D = 2**3 Most Significant Bit (MSB)
- //
- pinMode(N1A, OUTPUT); //Least Significant Bit (LSB)
- pinMode(N1B, OUTPUT);
- pinMode(N1C, OUTPUT);
- pinMode(N1D, OUTPUT); //MSB
- //
- pinMode(N2A, OUTPUT); //LSB
- pinMode(N2B, OUTPUT);
- pinMode(N2C, OUTPUT);
- pinMode(N2D, OUTPUT); //MSB
- //
- pinMode(N3A, OUTPUT); //LSB 2**0 38
- pinMode(N3B, OUTPUT); // 2**1 42
- pinMode(N3C, OUTPUT); // 2**2 44
- pinMode(N3D, OUTPUT); //MSB 2**3 40
- //
- pinMode(N4A, OUTPUT); //LSB
- pinMode(N4B, OUTPUT);
- pinMode(N4C, OUTPUT);
- pinMode(N4D, OUTPUT); //MSB
- //
- pinMode(but0,INPUT); // declare inputs for the variables of the buttons.
- pinMode(but1,INPUT);
- pinMode(but2,INPUT);
- pinMode(but3,INPUT);
- pinMode(but4,INPUT);
- pinMode(but5,INPUT);
- pinMode(but6,INPUT);
- pinMode(but7,INPUT);
- //
- // LEDs for the Clock Decimal,Decimal Point and Display Mode (LEDs for F Temp, Hg, %Humidity)
- pinMode(7,OUTPUT);
- pinMode(6,OUTPUT);
- pinMode(5,OUTPUT);
- pinMode(9,OUTPUT);
- pinMode(8,OUTPUT);
- //
- rtc.begin();
- //
- // The following lines can be uncommented to set the date and time - uncomment - then upload - the uncomment and re-upload.
- //rtc.setDOW(SATURDAY); // Set Day-of-Week to SUNDAY
- //rtc.setTime(22, 01, 40); // Set the time to 10:58:09 (Use 24hr format when setting time & use no leading 0.)
- //rtc.setDate(17,3,2018); // Set the date to day,month, year i.e. 31 Dec 2017
- // ------------------------------------------------------------------------------------
- //-------------------------------- Set Up the BME280 Sensor ------------------------------------------------
- // For I2C, enable the following lines to address the sensor
- mySensor.settings.commInterface = I2C_MODE;
- mySensor.settings.I2CAddress = 0x76;
- //runMode can be:
- // 0, Sleep mode
- // 1 or 2, Forced mode
- // 3, Normal mode
- mySensor.settings.runMode = 3; //Normal mode
- //tStandby can be:
- // 0, 0.5ms
- // 1, 62.5ms
- // 2, 125ms
- // 3, 250ms
- // 4, 500ms
- // 5, 1000ms
- // 6, 10ms
- // 7, 20ms
- mySensor.settings.tStandby = 0;
- //filter can be off or number of FIR coefficients to use:
- // 0, filter off
- // 1, coefficients = 2
- // 2, coefficients = 4
- // 3, coefficients = 8
- // 4, coefficients = 16
- mySensor.settings.filter = 0;
- //tempOverSample can be:
- // 0, skipped
- // 1 through 5, oversampling *1, *2, *4, *8, *16 respectively
- mySensor.settings.tempOverSample = 1;
- //pressOverSample can be:
- // 0, skipped
- // 1 through 5, oversampling *1, *2, *4, *8, *16 respectively
- mySensor.settings.pressOverSample = 1;
- //humidOverSample can be:
- // 0, skipped
- // 1 through 5, oversampling *1, *2, *4, *8, *16 respectively
- mySensor.settings.humidOverSample = 1;
- // End of Set up for the BME280 ----------------------------------------------
- // ---------------------START OF THE Serial Port Set Up ....................................
- Serial.begin(9600);
- Serial.print("Program Started\n");
- Serial.print("Starting BME280... result of .begin(): 0x");
- //------------ Calling .begin() causes the settings to be loaded
- delay(10); //Make sure sensor had enough time to turn on. BME280 requires 2ms to start up.
- Serial.println(mySensor.begin(), HEX);
- Serial.print("Displaying ID, reset and ctrl regs\n");
- Serial.print("ID(0xD0): 0x");
- Serial.println(mySensor.readRegister(BME280_CHIP_ID_REG), HEX);
- Serial.print("Reset register(0xE0): 0x");
- Serial.println(mySensor.readRegister(BME280_RST_REG), HEX);
- Serial.print("ctrl_meas(0xF4): 0x");
- Serial.println(mySensor.readRegister(BME280_CTRL_MEAS_REG), HEX);
- Serial.print("ctrl_hum(0xF2): 0x");
- Serial.println(mySensor.readRegister(BME280_CTRL_HUMIDITY_REG), HEX);
- Serial.print("\n\n");
- Serial.print("Displaying all regs\n");
- uint8_t memCounter = 0x80;
- uint8_t tempReadData;
- for(int rowi = 8; rowi < 16; rowi++ )
- {
- Serial.print("0x");
- Serial.print(rowi, HEX);
- Serial.print("0:");
- for(int coli = 0; coli < 16; coli++ )
- {
- tempReadData = mySensor.readRegister(memCounter);
- Serial.print((tempReadData >> 4) & 0x0F, HEX);//Print first hex nibble
- Serial.print(tempReadData & 0x0F, HEX);//Print second hex nibble
- Serial.print(" ");
- memCounter++;
- }
- Serial.print("\n");
- }
- Serial.print("\n\n");
- Serial.print("Displaying concatenated calibration words\n");
- Serial.print("dig_T1, uint16: ");
- Serial.println(mySensor.calibration.dig_T1);
- Serial.print("dig_T2, int16: ");
- Serial.println(mySensor.calibration.dig_T2);
- Serial.print("dig_T3, int16: ");
- Serial.println(mySensor.calibration.dig_T3);
- Serial.print("dig_P1, uint16: ");
- Serial.println(mySensor.calibration.dig_P1);
- Serial.print("dig_P2, int16: ");
- Serial.println(mySensor.calibration.dig_P2);
- Serial.print("dig_P3, int16: ");
- Serial.println(mySensor.calibration.dig_P3);
- Serial.print("dig_P4, int16: ");
- Serial.println(mySensor.calibration.dig_P4);
- Serial.print("dig_P5, int16: ");
- Serial.println(mySensor.calibration.dig_P5);
- Serial.print("dig_P6, int16: ");
- Serial.println(mySensor.calibration.dig_P6);
- Serial.print("dig_P7, int16: ");
- Serial.println(mySensor.calibration.dig_P7);
- Serial.print("dig_P8, int16: ");
- Serial.println(mySensor.calibration.dig_P8);
- Serial.print("dig_P9, int16: ");
- Serial.println(mySensor.calibration.dig_P9);
- Serial.println();
- //
- //
- // Set up the DHT22 Humidity Sensor ----------------------------------------
- dht.begin();
- sensor_t sensor;
- //delayMS = sensor.min_delay / 100;
- }
- ////////////////////////// MAIN PROGRAM LOOP //////////////////////////////////
- void loop() {
- // Read the state of the buttons........
- but0state = digitalRead(but0);
- but1state = digitalRead(but1);
- but2state = digitalRead(but2);
- but3state = digitalRead(but3);
- but4state = digitalRead(but4);
- but5state = digitalRead(but5);
- but6state = digitalRead(but6);
- but7state = digitalRead(but7);
- //
- // --------------------------------Servo Humidity Indicator for Last 1 hour ------------
- // 31.5 high 27.25 low mmHg .. 29.375 ave, range = 4.25
- //float CurrentHg = 31.5;
- float CurrentHg = mySensor.readFloatPressure()*0.000295;// read actual humidity
- CurrentHg = map(CurrentHg, 31.5, 27.25, 0, 100);
- servo1.write(CurrentHg);
- t = rtc.getTime();
- // Send date over serial monitor connection to help trouble shoot the time and program display.
- Serial.print("DATE: ");
- Serial.print(t.date, DEC);
- Serial.print(" ");
- Serial.print(rtc.getMonthStr());
- Serial.print(", ");
- Serial.print(t.year, DEC);
- Serial.println(".");
- // Send Day-of-Week and time
- Serial.print("Day of Week:");
- Serial.print(t.dow, DEC);
- Serial.print("/7");
- Serial.println(".");
- Serial.print(t.hour, DEC);
- Serial.print(":");
- Serial.print(t.min, DEC);
- Serial.print(":");
- Serial.print(t.sec, DEC);
- Serial.println(" ");
- Serial.println(" ");
- // Send current temperature
- Serial.print("Temperature: ");
- Serial.print(rtc.getTemp());
- Serial.println(" C");
- // Drive Serial Port for Troubleshooting the program and displays
- Serial.print("");
- Serial.print("Nix 1 = ");
- Serial.print(dig1);
- Serial.println(" ");
- Serial.print("Nix 2 = ");
- Serial.print(dig2);
- Serial.println(" ");
- Serial.print("Nix 3 = ");
- Serial.print(dig3);
- Serial.println(" ");
- Serial.print("Nix 4 = ");
- Serial.print(dig4);
- Serial.print(" ");
- Serial.println(" ");
- //
- DisplayWhat();
- //Now call the routine to drive the Nixie tubes with the correct Chip Driver pattern.
- //
- DriveTubes();
- byte freq = t.sec;
- if (freq >= 0 && freq <= 12 && but0state != HIGH && but1state != HIGH && but2state != HIGH && but3state != HIGH && but4state != HIGH
- && but5state != HIGH && but6state != HIGH && but7state != HIGH)
- {
- digitalWrite(7, LOW); //Middle Green LED
- digitalWrite(6, HIGH); //Top Colon LED
- digitalWrite(5, HIGH); //Bottom Colon LED
- digitalWrite(8, LOW); //Right Green LED
- digitalWrite(9, LOW); //Left Green LED
- DisplayTime(); //Time
- DriveTubes();
- delay(10);
- }
- else if (freq >= 13 && freq <= 17 && but0state != HIGH && but1state != HIGH && but2state != HIGH && but3state != HIGH && but4state != HIGH
- && but5state != HIGH && but6state != HIGH && but7state != HIGH)
- {
- digitalWrite(7, LOW); //Middle Green LED
- digitalWrite(6, LOW); //Top Colon LED
- digitalWrite(5, HIGH); //Bottom Colon LED
- digitalWrite(8, LOW); //Right Green LED
- digitalWrite(9, HIGH); //Left Green LED
- DisplayTemp(); //Temperature
- DriveTubes();
- delay(10);
- }
- else if (freq >= 18 && freq <= 27 && but0state != HIGH && but1state != HIGH && but2state != HIGH && but3state != HIGH && but4state != HIGH
- && but5state != HIGH && but6state != HIGH && but7state != HIGH)
- {
- digitalWrite(7, LOW); //Middle Green LED
- digitalWrite(6, HIGH); //Top Colon LED
- digitalWrite(5, HIGH); //Bottom Colon LED
- digitalWrite(8, LOW); //Right Green LED
- digitalWrite(9, LOW); //Left Green LED
- DisplayTime(); //Time
- DriveTubes();
- delay(10);
- }
- else if (freq >= 28 && freq <= 32 && but0state != HIGH && but1state != HIGH && but2state != HIGH && but3state != HIGH && but4state != HIGH
- && but5state != HIGH && but6state != HIGH && but7state != HIGH)
- {
- digitalWrite(7, HIGH); //Middle Green LED
- digitalWrite(6, LOW); //Top Colon LED
- digitalWrite(5, HIGH); //Bottom Colon LED
- digitalWrite(8, LOW); //Right Green LED
- digitalWrite(9, LOW); //Left Green LED
- DisplayPress(); //Pressure
- DriveTubes();
- delay(10);
- }
- else if (freq >= 33 && freq <= 42 && but0state != HIGH && but1state != HIGH && but2state != HIGH && but3state != HIGH && but4state != HIGH
- && but5state != HIGH && but6state != HIGH && but7state != HIGH)
- {
- digitalWrite(7, LOW); //Middle Green LED
- digitalWrite(6, HIGH); //Top Colon LED
- digitalWrite(5, HIGH); //Bottom Colon LED
- digitalWrite(8, LOW); //Right Green LED
- digitalWrite(9, LOW); //Left Green LED
- DisplayTime(); //Time
- DriveTubes();
- delay(10);
- }
- else if (freq >= 43 && freq <= 47 && but0state != HIGH && but1state != HIGH && but2state != HIGH && but3state != HIGH && but4state != HIGH
- && but5state != HIGH && but6state != HIGH && but7state != HIGH)
- {
- digitalWrite(7, LOW); //Middle Green LED
- digitalWrite(6, LOW); //Top Colon LED
- digitalWrite(5, HIGH); //Bottom Colon LED
- digitalWrite(8, HIGH); //Right Green LED
- digitalWrite(9, LOW); //Left Green LED
- DisplayHumid(); // humidity
- DriveTubes();
- delay(10);
- }
- else if (freq >= 48 && freq <= 60 && but0state != HIGH && but1state != HIGH && but2state != HIGH && but3state != HIGH && but4state != HIGH
- && but5state != HIGH && but6state != HIGH && but7state != HIGH)
- {
- digitalWrite(7, LOW); //Middle Green LED
- digitalWrite(6, HIGH); //Top Colon LED
- digitalWrite(5, HIGH); //Bottom Colon LED
- digitalWrite(8, LOW); //Right Green LED
- digitalWrite(9, LOW); //Left Green LED
- DisplayTime();// Time
- DriveTubes();
- delay(10);
- }
- //-------- THE BME280 Pressure & Temeprature Sensor ------------
- Serial.print("Temperature: ");
- Serial.print(mySensor.readTempC(), 2);
- Serial.println(" degrees C");
- Serial.print("Temperature: ");
- Serial.print(mySensor.readTempF(), 2);
- Serial.println(" degrees F");
- float HgPress;
- HgPress = mySensor.readFloatPressure()*0.000295;
- Serial.print("Pressure: ");
- Serial.print(HgPress, 2);
- Serial.println(" in Hg");
- Serial.print("Altitude: ");
- Serial.print(mySensor.readFloatAltitudeMeters(), 2);
- Serial.println("m");
- Serial.print("Altitude: ");
- Serial.print(mySensor.readFloatAltitudeFeet(), 2);
- Serial.println("ft");
- //
- //
- // --------------- Loop The DHT22 Humidity Sensor ---------------------------
- // Get humidity event and print its value.
- sensors_event_t event;
- //dht.humidity().getEvent(&event);
- if (isnan(event.relative_humidity)) {
- Serial.println("Error reading humidity!");
- }
- else {
- Serial.print("Humidity: ");
- Serial.print(dht.readHumidity(),2);
- Serial.println("%");
- }
- float h = dht.readHumidity();
- }
- /////////////////////////////////// SUBROUTINES /////////////////////
- void DisplayWhat()
- {
- if(but0state == HIGH || but1state == HIGH || but2state == HIGH || but3state == HIGH)
- {
- ChangeTime();
- }
- else if(but4state == HIGH)
- {
- DisplayTemp();
- }
- else if(but5state == HIGH)
- {
- DisplayPress();
- }
- else if(but6state == HIGH)
- {
- DisplayHumid();
- }
- else if(but7state == HIGH)
- {
- digitalWrite(7, HIGH); //Middle Green LED
- digitalWrite(6, HIGH); //Top Colon LED
- digitalWrite(5, HIGH); //Bottom Colon LED
- digitalWrite(8, HIGH); //Right Green LED
- digitalWrite(9, HIGH); //Left Green LED
- RunPoison();
- }
- }
- void DisplayTime()
- {
- t=rtc.getTime();
- nowHour = t.hour;
- nowMinute = t.min;
- nowSecond = t.sec;
- if(nowHour>12) nowHour=nowHour-12; // Needed for non-military display
- if(nowHour == 0) nowHour = 12;
- //
- // Strip off the digits for the time to drive each nixie tube independently
- dig1 = nowHour/10; //First digit of the hour (1 or 0)
- dig2 = nowHour%10; //Second digit of the hour.
- dig3 = nowMinute/10; //First digit of the minute (40, 30, 20 etc)
- dig4 = nowMinute%10; //Second digit of the minute
- if(dig1==0) dig1=16; //So that the first digit just won't be lit up at all. driveves ABCD bits to no outputs on.
- if(dig3==6) dig3=0; //So that the first digit just won't be lit up at all. ABCD drives a 12 = no outputs on chip driver for a 0.
- }
- //
- void ChangeTime()
- {
- byte prevHour = t.hour;
- byte prevMin = t.min;
- byte prevSec = t.sec;
- int newHour, newMin;
- newHour = prevHour;
- newMin = prevMin;
- if(but0state == HIGH)
- {// Increment the Hour up by 1
- newHour = prevHour+1;
- DisplayTime();
- DriveTubes();
- if(newHour>=24) newHour=0;
- }
- else if(but1state == HIGH)
- {// Decrement the Hour down by one
- newHour=prevHour-1;
- DisplayTime();
- DriveTubes();
- if(newHour<=0) newHour=23;
- }
- if(but2state == HIGH)
- {// Increment the Minute up by one
- newMin = prevMin+1;
- DisplayTime();
- DriveTubes();
- if(newMin>59) newMin=0;
- }
- else if(but3state == HIGH)
- {// Decrement Minute down by one
- newMin=prevMin-1;
- DisplayTime();
- DriveTubes();
- if(newMin<0) newMin=59;
- }
- rtc.setTime(newHour,newMin,prevSec);
- }
- //
- void DisplayTemp()
- {
- float temp;
- temp = mySensor.readTempF()-9;// the subtraction calibrates the temp
- //N1 - Tens
- temp/=10;
- dig1 = temp;
- //N2 - Ones
- temp = (temp-dig1)*10;
- dig2 = temp;
- //N3 - Tenths
- temp = (temp-dig2)*10;
- dig3 = temp;
- //N4 - Hundreths
- temp = (temp-dig3)*10;
- dig4 = temp;
- digitalWrite(7, LOW); //Middle Green LED
- digitalWrite(6, LOW); //Top Colon LED
- digitalWrite(5, HIGH); //Bottom Colon LED
- digitalWrite(8, LOW); //Right Green LED
- digitalWrite(9, HIGH); //Left Green LED
- }
- void DisplayPress()
- {
- float HgPress;
- HgPress = mySensor.readFloatPressure()*0.000295;
- //N1 - Tens
- HgPress/=10;
- dig1 = HgPress;
- //N2 - Ones
- HgPress = (HgPress-dig1)*10;
- dig2 = HgPress;
- //N3 - Tenths
- HgPress = (HgPress-dig2)*10;
- dig3 = HgPress;
- //N4 - Hundreths
- HgPress = (HgPress-dig3)*10;
- dig4 = HgPress;
- digitalWrite(7, HIGH); //Middle Green LED
- digitalWrite(6, LOW); //Top Colon LED
- digitalWrite(5, HIGH); //Bottom Colon LED
- digitalWrite(8, LOW); //Right Green LED
- digitalWrite(9, LOW); //Left Green LED
- }
- //
- void DisplayHumid()
- {
- float Humidity;
- //sensors_event_t event;
- //Humidity = event.relative_humidity;
- Humidity = dht.readHumidity();
- //N1 - Tens
- Humidity/=10;
- dig1 = Humidity;
- //N2 - Ones
- Humidity = (Humidity-dig1)*10;
- dig2 = Humidity;
- //N3 - Tenths
- Humidity = (Humidity-dig2)*10;
- dig3 = Humidity;
- //N4 - Hundreths
- Humidity = (Humidity-dig3)*10;
- dig4 = Humidity;
- //
- digitalWrite(7, LOW); //Middle Green LED
- digitalWrite(6, LOW); //Top Colon LED
- digitalWrite(5, HIGH); //Bottom Colon LED
- digitalWrite(8, HIGH); //Right Green LED
- digitalWrite(9, LOW); //Left Green LED
- //
- }
- //
- void RunPoison()
- // Run through the digits on all nixies to prevent cathode poisoning - on Pushbutton 8 only.
- // This code cycles through the digits of a Nixie Tube.
- {
- for (int i = 0; i < 10; i++)
- {
- //0
- digitalWrite(N1D, LOW); //D1 MSB
- digitalWrite(N1C, LOW); //C1 MSB -1
- digitalWrite(N1B, LOW); //B1 MSB -2
- digitalWrite(N1A, LOW); //A1 LSB
- delay(10);
- digitalWrite(N2D, LOW); //D2
- digitalWrite(N2C, LOW); //C2
- digitalWrite(N2B, LOW); //B2
- digitalWrite(N2A, LOW); //A2
- delay(10);
- digitalWrite(N3D, LOW); //D3
- digitalWrite(N3C, LOW); //C3
- digitalWrite(N3B, LOW); //B3
- digitalWrite(N3A, LOW); //A3
- delay(10);
- digitalWrite(N4D, LOW); //D3
- digitalWrite(N4C, LOW); //C3
- digitalWrite(N4B, LOW); //B3
- digitalWrite(N4A, LOW); //A3
- delay(10);
- //1
- digitalWrite(N1D, LOW); //D1
- digitalWrite(N1C, LOW); //C1
- digitalWrite(N1B, LOW); //B1
- digitalWrite(N1A, HIGH); //A1
- delay(10);
- digitalWrite(N2D, LOW); //D2
- digitalWrite(N2C, LOW); //C2
- digitalWrite(N2B, LOW); //B2
- digitalWrite(N2A, HIGH); //A2
- delay(10);
- digitalWrite(N3D, LOW); //D3
- digitalWrite(N3C, LOW); //C3
- digitalWrite(N3B, LOW); //B3
- digitalWrite(N3A, HIGH); //A3
- delay(10);
- digitalWrite(N4D, LOW); //D3
- digitalWrite(N4C, LOW); //C3
- digitalWrite(N4B, LOW); //B3
- digitalWrite(N4A, HIGH); //A3
- delay(10);
- //2
- digitalWrite(N1D, LOW); //D1
- digitalWrite(N1C, LOW); //C1
- digitalWrite(N1B, HIGH); //B1
- digitalWrite(N1A, LOW); //A1
- delay(10);
- digitalWrite(N2D, LOW); //D2
- digitalWrite(N2C, LOW); //C2
- digitalWrite(N2B, HIGH); //B2
- digitalWrite(N2A, LOW); //A2
- delay(10);
- digitalWrite(N3D, LOW); //D3
- digitalWrite(N3C, LOW); //C3
- digitalWrite(N3B, HIGH); //B3
- digitalWrite(N3A, LOW); //A3
- delay(10);
- digitalWrite(N4D, LOW); //D3
- digitalWrite(N4C, LOW); //C3
- digitalWrite(N4B, HIGH); //B3
- digitalWrite(N4A, LOW); //A3
- delay(10);
- //3
- digitalWrite(N1D, LOW); //D1
- digitalWrite(N1C, LOW); //C1
- digitalWrite(N1B, HIGH); //B1
- digitalWrite(N1A, HIGH); //A1
- delay(10);
- digitalWrite(N2D, LOW); //D2
- digitalWrite(N2C, LOW); //C2
- digitalWrite(N2B, HIGH); //B2
- digitalWrite(N2A, HIGH); //A2
- delay(10);
- digitalWrite(N3D, LOW); //D3
- digitalWrite(N3C, LOW); //C3
- digitalWrite(N3B, HIGH); //B3
- digitalWrite(N3A, HIGH); //A3
- delay(10);
- digitalWrite(N4D, LOW); //D3
- digitalWrite(N4C, LOW); //C3
- digitalWrite(N4B, HIGH); //B3
- digitalWrite(N4A, HIGH); //A3
- delay(10);
- //4
- digitalWrite(N1D, LOW); //D1
- digitalWrite(N1C, HIGH); //C1
- digitalWrite(N1B, LOW); //B1
- digitalWrite(N1A, LOW); //A1
- delay(10);
- digitalWrite(N2D, LOW); //D2
- digitalWrite(N2C, HIGH); //C2
- digitalWrite(N2B, LOW); //B2
- digitalWrite(N2A, LOW); //A2
- delay(10);
- digitalWrite(N3D, LOW); //D3
- digitalWrite(N3C, HIGH); //C3
- digitalWrite(N3B, LOW); //B3
- digitalWrite(N3A, LOW); //A3
- delay(10);
- digitalWrite(N4D, LOW); //D3
- digitalWrite(N4C, HIGH); //C3
- digitalWrite(N4B, LOW); //B3
- digitalWrite(N4A, LOW); //A3
- delay(10);
- //5
- digitalWrite(N1D, LOW); //D1
- digitalWrite(N1C, HIGH); //C1
- digitalWrite(N1B, LOW); //B1
- digitalWrite(N1A, HIGH); //A1
- //delay(10);
- digitalWrite(N2D, LOW); //D2
- digitalWrite(N2C, HIGH); //C2
- digitalWrite(N2B, LOW); //B2
- digitalWrite(N2A, HIGH); //A2
- //delay(10);
- digitalWrite(N3D, LOW); //D3
- digitalWrite(N3C, HIGH); //C3
- digitalWrite(N3B, LOW); //B3
- digitalWrite(N3A, HIGH); //A3
- //delay(10);
- digitalWrite(N4D, LOW); //D3
- digitalWrite(N4C, HIGH); //C3
- digitalWrite(N4B, LOW); //B3
- digitalWrite(N4A, HIGH); //A3
- delay(10);
- //6
- digitalWrite(N1D, LOW); //D1
- digitalWrite(N1C, HIGH); //C1
- digitalWrite(N1B, HIGH); //B1
- digitalWrite(N1A, LOW); //A1
- delay(10);
- digitalWrite(N2D, LOW); //D2
- digitalWrite(N2C, HIGH); //C2
- digitalWrite(N2B, HIGH); //B2
- digitalWrite(N2A, LOW); //A2
- delay(10);
- digitalWrite(N3D, LOW); //D3
- digitalWrite(N3C, HIGH); //C3
- digitalWrite(N3B, HIGH); //B3
- digitalWrite(N3A, LOW); //A3
- delay(10);
- digitalWrite(N4D, LOW); //D3
- digitalWrite(N4C, HIGH); //C3
- digitalWrite(N4B, HIGH); //B3
- digitalWrite(N4A, LOW); //A3
- delay(10);
- //7
- digitalWrite(N1D, LOW); //D1
- digitalWrite(N1C, HIGH); //C1
- digitalWrite(N1B, HIGH); //B1
- digitalWrite(N1A, HIGH); //A1
- delay(10);
- digitalWrite(N2D, LOW); //D2
- digitalWrite(N2C, HIGH); //C2
- digitalWrite(N2B, HIGH); //B2
- digitalWrite(N2A, HIGH); //A2
- delay(10);
- digitalWrite(N3D, LOW); //D3
- digitalWrite(N3C, HIGH); //C3
- digitalWrite(N3B, HIGH); //B3
- digitalWrite(N3A, HIGH); //A3
- delay(10);
- digitalWrite(N4D, LOW); //D3
- digitalWrite(N4C, HIGH); //C3
- digitalWrite(N4B, HIGH); //B3
- digitalWrite(N4A, HIGH); //A3
- delay(10);
- //8
- digitalWrite(N1D, HIGH); //D1
- digitalWrite(N1C, LOW); //C1
- digitalWrite(N1B, LOW); //B1
- digitalWrite(N1A, LOW); //A1
- delay(10);
- digitalWrite(N2D, HIGH); //D2
- digitalWrite(N2C, LOW); //C2
- digitalWrite(N2B, LOW); //B2
- digitalWrite(N2A, LOW); //A2
- delay(10);
- digitalWrite(N3D, HIGH); //D3
- digitalWrite(N3C, LOW); //C3
- digitalWrite(N3B, LOW); //B3
- digitalWrite(N3A, LOW); //A3
- delay(10);
- digitalWrite(N4D, HIGH); //D3
- digitalWrite(N4C, LOW); //C3
- digitalWrite(N4B, LOW); //B3
- digitalWrite(N4A, LOW); //A3
- delay(10);
- //9
- digitalWrite(N1D, HIGH); //D1
- digitalWrite(N1C, LOW); //C1
- digitalWrite(N1B, LOW); //B1
- digitalWrite(N1A, HIGH); //A1
- delay(10);
- digitalWrite(N2D, HIGH); //D2
- digitalWrite(N2C, LOW); //C2
- digitalWrite(N2B, LOW); //B2
- digitalWrite(N2A, HIGH); //A2
- delay(10);
- digitalWrite(N3D, HIGH); //D3
- digitalWrite(N3C, LOW); //C3
- digitalWrite(N3B, LOW); //B3
- digitalWrite(N3A, HIGH); //A3
- delay(10);
- digitalWrite(N4D, HIGH); //D3
- digitalWrite(N4C, LOW); //C3
- digitalWrite(N4B, LOW); //B3
- digitalWrite(N4A, HIGH); //A3
- delay(10);}
- }
- //
- //
- void DriveTubes() //..............Evaluate and display each nixie tube bit pattern.............................
- {
- // - ----------------------- Display First Nixie Tube Digit N1 --------------
- if (dig1 == 16) // write overflow to turn off all chip outputs and blank out the nixie tube.
- {
- digitalWrite(N1A, HIGH);
- digitalWrite(N1B, HIGH);
- digitalWrite(N1C, HIGH);
- digitalWrite(N1D, HIGH);
- }
- if (dig1 == 0) //write 0000
- {
- digitalWrite(N1A, LOW);
- digitalWrite(N1B, LOW);
- digitalWrite(N1C, LOW);
- digitalWrite(N1D, LOW);
- }
- if (dig1 == 1) //write 0001
- {
- digitalWrite(N1A, HIGH);
- digitalWrite(N1B, LOW);
- digitalWrite(N1C, LOW);
- digitalWrite(N1D, LOW);
- }
- if (dig1 == 2) //write 0010
- {
- digitalWrite(N1A, LOW);
- digitalWrite(N1B, HIGH);
- digitalWrite(N1C, LOW);
- digitalWrite(N1D, LOW);
- }
- if (dig1 == 3) //write 0011
- {
- digitalWrite(N1A, HIGH);
- digitalWrite(N1B, HIGH);
- digitalWrite(N1C, LOW);
- digitalWrite(N1D, LOW);
- }
- if (dig1 == 4) //write 0100
- {
- digitalWrite(N1A, LOW);
- digitalWrite(N1B, LOW);
- digitalWrite(N1C, HIGH);
- digitalWrite(N1D, LOW);
- }
- if (dig1 == 5) //write 0101
- {
- digitalWrite(N1A, HIGH);
- digitalWrite(N1B, LOW);
- digitalWrite(N1C, HIGH);
- digitalWrite(N1D, LOW);
- }
- if (dig1 == 6) //write 0110
- {
- digitalWrite(N1A, LOW);
- digitalWrite(N1B, HIGH);
- digitalWrite(N1C, HIGH);
- digitalWrite(N1D, LOW);
- }
- if (dig1 == 7) //write 0111
- {
- digitalWrite(N1A, HIGH);
- digitalWrite(N1B, HIGH);
- digitalWrite(N1C, HIGH);
- digitalWrite(N1D, LOW);
- }
- if (dig1 == 8) //write 1000
- {
- digitalWrite(N1A, LOW);
- digitalWrite(N1B, LOW);
- digitalWrite(N1C, LOW);
- digitalWrite(N1D, HIGH);
- }
- if (dig1 == 9) //write 1001
- {
- digitalWrite(N1A, HIGH);
- digitalWrite(N1B, LOW);
- digitalWrite(N1C, LOW);
- digitalWrite(N1D, HIGH);
- }
- // ------------------------- Display Second Nixie Tube Digit N2 -------------------
- if (dig2 == 0) //write 0000
- {
- digitalWrite(N2A, LOW);
- digitalWrite(N2B, LOW);
- digitalWrite(N2C, LOW);
- digitalWrite(N2D, LOW);
- }
- if (dig2 == 1) //write 0001
- {
- digitalWrite(N2A, HIGH);
- digitalWrite(N2B, LOW);
- digitalWrite(N2C, LOW);
- digitalWrite(N2D, LOW);
- }
- if (dig2 == 2) //write 0010
- {
- digitalWrite(N2A, LOW);
- digitalWrite(N2B, HIGH);
- digitalWrite(N2C, LOW);
- digitalWrite(N2D, LOW);
- }
- if (dig2 == 3) //write 0011
- {
- digitalWrite(N2A, HIGH);
- digitalWrite(N2B, HIGH);
- digitalWrite(N2C, LOW);
- digitalWrite(N2D, LOW);
- }
- if (dig2 == 4) //write 0100
- {
- digitalWrite(N2A, LOW);
- digitalWrite(N2B, LOW);
- digitalWrite(N2C, HIGH);
- digitalWrite(N2D, LOW);
- }
- if (dig2 == 5) //write 0101
- {
- digitalWrite(N2A, HIGH);
- digitalWrite(N2B, LOW);
- digitalWrite(N2C, HIGH);
- digitalWrite(N2D, LOW);
- }
- if (dig2 == 6) //write 0110
- {
- digitalWrite(N2A, LOW);
- digitalWrite(N2B, HIGH);
- digitalWrite(N2C, HIGH);
- digitalWrite(N2D, LOW);
- }
- if (dig2 == 7) //write 0111
- {
- digitalWrite(N2A, HIGH);
- digitalWrite(N2B, HIGH);
- digitalWrite(N2C, HIGH);
- digitalWrite(N2D, LOW);
- }
- if (dig2 == 8) //write 1000
- {
- digitalWrite(N2A, LOW);
- digitalWrite(N2B, LOW);
- digitalWrite(N2C, LOW);
- digitalWrite(N2D, HIGH);
- }
- if (dig2 == 9) //write 1001
- {
- digitalWrite(N2A, HIGH);
- digitalWrite(N2B, LOW);
- digitalWrite(N2C, LOW);
- digitalWrite(N2D, HIGH);
- }
- // --------------------- Display the Third Nixie Tube Digit N3 -----------
- if (dig3 == 0) //write 0000
- {
- digitalWrite(N3A, LOW);
- digitalWrite(N3B, LOW);
- digitalWrite(N3C, LOW);
- digitalWrite(N3D, LOW);
- }
- if (dig3 == 1) //write 0001
- {
- digitalWrite(N3A, HIGH);
- digitalWrite(N3B, LOW);
- digitalWrite(N3C, LOW);
- digitalWrite(N3D, LOW);
- }
- if (dig3 == 2) //write 0010
- {
- digitalWrite(N3A, LOW);
- digitalWrite(N3B, HIGH);
- digitalWrite(N3C, LOW);
- digitalWrite(N3D, LOW);
- }
- if (dig3 == 3) //write 0011
- {
- digitalWrite(N3A, HIGH);
- digitalWrite(N3B, HIGH);
- digitalWrite(N3C, LOW);
- digitalWrite(N3D, LOW);
- }
- if (dig3 == 4) //write 0100
- {
- digitalWrite(N3A, LOW);
- digitalWrite(N3B, LOW);
- digitalWrite(N3C, HIGH);
- digitalWrite(N3D, LOW);
- }
- if (dig3 == 5) //write 0101
- {
- digitalWrite(N3A, HIGH);
- digitalWrite(N3B, LOW);
- digitalWrite(N3C, HIGH);
- digitalWrite(N3D, LOW);
- }
- if (dig3 == 6) //write 0110
- {
- digitalWrite(N3A, LOW);
- digitalWrite(N3B, HIGH);
- digitalWrite(N3C, HIGH);
- digitalWrite(N3D, LOW);
- }
- if (dig3 == 7) //write 0111
- {
- digitalWrite(N3A, HIGH);
- digitalWrite(N3B, HIGH);
- digitalWrite(N3C, HIGH);
- digitalWrite(N3D, LOW);
- }
- if (dig3 == 8) //write 1000
- {
- digitalWrite(N3A, LOW);
- digitalWrite(N3B, LOW);
- digitalWrite(N3C, LOW);
- digitalWrite(N3D, HIGH);
- }
- if (dig3 == 9) //write 1001
- {
- digitalWrite(N3A, HIGH);
- digitalWrite(N3B, LOW);
- digitalWrite(N3C, LOW);
- digitalWrite(N3D, HIGH);
- }
- // ---------------------- Display the Last Nixie Tube Digit N4 -------------------
- if (dig4 == 0) //write 0000
- {
- digitalWrite(N4A, LOW);
- digitalWrite(N4B, LOW);
- digitalWrite(N4C, LOW);
- digitalWrite(N4D, LOW);
- }
- if (dig4 == 1) //write 0001
- {
- digitalWrite(N4A, HIGH);
- digitalWrite(N4B, LOW);
- digitalWrite(N4C, LOW);
- digitalWrite(N4D, LOW);
- }
- if (dig4 == 2) //write 0010
- {
- digitalWrite(N4A, LOW);
- digitalWrite(N4B, HIGH);
- digitalWrite(N4C, LOW);
- digitalWrite(N4D, LOW);
- }
- if (dig4 == 3) //write 0011
- {
- digitalWrite(N4A, HIGH);
- digitalWrite(N4B, HIGH);
- digitalWrite(N4C, LOW);
- digitalWrite(N4D, LOW);
- }
- if (dig4 == 4) //write 0100
- {
- digitalWrite(N4A, LOW);
- digitalWrite(N4B, LOW);
- digitalWrite(N4C, HIGH);
- digitalWrite(N4D, LOW);
- }
- if (dig4 == 5) //write 0101
- {
- digitalWrite(N4A, HIGH);
- digitalWrite(N4B, LOW);
- digitalWrite(N4C, HIGH);
- digitalWrite(N4D, LOW);
- }
- if (dig4 == 6) //write 0110
- {
- digitalWrite(N4A, LOW);
- digitalWrite(N4B, HIGH);
- digitalWrite(N4C, HIGH);
- digitalWrite(N4D, LOW);
- }
- if (dig4 == 7) //write 0111
- {
- digitalWrite(N4A, HIGH);
- digitalWrite(N4B, HIGH);
- digitalWrite(N4C, HIGH);
- digitalWrite(N4D, LOW);
- }
- if (dig4 == 8) //write 1000
- {
- digitalWrite(N4A, LOW);
- digitalWrite(N4B, LOW);
- digitalWrite(N4C, LOW);
- digitalWrite(N4D, HIGH);
- }
- if (dig4 == 9) //write 1001
- {
- digitalWrite(N4A, HIGH);
- digitalWrite(N4B, LOW);
- digitalWrite(N4C, LOW);
- digitalWrite(N4D, HIGH);
- }
- delay (10);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement