help with code for mega 2560 and maxim 7218 c chip

So i have ask this question How do I code a write thru the Adruino to a ICM7218 c ver chip to say "send the address for a digit and then send the val or data to say # 9"? I can send using the long method (see code below) but I need to send a value not just turn on or off the led segments. Code: // Arduino digital pins used to light up // corresponding segments on the LED display

define ID0 2 //DATA 0 - 3

define ID1 3 // adruino pins 2,3,4,5,10,11,12 and 8

define ID2 4

define ID3 5

define AD0 12 // ADDRESS 0- 2

define AD1 11

define AD2 10

define WRITE 8

// Common anode; // on when pin is low // and off when pin is high

define ON HIGH

define OFF LOW

void setup() { pinMode(ID0, OUTPUT); pinMode(ID1, OUTPUT); pinMode(ID2, OUTPUT); pinMode(ID3, OUTPUT);

pinMode(AD0, OUTPUT); pinMode(AD1, OUTPUT); pinMode(AD2, OUTPUT);

pinMode(WRITE,OUTPUT); }

void loop() { digitalWrite(ID0, ON); // WRITE # 9 digitalWrite(ID1, OFF); digitalWrite(ID2, OFF); digitalWrite(ID3, ON);

digitalWrite(AD0, OFF); // ADDRESS DIGIT 1 digitalWrite(AD1, OFF); digitalWrite(AD2, OFF);

digitalWrite(WRITE, ON); // PULSE THE WRITE PIN delay(10); digitalWrite(WRITE,OFF); }

This works but as you can see it's not what I need to do. How do I combine the two values to say address= digit 1, data= #9????? Any suggestions ? thanks Ron.

You could try something like

void icm7218c(int digit,int datum)
{  digitalWrite(ad0,1 & digit);
   digitalWrite(ad1,1 & (digit >> 1));
   digitalWrite(ad2,1 & (digit >> 2));
   digitalWrite(id0,1 & datum);
   digitalWrite(id1,1 & (datum >> 1));
   digitalWrite(id2,1 & (datum >> 2));
   digitalWrite(id3,1 & (datum >> 3));
   digitalWrite(write,HIGH);
   delay(1);
   digitalWrite(write,LOW);
}

void setup(void)
{  /* unchanged */
}

void loop(void)
{
   icm7218c(0,9);

   while (1);
}

(A link to the icm7218c data sheet would have been a welcome courtesy.)

So Sorry for not linking the data sheet, I didn’t think it mattered, BUT you have answered my question, THANK YOU ever so much, I can now move on. one more question. here " void loop() {

icm7218c(0,9);

while (1);"
this is where I would put the VALUE from say an encoder (digi pot) to the line " icm7218c(0,9);" I assume 0 is the digit, 9 is the val or number. So if you don’t mind, how can I say, in code, digit 1 gets data 0-9 then digit 2 get data 0-9 and so on to have 5 digits read a value of say 121.50 I am building a flight simm control panel for the comms radio…am I asking to much??? Again thank you. Ron.

You can't ask too much - the forum exists to answer questions. You can help people to help you by including the info they need to formulate an answer.

In what form do you get/have the information from your digital encoder? That makes a difference in how one might choose to call this function to do the output. (As you might have noticed, it will handle char digits as well a int digits.)

This is quick and dirty, and assumes that your encoder value is an int >= 0:

void numout(int n)
{  int pos = 7;
   do
   {  icm7218c(pos,n % 10);
      n /= 10;
   }  while (pos--);
}

Insert this function immediately after the end of the icm7218c() function.

OOps! My bad. I missed that your encoder reading is a float value. How do we get the display to show a decimal point?

The decimal point is not important, IE I don't need to display it, I just put it here to show the Number, 12150 would do. As for the encoder , well I don't know yet, It would just be a VALUE read from the encoder, as it send numbers or what ever out, the display would read the value, I think, I am not all that together yet on all this. I will work with the info you have given me and see where I end up, I'll not post again until I have done more work, Thank you for your time and advise on this, It has been a real problem for me. Please keep a eye out on this topic as I will have more to the point questions. Thank you, Ron.

[quote author=Morris Dovey link=topic=88234.msg663046#msg663046 date=1327271598] This is quick and dirty, and assumes that your encoder value is an int >= 0:

void numout(int n)
{  int pos = 7;
   do
   {  icm7218c(pos,n % 10);
      n /= 10;
   }  while (pos--);
}

Insert this function immediately after the end of the icm7218c() function.

[/quote]

// Arduino digital pins used to light up
// corresponding segments on the LED display
#define ID0 2 //DATA 0 - 3 
#define ID1 3
#define ID2 4
#define ID3 5

#define AD0 12  // ADDRESS 0- 2
#define AD1 11
#define AD2 10
#define WRITE 8

// Common anode;
// on when pin is low
// and off when pin is high
#define ON HIGH
#define OFF LOW

void icm7218c(int digit,int datum)
{  digitalWrite(AD0,1 & digit);
   digitalWrite(AD1,1 & (digit >> 1));
   digitalWrite(AD2,1 & (digit >> 2));
   digitalWrite(ID0,1 & datum);
   digitalWrite(ID1,1 & (datum >> 1));
   digitalWrite(ID2,1 & (datum >> 2));
   digitalWrite(ID3,1 & (datum >> 3));
   digitalWrite(WRITE,HIGH);
   delay(1);
   digitalWrite(WRITE,LOW);
}
 void numout(int n)
{  int pos = 7;
   do
   {  icm7218c(pos,n % 10);
      n /= 10;
   }
   while (pos--);
   
}        



void setup() {
  pinMode(ID0, OUTPUT);
  pinMode(ID1, OUTPUT);
  pinMode(ID2, OUTPUT);
  pinMode(ID3, OUTPUT);
  
  pinMode(AD0, OUTPUT);
  pinMode(AD1, OUTPUT);
  pinMode(AD2, OUTPUT);
  
  pinMode(WRITE,OUTPUT);
}

void loop() {

  
  
     // icm7218c(2,4);
      // icm7218c(3,3);
      //  icm7218c(2,4);
      //   icm7218c(1,8);
      //    icm7218c(0,7);



  while (1);

}

So i did this and nothing happend see below, did I put it in the right place, do I need to give "n" a value? I don't follow...??

You’ll need to actually invoke the numout() fuction and pass it a value. In loop(), add the line

   numout(12150);

and (I finally took a look at the data sheet) swap the HIGH and LOW values used to strobe the WRITE line in icm7218c() because I made a bad guess. (sorry).

Hi again. I wish to thank you once again for your time and the code you have given me. :) I now have it working, however I had to do a LOT of tweeks to get it to go. 1st I had to change the Pos value to 4 from 7 as it did not light up the digits correct. 2nd If in the numout call I said 12345 it displayed 54321 But I just swaped the digit anodes to start at the left, not thr right and all is well. See the code below. I still have a very long way to go but I'am happy today. Thank you. Ron.

// Arduino digital pins used to light up
// corresponding segments on the LED display
// Ron Buchwald** BUCHTRONICS LLC
// REV 1 1/23/2012  10:AM
#define ID0 42//2 //DATA 0 - 3 
#define ID1 44//3
#define ID2 46//4
#define ID3 48//5
#define AD0 12  // ADDRESS 0- 2
#define AD1 11
#define AD2 10
#define WRITE 8
#define encoder0PinA  2
#define encoder0PinB  4
volatile unsigned int encoder0Pos = 0;
// Common anode;
// on when pin is low
// and off when pin is high
#define ON HIGH
#define OFF LOW
void icm7218c(int digit,int datum)
{  digitalWrite(AD0,1 & digit);
   digitalWrite(AD1,1 & (digit >> 1));
   digitalWrite(AD2,1 & (digit >> 2));
   digitalWrite(ID0,1 & datum);
   digitalWrite(ID1,1 & (datum >> 1));
   digitalWrite(ID2,1 & (datum >> 2));
   digitalWrite(ID3,1 & (datum >> 3));
   digitalWrite(WRITE,HIGH);
   delay(10);
   digitalWrite(WRITE,LOW);
}
 void numout(int n)
{  int pos = 4;
   do
   {  icm7218c(pos,n % 10);
      n /= 10;
   }
   while (pos--);
}        
void setup() {
  pinMode(ID0, OUTPUT);
  pinMode(ID1, OUTPUT);
  pinMode(ID2, OUTPUT);
  pinMode(ID3, OUTPUT);
  pinMode(AD0, OUTPUT);
  pinMode(AD1, OUTPUT);
  pinMode(AD2, OUTPUT);
  pinMode(WRITE,OUTPUT);
  
  pinMode(encoder0PinA, INPUT); 
  digitalWrite(encoder0PinA, HIGH);       // turn on pullup resistor
  pinMode(encoder0PinB, INPUT); 
  digitalWrite(encoder0PinB, HIGH);       // turn on pullup resistor

  attachInterrupt(0, doEncoder, CHANGE);  // encoder pin on interrupt 0 - pin 2
  Serial.begin (9600);
  Serial.println("start");                // a personal quirk
}
void loop() {
   encoder0Pos = constrain(encoder0Pos, 11800, 13600);
        numout(encoder0Pos);
    }
  void doEncoder() {
  /* If pinA and pinB are both high or both low, it is spinning
   * forward. If they're different, it's going backward.
   * For more information on speeding up this process, see
   * [Reference/PortManipulation], specifically the PIND register.
   */
  if (digitalRead(encoder0PinA) == digitalRead(encoder0PinB)) {
    encoder0Pos++;
  } else {
    encoder0Pos--;
  }
      Serial.println (encoder0Pos, DEC);
  }