Pages: [1]   Go Down
Author Topic: Changing the 1-Wire pin in the library OneWire  (Read 424 times)
0 Members and 1 Guest are viewing this topic.
Chernogolovka, Moscow dst., Russia
Offline Offline
Newbie
*
Karma: 0
Posts: 43
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: May 07, 2011, 06:22:54 pm by ogogon » Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

It's just a variable:

Code:
#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.
Logged

Chernogolovka, Moscow dst., Russia
Offline Offline
Newbie
*
Karma: 0
Posts: 43
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well you could fiddle around and change the library a bit.
I had to slightly modify the library.
Remove from the constructor initialization pin to the function.

Code:
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.
Logged

Pages: [1]   Go Up
Jump to: