3

I am currently reading a DS1307 adafruit breakout board and I need to drive two nixie tubes from a shift register. The shift register is running two 74141 IC chips. I have code that loops through all the nixie digits one at a time with a delay of 1 second between each. Now I need to write some code to pull min, hour, and second and change the shift register low/high outputs to display the correct nixie digit. I have the DS1307 returning the correct time on my com by using

 Serial.print(now.hour(), DEC);
 Serial.print(now.minute(), DEC);
 Serial.print(now.second(), DEC);

However, I am not sure how to dimension a string, set that string equal to the two digits on the hour, minute, or time, and then divide the two digits and write if statements to correctly display the tubes. I am used to VB.NET and now C coding.

=======================UPDATE=======================

I am using this code to set any individual digit of the nixie tube to on.

       //Turn on 0
 sr.set(4, LOW);
 sr.set(5, LOW);
 sr.set(6, LOW);
 sr.set(7, LOW);

The sr is the shift register and each number is which leg of the shift register I am turning low or high. This specific piece turns on the digit 0.

  • There's no reason at all to develop strings if what you need are digits. What bit patterns do you need to output to turn on different digits? Ie, what is the interface to the nixies? – James Waldby - jwpat7 Nov 13 '16 at 23:20
  • The nixies have an anode positive leg and then a cathode leg for each digit. The 74141 just swaps out which cathode to run to gnd. I will update some code that shows how I turn a number on or off. – Cheddar Nov 13 '16 at 23:26
  • @jwpat7 All i need is to read the minute and say if the minute time is 12 then change one tube to a HIGH/LOW pattern to display 1 and the other for 2. – Cheddar Nov 13 '16 at 23:30
0

You can set up an array containing the bit patterns to turn on different digits, and then use code that sends the bits for the high digit of now.hour()/12 and the bits for the low digit of now.hour()%12. For example:

const byte digiBits[] = { B0000, B0001, 
// and so forth for all the digits ...
};

void send1Digit(byte digiVal, byte whichDigit) {
  // somehow use whichDigit to direct the bits someplace...

  // To send the bits:
  byte bits = digiBits[digiVal];
  for (byte i=4; i<8; ++i) {
    sr.set(i, bits & 1);  // Set a bit in SR to 0 or 1
    bits >>= 1; // shift out the used bit
  }
}

void send2Digits(byte numVal, byte whichDigit) {
  send1Digit(numVal/10, whichDigit);
  send1Digit(numVal%10, whichDigit+1);
}

void loop() {
  // other stuff, then:
  send2Digits(now.hour(), HourSpot);
  send2Digits(now.minute(), MinuteSpot);
  send2Digits(now.second(), SecondSpot);
  // other stuff ...
}

Note 1: If your sr.set() routine is doing any complicated masking or shifting, you may be able to avoid some of that by ORing digiBits[digiVal] with whatever number sr.set() might be building up to shift out.

Note 2: If the numerical value of digiBits[digiVal] is equal to digiVal, then don't bother defining digiBits[], but instead in send1Digit() just say byte bits = digiVal, or use digiVal directly in place of bits.

  • After days of trying i got it to work. This way probs works but my way is how i had to end up doing it. – Cheddar Nov 29 '16 at 4:25
  • @Cheddar, ok, good you got it to work – James Waldby - jwpat7 Nov 29 '16 at 5:05
  • Yea, a noob question though, I want to upload my code to show how i got it. Instead of doing indentations can I use come kind of bracket. I am having a hard time putting arduino code into the textboxes on this site. – Cheddar Nov 29 '16 at 5:08
  • @Cheddar, copy & paste your code into the question edit box, then select it and press Ctrl-K. That is, highlight the code with mouse (or by placing cursor at start of code, and holding down shift while moving cursor to end of code); then press ctrl-K or click the {} icon in edit tools bar. This marks the code as code. ¶ Note, you can make the edit box bigger by dragging the bottom bar of it downward. Makes code easier to see while editing. ¶ If your code is indented ok as you wrote it, it should be ok as pasted, except that tabs don't expand, so select 'tabs as spaces' in your editor – James Waldby - jwpat7 Nov 29 '16 at 5:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.