View unanswered posts | View active topics It is currently Tue Jul 29, 2014 3:52 pm






Reply to topic  [ 39 posts ]  Go to page Previous  1, 2, 3
2D array... I need help! (kinda urgent...). 
Author Message
Professor
User avatar

Joined: Sat May 18, 2013 1:24 pm
Posts: 272
Location: Olympia, WA
Post Re: 2D array... I need help! (kinda urgent...).
Thought I'd jump in and save Xander *some* writing :)

In RobotC, there's functions for displaying graphics and sounds. The standard set of provided sounds is different, although there is overlap. You can find the original NXT-G sounds/images in a directory somewhere, I'm sure. But back to the question: "PlaySoundFile(const string &FileName)" will play the sound file you specify. You will have to upload the sound file to the brick first though (I think the file extension is ".rso").

For displaying graphics, check out this link (note that you can choose to display plain text as well; that takes up less memory on the brick): http://www.robotc.net/wiki/NXT_Function ... layRICFile

_________________
FTC Team 6424, the 'Oly Cow - Chief programmer.
FRC Team 4450, Olympia Robotics Federation (ORF).

and also quadrotors. Quadrotors!


Thu Jun 06, 2013 11:56 pm
Profile
Rookie

Joined: Sun May 12, 2013 3:17 pm
Posts: 21
Post Re: 2D array... I need help! (kinda urgent...).
Ernest3.14 wrote:
Thought I'd jump in and save Xander *some* writing :)

In RobotC, there's functions for displaying graphics and sounds. The standard set of provided sounds is different, although there is overlap. You can find the original NXT-G sounds/images in a directory somewhere, I'm sure. But back to the question: "PlaySoundFile(const string &FileName)" will play the sound file you specify. You will have to upload the sound file to the brick first though (I think the file extension is ".rso").

For displaying graphics, check out this link (note that you can choose to display plain text as well; that takes up less memory on the brick): http://www.robotc.net/wiki/NXT_Function ... layRICFile

Thank you!
About the graphics: there's an Error about the file extension ".ric"... I don't know why.
I'll check it later again but try it by yourself. Maybe I'm doing something wrong... Maybe I'm not writing the names of the files as they are. For example - I have not seen any image named "faceclosed"... So I changed the name to Smile01.
I think the same problem about the sounds.


Fri Jun 07, 2013 12:10 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3164
Location: Rotterdam, The Netherlands
Post Re: 2D array... I need help! (kinda urgent...).
newspaper wrote:
Nope. I wrote you what's that in one of the private messages before a week ago (or mabe it was even before a week). Check it out if you don't remember :-)

I have a terrible memory, I'm worse than one of those, ehh, orange things in a bowl of water.

I thought about that:

Code:
int i, j;
int image[x][y]
for(i=0; i<x; i++){
  for(j=0; j<y; j++){
    if(image[i][j] == 1){ //1 IS BLACK POINT
      nxtSetPixel(j,x);
    }
  }
}


Quote:
Am I right? I don't think so... I need to change something and I don't know what. What do you think?

That could work, but you may want to use i instead of x.

Quote:
By the way:
What is the ROBOTC funciton if I want to display an image on the LCD screen of the nxt brick? I mean, there are several images in the NXTG of smilies and those kinds of images. In NXTG I just choose the image when I edit the "block" but what should I do in ROBOTC?
Same question if I want sounds - there are some sounds in the NXTG like "Hooray" etc. What are the ROBOTC function that fits to those sounds?

You need to use nxtDisplayRICFile(nleft, nBottom, sFileName); where filename is the name of the .ric (picture) file. To play a sound, you must use PlaySoundFile(sFileName);One thing you'll have to do before you do that, is set the folder where ROBOTC can find these files. Normally it's set to the folder that is present if you have the LEGO Education version of NXT-G. There is a bug in ROBOTC it seems that stops this from working as it should. What I did as a work-around for this was to create a folder called "Resources" in the folder where I keep all my .c files. From C:\Program Files (x86)\LEGO Software\LEGO MINDSTORMS NXT\engine\Sounds and C:\Program Files (x86)\LEGO Software\LEGO MINDSTORMS NXT\engine\Pictures I copied the sounds and images into this new Resource folder that I created. Next I configured that folder in the preferences, here:
Attachment:
2013-06-07_06-57-46.png
2013-06-07_06-57-46.png [ 18.85 KiB | Viewed 2398 times ]

I set both the bottom folders to the same folder name, the one I just created. Now when I hit F5, they're automatically uploaded with the program!
This is a quick test program to see if it all works:
Code:
// sound and picture!
// Hooray.rso
// Earth.ric
task main()
{
  nxtDisplayRICFile(0, 0, "Earth.ric");
  PlaySoundFile("Hooray.rso");
  wait1Msec(5000);
}


= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Fri Jun 07, 2013 1:00 am
Profile WWW
Rookie

Joined: Sun May 12, 2013 3:17 pm
Posts: 21
Post Re: 2D array... I need help! (kinda urgent...).
mightor wrote:
newspaper wrote:
Nope. I wrote you what's that in one of the private messages before a week ago (or mabe it was even before a week). Check it out if you don't remember :-)

I have a terrible memory, I'm worse than one of those, ehh, orange things in a bowl of water.
Sorry, I didn't quite understand the last part... "orange things in a bowl of water"? What? :oops:
I thought about that:

Code:
int i, j;
int image[x][y]
for(i=0; i<x; i++){
  for(j=0; j<y; j++){
    if(image[i][j] == 1){ //1 IS BLACK POINT
      nxtSetPixel(j,x);
    }
  }
}

Actually that's not working... :(

Quote:
Am I right? I don't think so... I need to change something and I don't know what. What do you think?

That could work, but you may want to use i instead of x.

Quote:
By the way:
What is the ROBOTC funciton if I want to display an image on the LCD screen of the nxt brick? I mean, there are several images in the NXTG of smilies and those kinds of images. In NXTG I just choose the image when I edit the "block" but what should I do in ROBOTC?
Same question if I want sounds - there are some sounds in the NXTG like "Hooray" etc. What are the ROBOTC function that fits to those sounds?

You need to use nxtDisplayRICFile(nleft, nBottom, sFileName); where filename is the name of the .ric (picture) file. To play a sound, you must use PlaySoundFile(sFileName);One thing you'll have to do before you do that, is set the folder where ROBOTC can find these files. Normally it's set to the folder that is present if you have the LEGO Education version of NXT-G. There is a bug in ROBOTC it seems that stops this from working as it should. What I did as a work-around for this was to create a folder called "Resources" in the folder where I keep all my .c files. From C:\Program Files (x86)\LEGO Software\LEGO MINDSTORMS NXT\engine\Sounds and C:\Program Files (x86)\LEGO Software\LEGO MINDSTORMS NXT\engine\Pictures I copied the sounds and images into this new Resource folder that I created. Next I configured that folder in the preferences, here:
Attachment:
2013-06-07_06-57-46.png

I set both the bottom folders to the same folder name, the one I just created. Now when I hit F5, they're automatically uploaded with the program!
This is a quick test program to see if it all works:
Code:
// sound and picture!
// Hooray.rso
// Earth.ric
task main()
{
  nxtDisplayRICFile(0, 0, "Earth.ric");
  PlaySoundFile("Hooray.rso");
  wait1Msec(5000);
}


= Xander

OK, thanks. I'll try it in a few days and I'll update if I'll have any problem.


I sent you privately the full code. :biggrin:


Fri Jun 07, 2013 3:10 pm
Profile
Professor
User avatar

Joined: Sat May 18, 2013 1:24 pm
Posts: 272
Location: Olympia, WA
Post Re: 2D array... I need help! (kinda urgent...).
Ahhh... That's why our cow wouldn't moo last year. I uninstalled NXT-G. :D

_________________
FTC Team 6424, the 'Oly Cow - Chief programmer.
FRC Team 4450, Olympia Robotics Federation (ORF).

and also quadrotors. Quadrotors!


Fri Jun 07, 2013 9:32 pm
Profile
Rookie

Joined: Sun May 12, 2013 3:17 pm
Posts: 21
Post Re: 2D array... I need help! (kinda urgent...).
OK guys, I wanna know if there is an option for the code to know when it comes to the last number in every grop.
I mean, here is 2d array:
image[i][j] = {{1,1,1,1,1,1,1,1,}, {1,1,0,1,0,1,1,0,}}
Now, I want when it comes to the 8th to do something but without write it like "when(j == 7)" but more in generally 'cause the I'm gonna change every time the amount of numbers in each group and I don't want every time to change also the number in the condition of the while loop...


Sun Jun 09, 2013 12:14 pm
Profile
Professor
User avatar

Joined: Sat May 18, 2013 1:24 pm
Posts: 272
Location: Olympia, WA
Post Re: 2D array... I need help! (kinda urgent...).
How are you going to determine the amount of numbers in each group? Because when you declare your array, you'll be using that number. You can just use "if(j==var)", and "image[i][var]" instead. There's no rule forbidding the use of variables other than "i" and "j" :)

_________________
FTC Team 6424, the 'Oly Cow - Chief programmer.
FRC Team 4450, Olympia Robotics Federation (ORF).

and also quadrotors. Quadrotors!


Sun Jun 09, 2013 12:18 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3164
Location: Rotterdam, The Netherlands
Post Re: 2D array... I need help! (kinda urgent...).
Ernest3.14 wrote:
There's no rule forbidding the use of variables other than "i" and "j" :)

You might want to check that with the Programmers Guild, they're sticklers for this kind of thing.

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Sun Jun 09, 2013 12:33 pm
Profile WWW
Rookie

Joined: Sun May 12, 2013 3:17 pm
Posts: 21
Post Re: 2D array... I need help! (kinda urgent...).
Ernest3.14 wrote:
How are you going to determine the amount of numbers in each group? Because when you declare your array, you'll be using that number. You can just use "if(j==var)", and "image[i][var]" instead. There's no rule forbidding the use of variables other than "i" and "j" :)




mightor wrote:
Ernest3.14 wrote:
There's no rule forbidding the use of variables other than "i" and "j" :)

You might want to check that with the Programmers Guild, they're sticklers for this kind of thing.

= Xander



I'm gonna change the amount of numbers in each grop by myself... So there's no way just to change the condition also by myself, right?


Sun Jun 09, 2013 12:49 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 39 posts ]  Go to page Previous  1, 2, 3

Who is online

Users browsing this forum: No registered users and 2 guests


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 post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.