Good day... I am in a classic "two pins short" scenario with my current project. I am used to using shift registers for various things, and do not mind them, however this particular project is highly dependant on various libraries like OneWire and LEDControl. Is there a way to use a shift register or similar device in conjunction with a software library layer to effectively present more "Arduino pins" such that other libs can use them?
For instance, OneWire and LEDControl can all use any digital output pin. I already have an 74HC595 in this project, so imagine for a second that I am only using 4 bits of it, leaving me with 4 extras which i would rather use and free up some of my GPIOs for other things. I'd like to be able to do something like pseudo code:
// !!!!!!!! this is pseudo/discussion code!!! dont attempt to use since the library doesnt actually exist!!! #include shifterToRegularPins.h /* use BCD shift register on pins 5, 6, and 7 to map to software layered pins, eight wide, starting at 20 (winds up as 20-27); */ #define shifterLatch 5 #define shifterClock 6 #define shifterData 7 #define shifterWidth 8 #define shifterFirstSoftPin PinShifter shifter1=PinShifter(shifterLatch, shifterClock ,shifterData, shifterWidth); // Then later on down in code pinMode(20, OUTPUT); // naturally this fakepin can only be output digitalWrite(20, HIGH); //turn on this pin // use some libraries, which as long as they only use output modes, dont care that the pins are fake/software emulated/whatever OneWire ds(21); ds.begin; LedControl lc=LedControl(22,23,24,25); // use above stuff as normal
Naturally, this would be somewhat nasty on use of stack, may not work with some parts that are unforgiving on timing and so on, But for some applications, "speed to market" and freedom to choose parts is more important. In my case, it would be a time saver, since I don't get to work on electronics as much as i would like. My fallback is to change the 7-seg driver over to an i2c part, and use i2c parts for my two input buttons, but above idea sure did sound nice in my head. Perhaps my day job on general purpose computers taints me... you can always "solve" a problem by acquiring more software layers. Good ones really will save you from having to re-do the system, until you get so many that you are crushed under their weight of course!