Hi All,
The following Select..Case snippet from some of my code needs some refinement.
I'm sure it can be replaced by 3 or 4 lines of code with a clever Lookup command, but there some uniqe operations that need to be processed.
Currently, the DataX running through my Select..case code works perfectly, but i'm sure it can be shrunk down to a very efficient procedure instead.
My challenges:
I need to send data (via 8 variables, ROW1 to ROW8) to the Hi2c LED display driver that controls a single 8x8 LED matrix.
The requirement is that when the incoming data (DataX) is '0', then blanks ($00) are sent to the display to blank it out.
When the value '1' arrives, it needs to light the 4 MSB LEDS by sending the data $F0 to the variable 'ROW1' (the MSB nibble)
However, When the value '2' arrives, it needs to light the 4 LSB LEDS by sending the data $0F to the SAME variable 'ROW1' (the LSB nibble)
(essentially treating ROW1 as 2 nibbles being updated).
This procedure then needs to be repeated as data 3,4,5 upto 16 arrives, and send nibbles to the ROW 2 to ROW8 positions.
I'm finding it hard to repeat my DataX twice into the same ROW data by using a Lookup method (so i defaulted to Select..case, which works).
I think i need to separate the odd and even DataX data, so all odds send $F0 to the ROW variable(s), and all evens send $0F to the ROW variable(s).
At the moment, as i receive DataX data from a pot or encoder, my Select..Case quickly gosubs to the "Blankit" routine to blank the entire LED matrix.
Upon return back into the Select..case code, it will then set the nibble data and write it to the LED matrix.
The end effect of doing this, is that by rotating a pot (or encoder) i will see a group of 4 LEDS in a row that moves from the MSB nibble to the LSB nibble position across each of the "ROW1" to ROW8" matrix LEDS, like a travelling line that moves 4-leds-at-a-time) if that makes sense?
At the moment i see Nibble light up from the TOP line of LEDs to the bottom line of LEDs on a single 8x8 matrix.
However, the end plan is to display the nibbles across 8 of the 8x8 matrixs all next to each other, so this nibble of LEDS will step across 8 matrix displays on the top row for example (this is easily handled when i use my existing i2c driver codes in my other project).
I hope this all makes sense? and not clear as mud ;-)
The following Select..Case snippet from some of my code needs some refinement.
I'm sure it can be replaced by 3 or 4 lines of code with a clever Lookup command, but there some uniqe operations that need to be processed.
Currently, the DataX running through my Select..case code works perfectly, but i'm sure it can be shrunk down to a very efficient procedure instead.
My challenges:
I need to send data (via 8 variables, ROW1 to ROW8) to the Hi2c LED display driver that controls a single 8x8 LED matrix.
The requirement is that when the incoming data (DataX) is '0', then blanks ($00) are sent to the display to blank it out.
When the value '1' arrives, it needs to light the 4 MSB LEDS by sending the data $F0 to the variable 'ROW1' (the MSB nibble)
However, When the value '2' arrives, it needs to light the 4 LSB LEDS by sending the data $0F to the SAME variable 'ROW1' (the LSB nibble)
(essentially treating ROW1 as 2 nibbles being updated).
This procedure then needs to be repeated as data 3,4,5 upto 16 arrives, and send nibbles to the ROW 2 to ROW8 positions.
I'm finding it hard to repeat my DataX twice into the same ROW data by using a Lookup method (so i defaulted to Select..case, which works).
I think i need to separate the odd and even DataX data, so all odds send $F0 to the ROW variable(s), and all evens send $0F to the ROW variable(s).
At the moment, as i receive DataX data from a pot or encoder, my Select..Case quickly gosubs to the "Blankit" routine to blank the entire LED matrix.
Upon return back into the Select..case code, it will then set the nibble data and write it to the LED matrix.
The end effect of doing this, is that by rotating a pot (or encoder) i will see a group of 4 LEDS in a row that moves from the MSB nibble to the LSB nibble position across each of the "ROW1" to ROW8" matrix LEDS, like a travelling line that moves 4-leds-at-a-time) if that makes sense?
At the moment i see Nibble light up from the TOP line of LEDs to the bottom line of LEDs on a single 8x8 matrix.
However, the end plan is to display the nibbles across 8 of the 8x8 matrixs all next to each other, so this nibble of LEDS will step across 8 matrix displays on the top row for example (this is easily handled when i use my existing i2c driver codes in my other project).
I hope this all makes sense? and not clear as mud ;-)
Code:
Symbol DataX = b53 ;Decimal Data (0 to 17, yes, 17 values) is captured from a scaled Analog pot input lookup table, or a rotary encoder/counter value etc.
Symbol _F0 = b54 ;Variable that holds a permanent value $F0
Symbol _0F = b55 ;Variable that holds a permanent value $0F
_F0 = $F0 ;Pre-defined "$F0" buffer (this value NEVER needs to change)
_0F = $0F ;Pre-defined "$0F" buffer (this value NEVER needs to change)
Do
select case DataX
case 0 : gosub blankit
case 1 : gosub blankit : ROW_1 = _F0 ;Set to Pre-defined value of "$F0"
case 2 : gosub blankit : ROW_1 = _0F ;Set to Pre-defined value of "$0F"
case 3 : gosub blankit : ROW_2 = _F0
case 4 : gosub blankit : ROW_2 = _0F
case 5 : gosub blankit : ROW_3 = _F0
case 6 : gosub blankit : ROW_3 = _0F
case 7 : gosub blankit : ROW_4 = _F0
case 8 : gosub blankit : ROW_4 = _0F
case 9 : gosub blankit : ROW_5 = _F0
case 10 : gosub blankit : ROW_5 = _0F
case 11 : gosub blankit : ROW_6 = _F0
case 12 : gosub blankit : ROW_6 = _0F
case 13 : gosub blankit : ROW_7 = _F0
case 14 : gosub blankit : ROW_7 = _0F
case 15 : gosub blankit : ROW_8 = _F0
case 16 : gosub blankit : ROW_8 = _0F
endselect
;Write Data to the 8 LED ROWS on the matrix display. (The $00's are just place fillers for a 2nd 8x8 matrix not being used at this time)
Hi2cOUT $00, (ROW_1, $00, ROW_2, $00, ROW_3, $00, ROW_4, $00, ROW_5, $00, ROW_6, $00, ROW_7, $00, ROW_8, $00)
Loop
;Set ALL the LED rows to OFF, before updating 1 of the LED rows with the $F0 or $0F data pattern.
blankit:
;Set ALL the LED rows to OFF (The $00's are just place fillers for a 2nd 8x8 matrix not being used at this time)
ROW_1 = $00 : ROW_2 = $00 : ROW_3 = $00 : ROW_4 = $00 : ROW_5 = $00 : ROW_6 = $00 : ROW_7 = $00 : ROW_8 = $00
return