Hi Yatahaze323
Thank you for the details - very clear.
I've looked at the code again, and I think I may have found something.
From your last post, it sounds like paddle1Val starts at 0. When you press "up" button, you were expecting it to increase in value. But the data from Bluetooth you included showed it going down, -1, -2 etc.
Your code has ...
// if the 1 is sent the incoming byte is "49", make the left paddle go up
if (incomingP1Byte == 49)
{
player1Serial.println(paddle1Val--);
delay(10);
}
This is decrementing paddle1Val for each up button, so after first press, it is -1, I think.
Then look at this part of your code. I have added my comments on what I think is happening.
//----------------------------------left paddle
carry=0;
if(paddle1Val<=7){ // this is true, since variable is -1
bitSet(pong[0], paddle1Val); // can't logically set the -1 bit of a byte, not sure what bitSet does, probably nothing
if(paddle1Val-1>=0){ // this is false
bitSet(pong[0],paddle1Val-1); // not executed
}
else{
bitSet(pong[1], 7); // these two lines get executed
bitSet(pong[1],6);
carry==1; // this needs to be corrected to carry = 1
}
if(carry==0){ // I think this is still true, because of previous problem
if(paddle1Val-2>=0){ // this is false
bitSet(pong[0], paddle1Val-2); // not executed
}
else{
bitSet(pong[1], 7); // executed
}
}
}
So, it looks as though, so long as paddle1Val is negative, there is no change in the bit settings in pong[0] and pong[1]. Looks like it is this part of the code that needs work.
Since you only have 14 possible positions of the paddle, an easier approach could be ...
-
Alter paddle1Val so that it runs from 1 to 14, with 8 being the starting value, equivalent to the position shown in your diagram.
-
Set up a two dimensional array of bytes:
byte paddleBitMap [15] [1].
-
Initialise this with the values (bit patterns) you want in pong[0] and pong[1] for each of the 14 positions of paddle1Val.
-
When you want to update the LEDs, you just need to do something like ...
for (i = 0; i < 2; i++)
{
pong[i] = paddleBitMap[paddle1Val][i];
}
or simply
pong[0] = paddleBitMap[paddle1Val][0];
pong[1] = paddleBitMap[paddle1Val][1];
You can use the same bit map array for the other paddle ...
pong[46 + i] = paddleBitMap[paddle2Val][i]
NOTE: to avoid problems, you need to make sure that paddle1Val does not go outside the permitted range, so you need to work on the up / down part of your code too.
NOTE: if changing paddle1Val to run from 1 to 14 causes a lot of work in other parts of your program, you can keep it running from -6 to +7 (and initial value 0). But then you need to change the code that accesses the bit map array, like this ...
pong[0] = paddleBitMap[paddle1Val + 7][0];
pong[1] = paddleBitMap[paddle1Val + 7][1];
Hope that helps
Ray