|
|
View previous topic :: View next topic |
Author |
Message |
benni
Joined: 28 Jun 2012 Posts: 28
|
Need help with arrays |
Posted: Tue Jul 03, 2012 9:37 am |
|
|
Hello,
I want to make a tetris game in ccs but I have a problem because SOME LEDS are permanent on.
I made an array and set everything to false:
Code: |
int1 Pixel[16][8] = {{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0}};
|
Then when I create the condition all Leds are on:
Code: |
for(x = 0; x < 16; x++)
{
for(y = 0; y < 8;y++)
{
if(Row[x][y] == 1 || Pixel[x][y] == 1)
{
TurnLedOnByCoords(x+1,y+1);
}
}
}
|
The function of TurnLedOnByCoords:
Code: |
void TurnLedOnByCoords(int row, int col)
{
if(row <= 7 || col <= 5)
{
if(row==1) output_high(PIN_A0);
if(row==2) output_high(PIN_A1);
if(row==3) output_high(PIN_A2);
if(row==4) output_high(PIN_A3);
if(row==5) output_high(PIN_A4);
if(row==6) output_high(PIN_A5);
if(row==7) output_high(PIN_B0);
if(col==1)output_high(PIN_D4);
if(col==2)output_high(PIN_C6);
if(col==3)output_high(PIN_D5);
if(col==4)output_high(PIN_B3);
if(col==5)output_high(PIN_C5);
delay_us(250);
if(row==1) output_low(PIN_A0);
if(row==2) output_low(PIN_A1);
if(row==3) output_low(PIN_A2);
if(row==4) output_low(PIN_A3);
if(row==5) output_low(PIN_A4);
if(row==6) output_low(PIN_A5);
if(row==7) output_low(PIN_B0);
if(col==1)output_low(PIN_D4);
if(col==2)output_low(PIN_C6);
if(col==3)output_low(PIN_D5);
if(col==4)output_low(PIN_B3);
if(col==5)output_low(PIN_C5);
}
}
|
This function for turning on the leds is right because I use it in another project.
I hope that someone can help me. |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Tue Jul 03, 2012 10:47 am |
|
|
The obvious question would be:
What is in ???
G _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
benni
Joined: 28 Jun 2012 Posts: 28
|
|
Posted: Tue Jul 03, 2012 11:17 am |
|
|
a 0 or a 1
for example:
Code: | Pixel[0][3]=true;
Pixel[0][4]=true;
Pixel[1][3]=true;
Pixel[1][4]=true; |
When i use BYTE instead of Boolean it works but thats not the way its only true and false that i need. |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Tue Jul 03, 2012 12:05 pm |
|
|
Thanks for the explanation of "Pixel[][]".... which is _not_ "Row[][]".....
... sigh.
G. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
benni
Joined: 28 Jun 2012 Posts: 28
|
|
Posted: Tue Jul 03, 2012 12:18 pm |
|
|
Row[][] is a bool array just ignore Row because when for example Pixel[0][5] is set to true the led in Row 1 and Col 5 Should normally be on but the problem is that everything is on then. When I use byte instead of Boolean it works so how can i do it with boolean because otherwise the array is to big and i get an error that there is no space for all variables.
I hope you understand it. |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Tue Jul 03, 2012 3:14 pm |
|
|
I'm totally lost. I can't even start to understand what you are doing.
Please supply schematic for LEDs, shortest possible complete compilable code which CLEARLY illustrates problem, a lucid account of what does/doesn't should/shouldn't happen, and compiler version etc.
Mike |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Tue Jul 03, 2012 4:08 pm |
|
|
from the looks of it he is trying to drive a LED matrix ("screen")
and set each "pixel" individually...
...
its easier if you set each column or row a full byte and write entire columns or rows at the same time... you can address "pixels" individually as well with this byte aproach... _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|