24x24 led matrix
Moderators: Chuckt, Garth, bitfogav
Brad I need some help with this?brad wrote:It's just crazy isn't it!
Such a time saver - it allows you to get on with your program without having to worry about all the little bits and pieces that really can take up alot of time.
Code: Select all
temp_byte = %00000000
For k = 0 To 7
Select k
Case 0
Select random_gen_line(k)
Case 1
temp_byte = temp_byte Or %10000000
EndSelect
Case 1
Select random_gen_line(k)
Case 1
temp_byte = temp_byte Or %01000000
EndSelect
Case 2
Select random_gen_line(k)
Case 1
temp_byte = temp_byte Or %00100000
EndSelect
Case 3
Select random_gen_line(k)
Case 1
temp_byte = temp_byte Or %00010000
EndSelect
Case 4
Select random_gen_line(k)
Case 1
temp_byte = temp_byte Or %00001000
EndSelect
Case 5
Select random_gen_line(k)
Case 1
temp_byte = temp_byte Or %00000100
EndSelect
Case 6
Select random_gen_line(k)
Case 1
temp_byte = temp_byte Or %00000010
EndSelect
Case 7
Select random_gen_line(k)
Case 1
temp_byte = temp_byte Or %00000001
EndSelect
EndSelect
Next
left_block_new_road_line = temp_byte
random_gen_line as been declared as
Code: Select all
dim random_gen_line (8) as bit
- brad
- Site Admin
- Posts: 2578
- Joined: Fri Mar 26, 2010 10:30 pm [phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
Hmm, you really are going about that in an interesting way!
from what I can see, you are checking to see if a certain bit is set in random_gen_line. if it is set, then you set a certain bit in temp_byte. The bit you set seems to be opposite to what you are checking I.E. if you check bit 0 you will then set bit 7, if you check bit 1 you then set bit 6 etc...
However if you just want to set the same bit that you check then it can be as simple as this:
You could also do this sort of thing which may help you:
Or I may be missing your point totally - if so then let me know!
from what I can see, you are checking to see if a certain bit is set in random_gen_line. if it is set, then you set a certain bit in temp_byte. The bit you set seems to be opposite to what you are checking I.E. if you check bit 0 you will then set bit 7, if you check bit 1 you then set bit 6 etc...
However if you just want to set the same bit that you check then it can be as simple as this:
Code: Select all
temp_byte = random_gen_line
Code: Select all
temp byte = 0
for x = 0 to 7
if random_gen_line.bits(x) = 1 then
temp_byte.bits(x) = 1
next
This is abit weird
I have tried your bit of code Brad and for some reason my swordfish ide locksup, if I remove your bit of code it works fine
I have changed your code slightly to the code above.

I have tried your bit of code Brad and for some reason my swordfish ide locksup, if I remove your bit of code it works fine

Code: Select all
temp_byte = 0
for x = 0 to 7
if random_gen_line.bits(x) = 1 then
temp_byte.bits(x) = 1
endif
next
I think ive got a solution Brad,
The bit of code
well random_gen_line has already been declared as a bit for example:
so I changed it to this:
It works but like you said before I need the bits in the byte tobe opposite, for example if you check bit 0 you will then set bit 7, if you check bit 1 you then set bit 6 etc...
The bit of code
Code: Select all
if random_gen_line.bits(x) = 1
Code: Select all
dim random_gen_line (8) as bit
Code: Select all
For k = 0 To 7
If random_gen_line(k) = 1 Then
temp_byte.bits(k) = 1
EndIf
Next
- brad
- Site Admin
- Posts: 2578
- Joined: Fri Mar 26, 2010 10:30 pm [phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
Oops! I forgot that you had declared it as eight separate bits (in an array)
To fix your other problem, I guess you could do this:
It first checks to see if a particular bit is a logic 1, it then uses case statements to set your required bit in temp_byte
To fix your other problem, I guess you could do this:
Code: Select all
temp byte = 0
for x = 0 to 7
if random_gen_line.bits(x) = 1 then
select x
case 0
temp_byte.bits(7) = 1
case 1
temp_byte.bits(6) = 1
case 2
temp_byte.bits(5) = 1
case 3
temp_byte.bits(4) = 1
case 4
temp_byte.bits(3) = 1
case 5
temp_byte.bits(2) = 1
case 6
temp_byte.bits(1) = 1
case 7
temp_byte.bits(0) = 1
EndSelect
Endif
next
That looks spot on Brad, I will give it ago today in my program.
I think you would be very interested in what this bit of code does, I am actually drawing a random road across 24 bits which equals one row on my matrix, this bit of code is used to draw just 8 bits of my 24 bits (which is one 8x8 matrix), so I might have to copy and paste this piece of code 3 times in my program to cover all 24bits.
I am also using the random generator that cames on the user modules on digital.diy.com to generate my random road data.
I think you would be very interested in what this bit of code does, I am actually drawing a random road across 24 bits which equals one row on my matrix, this bit of code is used to draw just 8 bits of my 24 bits (which is one 8x8 matrix), so I might have to copy and paste this piece of code 3 times in my program to cover all 24bits.
I am also using the random generator that cames on the user modules on digital.diy.com to generate my random road data.
Yes Brad that is the ideabrad wrote:Great idea, so does that mean that the track is just about always different because it draws different bits and pieces here and there?

Heres a video of the random track, its also setup to check the distance between left and right track datas and then if left track and right track data is a certain distance apart it will draw two lanes. I have also reworked the Car controls to cover all the matrix's with crash detection included, I have crashed the car in the video to show you how it works and pauses the track to show where you crashed, it then restarts the game

I have ran into abit of a problem though, the random generator will draw the track randomly for quite awhile and then it gets into a fixed loop where it keeps drawing the same piece of track, I have tried serveral random primary numbers to initialise the random generator but it still gets into a fixed loop. If anyone has any ideas that would be greatful, or it might be a case of creating a better random generator.
http://www.youtube.com/watch?v=-HPgRdKGlbo
Thanks buddy.. you say an LED to generate a random number? has this got something to do with using an LED as a sensor? hehebrad wrote:I cant get too much into it now because I am running late for work, but I have come up with the most basic way of generating a random number. And it really is random!
it involves an LED believe it or not to generate the random number. Will post full details after work...
By the way - cool video!

Who is online
Users browsing this forum: No registered users and 5 guests