Can i use function instead pin number?

Hello,

Is there any way to use a function call instead of a pin number?

Suppose I want to use the LiquidCrystal library. To use it I have to declare which pins will be used: "LiquidCrystal (rs, enable, d4, d5, d6, d7)". How can I assign "abcd ();" instead of the usual int which will be the pin number?

I could work around it by bridging two pins and set one of them as rs and the other as digitalRead. In this case, the library would set the pin state to high and at this point the second pin could read this state and run the function, but I'm looking for a more elegant solution.

One way would be to create the LiquidCrystal object dynamically at runtime.

I am not clear exactly what you want to do and why. Please give an example of how the LiquidCrystal constructor would look if you could do what you want ?

I tried to make sense of this and I can only think the OP wants to do something (call abcd) if the library uses the reset line.

In any case, when does the rs input get used? It isn’t something done explicitly in any higher level code, at least I don’t remember seeing it go by.

a7

Maybe I'm thinking wrong. I am trying to repair a board whose microcontroller has broken, and they have not been producing them for several years. The manufacturer of the device ran out of pins, so he started multiplexing them. In order to physically activate the RS pin, it is necessary to set the appropriate high and low states on several outputs. Only then you can try to run the rs pin. To do it the easiest way, I decided to use a function after which I will set the appropriate states and finally the state of the rs pin.

Judging by your reaction, I am doing something wrong, so how do I do it?
Maybe someone has some other idea.

might be helpful to see a schematic

the lcd data pins could be reconfigured (i.e. input/output) in between LCD accesses for other purposes as long as their configuration is restored before the next LCD access.

for example, the same data pins could be used for a 2nd LCD as long as the LCD enable pins are unique

That's Nonsense.

@thorourd, if you absolutely must initialize the LCD at runtime, then use dynamic allocation as I suggested way back in Post #2. Something like this:

#include <LiquidCrystal.h>
LiquidCrystal *displayPtr;

void setup() {
  // do stuff here to set up rs pin at run time
  displayPtr = new LiquidCrystal(rs, enable, d4, d5, d6, d7);
}

void loop() {
}

or:

#include <LiquidCrystal.h>
LiquidCrystal *displayPtr;

void setup() {
  displayPtr = new LiquidCrystal(functionThatSetsUpRsPinAndReturnsAnInteger(), enable, d4, d5, d6, d7);
}

void loop() {
}

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.