Hey all,
Currently working on a new project - an electronic version of the board game Mastermind (the one with the different coloured pegs, the combination of which has to be guessed in the lowest number of tries possible.)
Going well so far, and I'm coping well with controlling such a vast amount of RGB LEDs! I am, however, having one problem which I'm going to try my best to describe as simply as possible.
In order to be able to produce 6 different colours for the LED 'pegs', the LED controllers (3xMAX6956, one for red, one for green, one for blue) can individually control the current sink of a cathode in steps of 1/16th. This is great, except the controllers use one byte to control the current level of two LED ports.
For example, at address $16 the first nibble of the byte (4 bits, 7-4) controls current for port 13, and the second nibble (3-0) controls the current for port 12.
I'm building a subroutine which takes in the port ID and colour ID of a given RGB LED and adjusts the I/O state and current level of all three LED elements within the RGB LED to achieve the colour. The I/O states are easy; the problem I'm having is with changing just 4 bits of the existing current value to work out the new one to send to the controller (I2C).
I know the existing current byte of each colour element. I know the new state of one of the nibbles, and I also know whether or not this is to be the first or second four bits.
For example,
The code needs to calculate the new current value to be sent to the controller as %11101111. It should choose the first nibble from the new value, and the second nibble from the existing value, and combine the two together. If the mask were the other way round (i.e. %00001111) then the new current byte should be %10100000 based on the above data.
I'm assuming this is possible? I'm guessing with bitwise operators but I can't think of a way how. I also tried manually setting the bits but this of course isn't possible beyond bit15 of my PICAXE 18X.
Any suggestions much appreciated. Hope I've explained it well enough!
Thanks as always,
Charlie
Currently working on a new project - an electronic version of the board game Mastermind (the one with the different coloured pegs, the combination of which has to be guessed in the lowest number of tries possible.)
Going well so far, and I'm coping well with controlling such a vast amount of RGB LEDs! I am, however, having one problem which I'm going to try my best to describe as simply as possible.
In order to be able to produce 6 different colours for the LED 'pegs', the LED controllers (3xMAX6956, one for red, one for green, one for blue) can individually control the current sink of a cathode in steps of 1/16th. This is great, except the controllers use one byte to control the current level of two LED ports.
For example, at address $16 the first nibble of the byte (4 bits, 7-4) controls current for port 13, and the second nibble (3-0) controls the current for port 12.
I'm building a subroutine which takes in the port ID and colour ID of a given RGB LED and adjusts the I/O state and current level of all three LED elements within the RGB LED to achieve the colour. The I/O states are easy; the problem I'm having is with changing just 4 bits of the existing current value to work out the new one to send to the controller (I2C).
I know the existing current byte of each colour element. I know the new state of one of the nibbles, and I also know whether or not this is to be the first or second four bits.
For example,
Code:
Current current value: %10101111
New current value: %11100000 (last 4 bits are 0s given that they should be ignored anyway)
Mask (based on whether port number is even or odd): %11110000
I'm assuming this is possible? I'm guessing with bitwise operators but I can't think of a way how. I also tried manually setting the bits but this of course isn't possible beyond bit15 of my PICAXE 18X.
Any suggestions much appreciated. Hope I've explained it well enough!
Thanks as always,
Charlie