In all the examples use the library OneWire, pin control 1-Ware bus is given explicitly when compiling sketch.
Can I change pin from a program?
Ogogon.
In all the examples use the library OneWire, pin control 1-Ware bus is given explicitly when compiling sketch.
Can I change pin from a program?
Ogogon.
It's just a variable:
#include <OneWire.h>
/* DS18S20 Temperature chip i/o */
OneWire ds(10); // on pin 10
void setup(void) {
Serial.begin(9600);
}
Instead of 10 use x, where x can change.
Ah, I see the problem, it is in the constructor. Well you could fiddle around and change the library a bit.
Do something like make the constructor take no arguments. Then make a "begin" function that does what the constructor used to do. And call ds.begin (x) where x is the pin you want to use.
I had to slightly modify the library.
Remove from the constructor initialization pin to the function.
OneWire::OneWire( uint8_t pinArg)
{
pinset (pinArg);
}
void OneWire::pinset (uint8_t pinArg)
{
pin = pinArg;
port = digitalPinToPort (pin);
bitmask = digitalPinToBitMask (pin);
outputReg = portOutputRegister (port);
inputReg = portInputRegister (port);
modeReg = portModeRegister (port);
#if ONEWIRE_SEARCH
reset_search ();
#endif
}
In fact, the designer should be without this argument, and it should already be set in the setup() section.
But this will lead to incompatibilities with previous versions.
Ogogon.