Show Posts
|
|
Pages: [1] 2 3 ... 12
|
|
2
|
Using Arduino / Programming Questions / Nixe tube clock sketch
|
on: April 19, 2012, 08:17:49 am
|
 Hello, I'm trying to modify this piece of code originally written for a nixie tube clock. The clock uses 4 nixie tubes to show hours & minutes but I wish to add 2 extra tubes to show the seconds as well. Can someone point me in the right direction as to which parts of the code to modify and some hints on how?? /* Nixie tube demonstration code - simple clock http://tronixstuff.com - John Boxall. February 2011. Baseon on a sketch originally created by Lionel Haims, July 25, 2008. Released into the public domain. */
#include "Wire.h" #include "Nixie.h" #define DS1307_I2C_ADDRESS 0x68
// note the digital pins of the arduino that are connected to the nixie driver #define dataPin 2 // data line or SER #define clockPin 3 // clock pin or SCK #define latchPin 4 // latch pin or RCK
// note the number of digits (nixie tubes) you have (buy more, you need more!) #define numDigits 4
int narray[numDigits]; // holds the digits to display int a=0;
// Create the Nixie object // pass in the pin numbers in the correct order Nixie nixie(dataPin, clockPin, latchPin);
// Convert normal decimal numbers to binary coded decimal byte decToBcd(byte val) { return ( (val/10*16) + (val%10) ); }
// Convert binary coded decimal to normal decimal numbers byte bcdToDec(byte val) { return ( (val/16*10) + (val%16) ); }
void 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)); Wire.send(decToBcd(dayOfWeek)); Wire.send(decToBcd(dayOfMonth)); Wire.send(decToBcd(month)); Wire.send(decToBcd(year)); Wire.send(0x10); // sends 0x10 (hex) 00010000 (binary) to control register - turns on square wave Wire.endTransmission(); }
// Gets the date and time from the ds1307 void 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; pinMode(latchPin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(dataPin, OUTPUT); Wire.begin(); nixie.clear(numDigits); // clear display
// 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.
second = 45; minute = 59; hour = 23; dayOfWeek = 5; dayOfMonth = 26; month = 2; year = 11; setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year); }
void nixNum(int z) // displays integer 'z' on 4-digit nixe display // keeps leading zero, as blank still flickers somewhat { narray[0]=int(z/1000); // thousands value z=z-(narray[0]*1000); narray[1]=int(z/100); // hundreds value z=z-(narray[1]*100); narray[2]=int(z/10); // tens value narray[3]=z-(narray[2]*10); // ones value nixie.writeArray( narray, numDigits); }
void showTime() { int zzz=0; byte second, minute, hour, dayOfWeek, dayOfMonth, month, year; getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); if (bcdToDec(hour)<1) { zzz=minute; } else if (bcdToDec(hour)>=1) { zzz=hour*100; zzz=zzz+minute; } nixNum(zzz); }
void showDate() { int zzz=0; byte second, minute, hour, dayOfWeek, dayOfMonth, month, year; getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); zzz=(dayOfMonth*100)+month; nixNum(zzz); }
void loop() { showTime(); // display the time delay(1000); a++; if (a==10) { showDate(); // display the date (day and month) for two seconds delay(2000); a=1; } }
From what I understand, after changing the "define numDigits" to 6 I then need to add a "narray" 4 & 5 here? { narray[0]=int(z/1000); // thousands value z=z-(narray[0]*1000); narray[1]=int(z/100); // hundreds value z=z-(narray[1]*100); narray[2]=int(z/10); // tens value narray[3]=z-(narray[2]*10); // ones value nixie.writeArray( narray, numDigits); } and then play with the "if" statement? if (bcdToDec(hour)<1) { zzz=minute; } else if (bcdToDec(hour)>=1) { zzz=hour*100; zzz=zzz+minute; } nixNum(zzz); }
Thanks for any help at all 
|
|
|
|
|
5
|
Using Arduino / LEDs and Multiplexing / Re: Help with two 7-segment displays & pot code
|
on: May 01, 2011, 07:38:44 pm
|
 Ok, cool! Thanks AWOl. I see what you mean and corrected it. My confusion was having a mix of "dataPin" & myDataPin" etc, throughout the code. Here she is now.....
int dataPin = 11; int clockPin = 12; int latchPin = 8;
byte dataArrayRED[] = { 0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6F }; // 0 1 2 3 4 5 6 7 8 9 byte dataArray2[] = { 0x77, 0x7c, 0x39, 0x5E, 0x79, 0x71, 0x6F }; // A b C d E F g
void setup() { pinMode(latchPin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(dataPin, OUTPUT); } void loop() { int val = 10; //this is for how many digits int i = map(analogRead (0), 0, 1023, 0, 20); // Scale Selection Display int h = map(analogRead (1), 0, 1023, 0, 7); // Key Selection Display { digitalWrite(latchPin, 0);
int digit2 = i % val; int digit1 = ( i - digit2 ) / val; int digit3 = h; shiftOut(dataPin, clockPin, dataArray2[digit3]); shiftOut(dataPin, clockPin, dataArrayRED[ digit2 ]); shiftOut(dataPin, clockPin, dataArrayRED[ digit1 ]);
digitalWrite(latchPin, 1);
} }
void shiftOut( int dataPin, int clockPin, byte dataOut) {
int i=0; int pinState; digitalWrite(dataPin, 0); digitalWrite(clockPin, 0); for (i=7; i>=0; i--) { digitalWrite(clockPin, 0);
if ( dataOut & (1<<i) ) { pinState= 1; } else { pinState= 0; } //Sets the pin to HIGH or LOW depending on pinState digitalWrite(dataPin, pinState); //register shifts bits on upstroke of clock pin digitalWrite(clockPin, 1); //zero the data pin after shift to prevent bleed through digitalWrite(dataPin, 0); } digitalWrite(clockPin, 0); }
|
|
|
|
|
6
|
Using Arduino / LEDs and Multiplexing / Re: Help with two 7-segment displays & pot code
|
on: April 30, 2011, 02:45:31 pm
|
|
If I place pinMode(myClockPin, OUTPUT); & pinMode(myDataPin, OUTPUT); in set up, then I must also "int myClockPin; & int myDataPin; at the beginning of my code. I must also leave them where originally positioned under "void shiftOut" in order for the code to run correctly. But maybe this is the way it should be done??? Can they be both under "set up" and "void shiftOut" ??
|
|
|
|
|
7
|
Using Arduino / LEDs and Multiplexing / Re: Help with two 7-segment displays & pot code
|
on: April 30, 2011, 01:47:44 pm
|
 Thanks for your help AWOL & GRUMPY_MIKE.....Here's the now further simplified code for anyone who needs it and a link for "Binary to Decimal to Hexadecimal Converter" which I found useful! http://www.mathsisfun.com/binary-decimal-hexadecimal-converter.html
int dataPin = 11; int clockPin = 12; int latchPin = 8;
byte dataArrayRED[] = { 0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6F }; // 0 1 2 3 4 5 6 7 8 9 byte dataArray2[] = { 0x77, 0x7c, 0x39, 0x5E, 0x79, 0x71, 0x6F }; // A b C d E F g
void setup() { pinMode(latchPin, OUTPUT); } void loop() { int val = 10; //this is for how many digits int i = map(analogRead (0), 0, 1023, 0, 20); // Scale Selection Display int h = map(analogRead (1), 0, 1023, 0, 7); // Key Selection Display { digitalWrite(latchPin, 0);
int digit2 = i % val; int digit1 = ( i - digit2 ) / val; int digit3 = h; shiftOut(dataPin, clockPin, dataArray2[digit3]); shiftOut(dataPin, clockPin, dataArrayRED[ digit2 ]); shiftOut(dataPin, clockPin, dataArrayRED[ digit1 ]);
digitalWrite(latchPin, 1);
} } void shiftOut( int myDataPin, int myClockPin, byte myDataOut) {
int i=0; int pinState; pinMode(myClockPin, OUTPUT); pinMode(myDataPin, OUTPUT); digitalWrite(myDataPin, 0); digitalWrite(myClockPin, 0); for (i=7; i>=0; i--) { digitalWrite(myClockPin, 0);
if ( myDataOut & (1<<i) ) { pinState= 1; } else { pinState= 0; } //Sets the pin to HIGH or LOW depending on pinState digitalWrite(myDataPin, pinState); //register shifts bits on upstroke of clock pin digitalWrite(myClockPin, 1); //zero the data pin after shift to prevent bleed through digitalWrite(myDataPin, 0); } digitalWrite(myClockPin, 0); }
|
|
|
|
|
8
|
Using Arduino / LEDs and Multiplexing / Re: Help with two 7-segment displays & pot code
|
on: April 30, 2011, 07:27:18 am
|
 Hello there. This is the result of my understand so far on using the "if" statement..... if ((i==2) && (h==2)){ mapMode == 11; syncPhaseInc = mapPentatonic11(analogRead(SYNC_CONTROL)); } it's working for me. And yes I managed to get three 7-segment displays working together. Two with one pot to select a musical scale (0-99 "i") and a separate one to select the key of that scale (A-G "h"). In case anyone has a need for something similar here it is (three 7-segment common cathode displays using three 595's).
int dataPin = 11; int clockPin = 12; int latchPin = 8;
byte dataRED; byte dataArrayRED[10]; byte dataArray2[7];
void setup() { pinMode(latchPin, OUTPUT);
dataArrayRED[0] = 0x3F; //00111111 - 0 dataArrayRED[1] = 0x06; //00000110 - 1 dataArrayRED[2] = 0x5B; //01011011 - 2 dataArrayRED[3] = 0x4F; //01001111 - 3 dataArrayRED[4] = 0x66; //01100110 - 4 dataArrayRED[5] = 0x6D; //01101101 - 5 dataArrayRED[6] = 0x7D; //01111101 - 6 dataArrayRED[7] = 0x07; //00000111 - 7 dataArrayRED[8] = 0x7F; //01111111 - 8 dataArrayRED[9] = 0x6F; //01100111 - 9 // Key Selection dataArray2[0] = B01110111; // A Check display wiring, this has been modified! dataArray2[1] = B01111100; // b dataArray2[2] = B00111001; // C dataArray2[3] = B01011110; // d dataArray2[4] = B01111001; // E dataArray2[5] = B01110001; // F dataArray2[6] = B01101111; // g } void loop() { int val = 10; //this is for how many digits int i = map(analogRead (0), 0, 1023, 0, 20); // Scale Selection Display int h = map(analogRead (1), 0, 1023, 0, 7); // Key Selection Display { digitalWrite(latchPin, 0);
int digit2 = i % val; int digit1 = ( i - digit2 ) / val; int digit3 = h; shiftOut(dataPin, clockPin, dataArray2[digit3]); shiftOut(dataPin, clockPin, dataArrayRED[ digit2 ]); shiftOut(dataPin, clockPin, dataArrayRED[ digit1 ]);
digitalWrite(latchPin, 1);
} } void shiftOut( int myDataPin, int myClockPin, byte myDataOut) {
int i=0; int pinState; pinMode(myClockPin, OUTPUT); pinMode(myDataPin, OUTPUT); digitalWrite(myDataPin, 0); digitalWrite(myClockPin, 0); for (i=7; i>=0; i--) { digitalWrite(myClockPin, 0);
if ( myDataOut & (1<<i) ) { pinState= 1; } else { pinState= 0; } //Sets the pin to HIGH or LOW depending on pinState digitalWrite(myDataPin, pinState); //register shifts bits on upstroke of clock pin digitalWrite(myClockPin, 1); //zero the data pin after shift to prevent bleed through digitalWrite(myDataPin, 0); } digitalWrite(myClockPin, 0); }
|
|
|
|
|
10
|
Using Arduino / LEDs and Multiplexing / Re: Help with two 7-segment displays & pot code
|
on: April 23, 2011, 01:19:03 pm
|
|
I tried that ...if(j== map(analogRead (0), 0, 1023, 0, 10))....and she stays stuck on zero! For the code that I have it only works this way...if(j= map(analogRead (0), 0, 1023, 0, 10));
|
|
|
|
|
12
|
Using Arduino / LEDs and Multiplexing / Re: Help with two 7-segment displays & pot code
|
on: April 23, 2011, 12:07:38 pm
|
 Yes, I am getting the zero that I wanted now. I see your point though, essentially its still the same no? and I thought for a moment there, I knew what I was doing!!!!!  However, I was getting the zero before but only when the sketch uploaded and when the pot was at one extreme. As soon as I swept the pot up and down, "1" was the minimum that I could get! So the small change I made appeared to have solved this. After that, I took out other parts of the code that didn't appear to be needed and ended up with this... //**************************************************************// // Name : shiftOutCode, Predefined Array Style // // Author : Carlyn Maw, Tom Igoe // // Date : 25 Oct, 2006 // // Version : 1.0 // // Notes : Code for using a 74HC595 Shift Register // // : to count from 0 to 255 // //****************************************************************
//Pin connected to ST_CP of 74HC595 int latchPin = 8; //Pin connected to SH_CP of 74HC595 int clockPin = 12; ////Pin connected to DS of 74HC595 int dataPin = 11; int j; //holders for infromation you're going to pass to shifting function byte data; byte dataArray[10];
void setup() { //set pins to output because they are addressed in the main loop pinMode(latchPin, OUTPUT); Serial.begin(9600);
dataArray[0] = 0x3F; // 0 dataArray[1] = 0x06; // 1 dataArray[2] = 0x5B; // 2 dataArray[3] = 0x4F; // 3 dataArray[4] = 0x66; // 4 dataArray[5] = 0x6D; // 5 dataArray[6] = 0x7C; // 6 dataArray[7] = 0x07; // 7 dataArray[8] = 0x7F; // 8 dataArray[9] = 0x67; // 9
}
void loop(){
if (j= map(analogRead (0), 0, 1023, 0, 10)); { data = dataArray[j]; //ground latchPin and hold low for as long as you are transmitting digitalWrite(latchPin, 0); //move 'em out shiftOut(dataPin, clockPin, data); //return the latch pin high to signal chip that it //no longer needs to listen for information digitalWrite(latchPin, 1);
} }
// the heart of the program void shiftOut(int myDataPin, int myClockPin, byte myDataOut) { // This shifts 8 bits out MSB first, //on the rising edge of the clock, //clock idles low
//internal function setup int pinState; pinMode(myClockPin, OUTPUT); pinMode(myDataPin, OUTPUT);
//clear everything out just in case to //prepare shift register for bit shifting digitalWrite(myDataPin, 0); digitalWrite(myClockPin, 0);
//for each bit in the byte myDataOut? //NOTICE THAT WE ARE COUNTING DOWN in our for loop //This means that %00000001 or "1" will go through such //that it will be pin Q0 that lights. for (j=7; j>=0; j--) { digitalWrite(myClockPin, 0);
//if the value passed to myDataOut and a bitmask result // true then... so if we are at i=6 and our value is // %11010100 it would the code compares it to %01000000 // and proceeds to set pinState to 1. if ( myDataOut & (1<<j) ) { pinState= 1; } else { pinState= 0; }
//Sets the pin to HIGH or LOW depending on pinState digitalWrite(myDataPin, pinState); //register shifts bits on upstroke of clock pin digitalWrite(myClockPin, 1); //zero the data pin after shift to prevent bleed through digitalWrite(myDataPin, 0); }
//stop shifting digitalWrite(myClockPin, 0);
}
|
|
|
|
|
13
|
Using Arduino / LEDs and Multiplexing / Re: Help with two 7-segment displays & pot code
|
on: April 23, 2011, 04:03:30 am
|
:)Cool!! Thanks for your help AWOL!! This what I did void loop(){
if (j= map(analogRead (0), 0, 1024, 0, 10)); { data = dataArray[j]; //ground latchPin and hold low for as long as you are transmitting digitalWrite(latchPin, 0); //move 'em out shiftOut(dataPin, clockPin, data); //return the latch pin high to signal chip that it //no longer needs to listen for information digitalWrite(latchPin, 1);
}
|
|
|
|
|