B4R Question How to convert a linear relation to a x/y ?

Cableguy

Expert
Licensed User
Longtime User
This seems a simple question but given the limited resources or the Arduino, it is not that easy...

So what I am trying to achieve is to be able to reference a linear position by calling a x/y value...
My RGB board has 40 Leds, placed in a 8X5 array... So I would like to code "turn on position X6, Y4" ...
How do I do it, since we cannot use 2 dimension arrays...
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Example of a 2d array:
B4X:
Sub Process_Globals
   Public Serial1 As Serial
   Private My2dArray(8 * 5) As Byte
End Sub

Private Sub AppStart
   Serial1.Initialize(115200)
   Log("AppStart")
   Set(1, 2, 100)
   Log(Get(1, 2))
End Sub

Private Sub Get(x As Byte, y As Byte) As Byte
   Return My2dArray(x * 8 + y)
End Sub

Private Sub Set(x As Byte, y As Byte, value As Byte)
   My2dArray(x * 8 + y) = value
End Sub
 
Upvote 0
Top