Tank Street Dominoes: I can't crack this math

I really thought I was going to finish Tank Street Dominoes before work today.

Below, variable ClickTell informs what value to send on the faces of the " buildings " [Double Click] that the “cars” [Multi Click] receive and respond to when the cars are connected to a building blink, and the faces of the car and the building match in color. Much like in dominoes.

I have the buildings successfully cycling Green Red Yellow Blue. This is expected. However, once past the first Blue, when the blink’s colors go back to green, ClickTell does not.

Because ClickTell does not “reset” it no longer sets the correct value on the faces, and therefore, the cars can no longer cross the corresponding “” errand “” off their list / turn off the matching face on the car.

Not sure what to do with the math at this point, I’ve done various math checks at 4 and 5, equal to, greater than, … as well as setting ClickTell to 0, -1, and even subtracting 4 from click tell.

Apparently the answer is none of the above, or anything close to the above.



// Tank Street Dominoes The Not Knot 7/7

byte BuildingColor = 0;
byte CarColor = 0;
byte ClickTell = 0;
Color CarColorList[4] = {CYAN, WHITE, ORANGE, MAGENTA};
Color BuildingColorList[4] = {GREEN, RED, YELLOW, BLUE};

void setup() {
  
  setColor(OFF);

}

void loop() {

  if (buttonLongPressed()){
    setColorOnFace(dim (CarColorList[CarColor], 100), 2);
    setColorOnFace(OFF, 5);
    CarColor = (CarColor + 1) % 4; 
  }

  if (buttonDoubleClicked()){
    setColorOnFace(BuildingColorList[BuildingColor], 0);
    setColorOnFace(BuildingColorList[BuildingColor], 1);
    setColorOnFace(BuildingColorList[BuildingColor], 3);
    setColorOnFace(BuildingColorList[BuildingColor], 4);
    BuildingColor = (BuildingColor + 1) % 4;
    setValueSentOnAllFaces(++ClickTell);
    }

  if (buttonMultiClicked()){
        setColorOnFace(GREEN, 0);
        setColorOnFace(RED, 1);
        setColorOnFace(YELLOW, 3);
        setColorOnFace(BLUE, 4);
}

  if (buttonSingleClicked())
  {

    if (getLastValueReceivedOnFace(0) == 1 && isValueReceivedOnFaceExpired(1) && isValueReceivedOnFaceExpired(3) && isValueReceivedOnFaceExpired(4))
    {
        setColorOnFace (OFF, 0);
        //Green Single Off
    }

    if (getLastValueReceivedOnFace(1) == 2 && isValueReceivedOnFaceExpired(0) && isValueReceivedOnFaceExpired(3) && isValueReceivedOnFaceExpired(4))
    {
       setColorOnFace (OFF, 1);
       //Red Single Off
    }

    if (getLastValueReceivedOnFace(3) == 3 && isValueReceivedOnFaceExpired(1) && isValueReceivedOnFaceExpired(0) && isValueReceivedOnFaceExpired(4))
    {
       setColorOnFace (OFF, 3);
       //Yellow Single Off
    }

   if (getLastValueReceivedOnFace(4) == 4 && isValueReceivedOnFaceExpired(1) && isValueReceivedOnFaceExpired(3) && isValueReceivedOnFaceExpired(0))
   {
      setColorOnFace (OFF, 4);
      //Blue Single Off
    }

   if (getLastValueReceivedOnFace(0) == 1 && getLastValueReceivedOnFace(1) == 2 && isValueReceivedOnFaceExpired(3) && isValueReceivedOnFaceExpired(4))
    {
        setColorOnFace (OFF, 0);
        setColorOnFace (OFF, 1);
        //Doubles. Green and Red off. 
    }

    
   if (getLastValueReceivedOnFace(3) == 3 && getLastValueReceivedOnFace(4) == 4 && isValueReceivedOnFaceExpired(0) && isValueReceivedOnFaceExpired(1))
    {
        setColorOnFace (OFF, 3);
        setColorOnFace (OFF, 4);
        //Doubles. Yellow and Blue off. 
    }


   if (getLastValueReceivedOnFace(3) == 3 && getLastValueReceivedOnFace(4) != 4 && isValueReceivedOnFaceExpired(0) && isValueReceivedOnFaceExpired(1))
    {
        setColorOnFace (OFF, 3);
        //Yellow Off, Blue Touches Non Blue 
    }

    if (getLastValueReceivedOnFace(1) == 2 && getLastValueReceivedOnFace(0) != 1 && isValueReceivedOnFaceExpired(3) && isValueReceivedOnFaceExpired(4))
    {
        setColorOnFace (OFF, 1);
        //Red Off, Green touches Non Green
    }

    if (getLastValueReceivedOnFace(0) == 1 && getLastValueReceivedOnFace(1) != 2 && isValueReceivedOnFaceExpired(3) && isValueReceivedOnFaceExpired(4))
    {
        setColorOnFace (OFF, 0);
        //Green Off, Red touches Non Red
    }

if (getLastValueReceivedOnFace(4) == 4 && getLastValueReceivedOnFace(3) != 3 && isValueReceivedOnFaceExpired(0) && isValueReceivedOnFaceExpired(1))
    {
        setColorOnFace (OFF, 4);
        //Blue Off, Yellow Touches Non Yellow
    }

}

//another attempt at ClickTell reset below, comment out as needed

if (ClickTell >=4){
    ClickTell = -1;
}

//ClickTell Attempt End


}

It is not clear to me what you actually want to do but most likelly the above does not do what you think it does.

ClickTell’s type is byte. Possible byte values go from 0 to 255 (there are no negative numbers). When you try to assign -1 to it you are actually assigning 128 (due to the way signed numbers are represented). So after the first time ClickTell is greater than 4, you will keep resetting it to 128 every loop iteration and will get stuck in this state. You most likely want to do ClickTell = 0 (and then change the preincrement ++Clicktell to a postincrement Clicktell++) or you can abuse the fact that when it reaches 255 it will wrap-around to 0 and set it to 255 here instead of -1 (but that is kinda ugly).