Not sure what is wrong with my 3-state switch library code

Hi,

I'm trying to write a library for a 3-state switch, which includes debouncing as you change state. However, I can't seem to figure out why the code won't work. I tried to incorporate the Debounce library code into my "Three-way" library code but wasn't able to get it to work. Not sure what is wrong. The switch that I'm using is a three-state switch ON-OFF-ON. Whenever I change states on it, the test LEDs that I'm using don't light up for some reason.

I wired up each state to a digital input line with a PULLUP resistor enabled. To test each state, I use an LED each connected to 220 ohm resistor connected to a digital line.

I have included my "Three-way" library. Also, I have included the script file test5.ino to run the program. Also, I included the Debounce library as well for reference.

If anyone has any input or ideas, it would well be appreciated. Thanks.

dparduino

Debounce.zip (67.1 KB)

test5.ino (1.23 KB)

Three_way.zip (966 Bytes)

Three_way::Three_way(int pinA, int pinB)
{
  _pinA = pinA;
  _pinB = pinB;
  previous_millis = millis();
  interval_millis = 50;
  stateA = digitalRead(_pinA);
  stateB = digitalRead(_pinB);
  stateC = 0;

  _state = 0;
  

  pinMode(_pinA, INPUT_PULLUP);
  pinMode(_pinB, INPUT_PULLUP);

  
}

Get rid of the useless blank lines.
Stop diddling with the hardware. It is NOT ready when your constructor runs.

Add some comments to say what the functions are supposed to do and what they are supposed to return.

It looks like Position doesn't read the switch and only returns the state the switch was in the last time you called Update. It looks like Update doesn't return the Position, just a flag to say if the Position has changed? So you call Update and if it returns 1 you then call Position to see what the new position is?