Go Down

### Topic: Multiplexing Nixie tubes Need help with writing code. (Read 1 time)previous topic - next topic

#### Eric1180

##### May 04, 2011, 07:40 pmLast Edit: May 04, 2011, 07:43 pm by Eric1180 Reason: 1
Hi i want to Multiplex 4 Nixie tubes connected in series at the cathodes. And i plan on turning on each separately at the anode with a Hv NpN transistor. I am using a 71414 BCD driver but i only have one... it's a long story
What i need help with is i don't know how to separate the the minutes and hours.
I am basing my sketch off of a RTC sketch.
So by using Driver(minute, DEC) or Driver(hour, DEC) i would send the number i want out

Well i would like to do that but i need to separate the minutes and hours to where i have 2 one digits number
So say it 12:56
well i don't want it to send 12 and 56 to the BCD driver i want it to send

1 ... First nix on.
Off
2 ... Second nix on.
Off
5 ... Third nix on.
Off
6 ... Forth nix on.

Sorry i will include some code i am using but right now i am away from my home computer

#### AWOL

#1
##### May 04, 2011, 08:34 pmLast Edit: May 04, 2011, 08:50 pm by AWOL Reason: 1
How about the / and % operators?

If you don't know about the % operator, then you can get by with just / and *
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

#### Eric1180

#2
##### May 05, 2011, 04:36 am

How about the / and % operators?

If you don't know about the % operator, then you can get by with just / and *

Ok i first looked at most of the reference  section to see if the was something basic i could understand to fit my need before i posted.

So how exactly do i split 56 (minutes) into 6 for ones
and then 5 for tens?
this is for a clock so the numbers do change

#### AWOL

#3
##### May 05, 2011, 08:43 am
Quote
So how exactly do i split 56 (minutes) into 6 for ones
and then 5 for tens?

The usual way. by dividing by ten.
Unless the value is in BCD, in which case, divide by 16.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

#### Eric1180

#4
##### May 09, 2011, 05:17 am

Quote
So how exactly do i split 56 (minutes) into 6 for ones
and then 5 for tens?

The usual way. by dividing by ten.
Unless the value is in BCD, in which case, divide by 16.

ok thanks for taking the time to post but i think you over simplified it.
after 2 hour i finally figured out a formula that would separate time 12:56 in to (1-:--)(-2:--)(--:5-)(--:-6)

so the what i created was

Ten = minute / 10;  That gave me the (--:5-)

val = minute / 10;
One = minute - (val*10);   That gave me the (--:-6)

Code: [Select]
`#include <LiquidCrystal.h>#include "Wire.h"#define DS1307_I2C_ADDRESS 0x68LiquidCrystal lcd(12, 11, 5, 4, 3, 2);int Anode1 = 1;int Anode2 = 2;int Anode3 = 3;int Anode4 = 4;int latchPin = 8;//Pin connected to SH_CP of 74HC595int clockPin = 12;////Pin connected to DS of 74HC595int dataPin = 11;int One;int Ten;int Hundred;int Thousand;int Aval;int Bval;// Convert normal decimal numbers to binary coded decimalbyte decToBcd(byte val){  return ( (val/10*16) + (val%10) );}// Convert binary coded decimal to normal decimal numbersbyte bcdToDec(byte val){  return ( (val/16*10) + (val%16) );}// Stops the DS1307, but it has the side effect of setting seconds to 0// Probably only want to use this for testing/*void stopDs1307(){  Wire.beginTransmission(DS1307_I2C_ADDRESS);  Wire.send(0);  Wire.send(0x80);  Wire.endTransmission();}*/// 1) Sets the date and time on the ds1307// 2) Starts the clock// 3) Sets hour mode to 24 hour clock// Assumes you're passing in valid numbersvoid setDateDs1307(byte second,        // 0-59                   byte minute,        // 0-59                   byte hour,          // 1-23                   byte dayOfWeek,     // 1-7                   byte dayOfMonth,    // 1-28/29/30/31                   byte month,         // 1-12                   byte year)          // 0-99{   Wire.beginTransmission(DS1307_I2C_ADDRESS);   Wire.send(0);   Wire.send(decToBcd(second));    // 0 to bit 7 starts the clock   Wire.send(decToBcd(minute));   Wire.send(decToBcd(hour));      // If you want 12 hour am/pm you need to set                                   // bit 6 (also need to change readDateDs1307)   Wire.send(decToBcd(dayOfWeek));   Wire.send(decToBcd(dayOfMonth));   Wire.send(decToBcd(month));   Wire.send(decToBcd(year));   Wire.endTransmission();}// Gets the date and time from the ds1307void getDateDs1307(byte *second,          byte *minute,          byte *hour,          byte *dayOfWeek,          byte *dayOfMonth,          byte *month,          byte *year){  // Reset the register pointer  Wire.beginTransmission(DS1307_I2C_ADDRESS);  Wire.send(0);  Wire.endTransmission();  Wire.requestFrom(DS1307_I2C_ADDRESS, 7);  // A few of these need masks because certain bits are control bits  *second     = bcdToDec(Wire.receive() & 0x7f);  *minute     = bcdToDec(Wire.receive());  *hour       = bcdToDec(Wire.receive() & 0x3f);  // Need to change this if 12 hour am/pm  *dayOfWeek  = bcdToDec(Wire.receive());  *dayOfMonth = bcdToDec(Wire.receive());  *month      = bcdToDec(Wire.receive());  *year       = bcdToDec(Wire.receive());}void setup(){  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;  Wire.begin();  Serial.begin(9600);  // Change these values to what you want to set your clock to.  // You probably only want to set your clock once and then remove  // the setDateDs1307 call.0000000000000000000  second = 0;  minute = 0;  hour = 0;  dayOfWeek = 0;  dayOfMonth = 0;  month = 0;  year = 0;  pinMode(latchPin, OUTPUT);  pinMode(clockPin, OUTPUT);  pinMode(dataPin, OUTPUT);  pinMode(Anode1, OUTPUT);  pinMode(Anode2, OUTPUT);  pinMode(Anode3, OUTPUT);  pinMode(Anode4, OUTPUT);}void loop(){      // print the number of seconds since reset:  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;  getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);  Serial.print(hour, DEC);  Serial.print(":");  Serial.print(minute, DEC);  Serial.print(":");  Serial.print(second, DEC);  Serial.print("  ");  Serial.print(month, DEC);  Serial.print("/");  Serial.print(dayOfMonth, DEC);  Serial.print("/");  Serial.print(year, DEC);  Serial.print("  Day_of_week:");  Serial.print(dayOfWeek, DEC);  Serial.print("  ");  Serial.print(Thousand, DEC);  Serial.print(Hundred, DEC);  Serial.print(Ten, DEC);   Serial.print(One, DEC);  Serial.print("  ");  Serial.println(One, BIN);    Thousand = hour / 10;  Aval = hour / 10;  Hundred = hour - (Aval*10);  Ten = minute / 10;  Bval = minute / 10;  One = minute - (Bval*10);          digitalWrite(latchPin, LOW);    shiftOut(dataPin, clockPin, MSBFIRST, Thousand);      digitalWrite(latchPin, HIGH);    digitalWrite(Anode1, HIGH);    delay(1);    digitalWrite(Anode1, LOW);        digitalWrite(latchPin, LOW);    shiftOut(dataPin, clockPin, MSBFIRST, Hundred);      digitalWrite(latchPin, HIGH);    digitalWrite(Anode2, HIGH);    delay(1);    digitalWrite(Anode2, LOW);        digitalWrite(latchPin, LOW);    shiftOut(dataPin, clockPin, MSBFIRST, Ten);      digitalWrite(latchPin, HIGH);    digitalWrite(Anode3, HIGH);    delay(1);    digitalWrite(Anode3, LOW);        digitalWrite(latchPin, LOW);    shiftOut(dataPin, clockPin, MSBFIRST, One);      digitalWrite(latchPin, HIGH);    digitalWrite(Anode4, HIGH);    delay(1);    digitalWrite(Anode4, LOW);}`

Go Up