I am working on a project that will use a MAX6959 to print onto 2 2-digit 7 segment displays. I am in the process of writing a library for it, but I don't exactly know what I am doing. Lets say I want the display to be able to print from 0-9999. How do I put that in the library? Do I have to code each number and each digit individually?
The purpose of having a library is for someone including the author to reuse the code in other projects, other than the original project the code came from. It sounds to me that you have some confusion on how to make some code into library. You can share the code here for some critique. I would wager you are better off with coding a function call
display_on_max6959(int number);
essentially a function call that takes a number (0-9999) and displays it on the displays.
If you already have the code, you don't have to make it into a library right away. Modify your code for your intended library users before making it into a library or others that use your first version will complain when you changed everything in your second version.
if possible you should try to write the library in such a way that you have a constructor or a begin() method that defines the pins used.
Also check if you can make the lib work for other 7 seg displays. with one, 2 or 4 or more segments.
What I also would like is the ability to concat 2 or 3 of them
max69.begin(int digits, int pins[]); // number of digits
max69.print(int number); // see liudr's post
max69.on();
max69.off(); // switch off
and of course ...
x = max69.read(); // to read the current number displayed
max69.shiftright("1234567890"); // and of course the left variation to
max69.flip(); // rotates the number 180 degrees on the 7 segment display, never seen but can be done.
max69.write(int number, HEX);
It depends on how you intend to structure the library. Library routines are simply most basic / often used routines that can be reconfigured / called by the users. So in this case, you need to
provide a way for the user to reconfigure the pins to communicte with the chip to perform certain functions; and
define and implement basic functions.
Which functions to implement and how to implement such functions depend on your specific chip and your desired ways to communicate with such chips.
For example, in this case, you will need the following routines:
low level routines: send a byte to mx6959; read a byte from max6959;
mid level routines: using the above routines, write a byte to an address; write a string to a starting address; read a byte from an address;
high level routines: using the above routines, initialize the chip; write segment information to a segment; set the chip for certain functions (brightness, etc.)).
Your user code will likely just call the high level routines so you can prototype them into a header file.
robtillaart:
if possible you should try to write the library in such a way that you have a constructor or a begin() method that defines the pins used.
Also check if you can make the lib work for other 7 seg displays. with one, 2 or 4 or more segments.
What I also would like is the ability to concat 2 or 3 of them
max69.begin(int digits, int pins[]); // number of digits
max69.print(int number); // see liudr's post
max69.on();
max69.off(); // switch off
and of course ...
x = max69.read(); // to read the current number displayed
max69.shiftright("1234567890"); // and of course the left variation to
max69.flip(); // rotates the number 180 degrees on the 7 segment display, never seen but can be done.
max69.write(int number, HEX);
Probably not necessary to define pins but define I2C addresses and number of max6959 on the I2C bus instead? This gives the begin method the actual setup of your hardware so if you display number on it, the print on display function knows which digit to send where. You will still need a begin to clear the display.