24x24 led matrix

Post here to let others know of a project you're working on.

Moderators: Chuckt, Garth, bitfogav

User avatar
brad
Site Admin
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

Post by brad » Thu Sep 09, 2010 10:19 pm

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.

User avatar
bitfogav
Moderator
Moderator
Posts: 915
Joined: Sun Mar 28, 2010 9:03 pm
Location: United Kingdom
Contact:

Post by bitfogav » Fri Sep 10, 2010 9:28 am

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.
Brad I need some help with this?

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
Im trying to check each bit of a byte and this is the only way I could do it, there must be a easier way? what do you think?

random_gen_line as been declared as

Code: Select all

dim random_gen_line (8) as bit

User avatar
brad
Site Admin
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

Post by brad » Fri Sep 10, 2010 3:38 pm

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:

Code: Select all

temp_byte = random_gen_line
You could also do this sort of thing which may help you:

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         
Or I may be missing your point totally - if so then let me know!

User avatar
bitfogav
Moderator
Moderator
Posts: 915
Joined: Sun Mar 28, 2010 9:03 pm
Location: United Kingdom
Contact:

Post by bitfogav » Sat Sep 11, 2010 2:48 am

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 :?

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 have changed your code slightly to the code above.

User avatar
bitfogav
Moderator
Moderator
Posts: 915
Joined: Sun Mar 28, 2010 9:03 pm
Location: United Kingdom
Contact:

Post by bitfogav » Sat Sep 11, 2010 3:44 am

I think ive got a solution Brad,

The bit of code

Code: Select all

if random_gen_line.bits(x) = 1 
well random_gen_line has already been declared as a bit for example:

Code: Select all

dim random_gen_line (8) as bit
so I changed it to this:

Code: Select all

	For k = 0 To 7
			If random_gen_line(k) = 1 Then
			   temp_byte.bits(k) = 1
			EndIf
	Next
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...

User avatar
brad
Site Admin
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

Post by brad » Sat Sep 11, 2010 8:15 pm

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:

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  
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

User avatar
bitfogav
Moderator
Moderator
Posts: 915
Joined: Sun Mar 28, 2010 9:03 pm
Location: United Kingdom
Contact:

Post by bitfogav » Sat Sep 11, 2010 8:59 pm

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.

User avatar
brad
Site Admin
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

Post by brad » Sun Sep 12, 2010 8:35 pm

Great idea, so does that mean that the track is just about always different because it draws different bits and pieces here and there?

User avatar
bitfogav
Moderator
Moderator
Posts: 915
Joined: Sun Mar 28, 2010 9:03 pm
Location: United Kingdom
Contact:

Post by bitfogav » Sun Sep 12, 2010 9:52 pm

brad 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?
Yes Brad that is the idea :)

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

User avatar
brad
Site Admin
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

Post by brad » Tue Sep 14, 2010 6:16 am

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!

User avatar
bitfogav
Moderator
Moderator
Posts: 915
Joined: Sun Mar 28, 2010 9:03 pm
Location: United Kingdom
Contact:

Post by bitfogav » Tue Sep 14, 2010 6:25 am

brad 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!
Thanks buddy.. you say an LED to generate a random number? has this got something to do with using an LED as a sensor? hehe :)

Post Reply
[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

Who is online

Users browsing this forum: No registered users and 3 guests