I have been working on ESP8266 basic for some time now and one of the goals is never to have to declare what pin is to be used or the type of input or output before using it.
Currently I have implemented some hokey code to do this but think it could be improved with a universal function.
The idea would be to have a global array that catalogs what a pin is set as (digital read, digital write, pwm out, pwm in, servo, ect) and the last value sent to that pin (high/low, servo degrees, pwm , ect)
I am a bit foggy as to how to take a pin out of an existing state. With servos you can atach() and detach() them. With PWM out it seems tat you have to set it to 0 before doing a digital write or re purposing the pin for servo out put. Because it is an interpreter it must be able to do this on the fly as needed.
Is any one familiar enough with how all this works to help out a bit in creating such a function. It would be a tremendous help.
Hopefully this could be extended to handle things like tone and other arduino i/o functions as time goes on handling all the code to disengage a previous pin setting or request from a pin if necessary.
Some thing like:
int PinManagmentVar[20][2];
float UniversalPinIO(String PinCommand, byte pin, float PinValue)
{
....
}
to be able to be called in a similar fashion as follows:
bla = UniversalPinIO("pwmin",pin,0) // return the value from the pin
bla = UniversalPinIO("pwmout",pin,0) // Set the pin to the desired value and return the value sent
bla = UniversalPinIO("digitalwrite",pin,0) // Set the pin to the desired value and return the value sent.
bla = UniversalPinIO("digitalread",pin,0) // return the value from the pin
bla = UniversalPinIO("servo",pin,90) //set servo to 90 degrees and return the value sent
http://esp8266basic.com
A BASIC interpreter for your ESP
Working now on Autodrop3d. A 3d printer with automatic part ejection system. https://autodrop3d.com