How to draw Bar charts on NXT with Robotc

News, rumors, and other broad discussion topics.
Post Reply
john6672
Posts: 3
Joined: 27 Mar 2013, 22:01

How to draw Bar charts on NXT with Robotc

Post by john6672 »

Hello,

I am working on a code where i have to collect sensor readings for (light, sound, sonar) every second and display a graph at the end with min and max values.
I also have to display total readings which was easy. I have put together all the code except for the graph part. I would really appreciate if anyone would help me out on this.

Here my code so far :

Code: Select all

task read()
{
	int light_readings[60];
  int sound_readings[60];
  int sonar_readings[60];
  int lightcount=0;
  int soundcount=0;
  int sonarcount=0;
  int tot=0;
  int maxLight=SensorValue[light];
  int minLight=SensorValue[light];
  int maxSound=SensorValue[sound];
  int minSound=SensorValue[sound];
  int maxSonar=SensorValue[sonar];
  int minSonar=SensorValue[sonar];
  ClearTimer(T1);

  while (time1[T1] < 10000)
  {
  	if (SensorValue[light]<minLight)
    {
      minLight=SensorValue[light];
    }
  	if (SensorValue[light]>maxLight)
    {
  	 	maxLight=SensorValue[light];
    }
    if (SensorValue[sound]<minSound)
    {
  	 	minSound=SensorValue[sound];
   	}
   	if (SensorValue[sound]>maxSound)
    {
  	 	maxSound=SensorValue[sound];
    }
    if (SensorValue[sonar]<minSonar)
   	{
  		minSonar=SensorValue[sonar];
 		}
 		if (SensorValue[sonar]>maxSonar)
   	{
  	 	maxSonar=SensorValue[sonar];
  	}

		light_readings = SensorValue[light];
  	lightcount=lightcount +1;
  	sound_readings = SensorValue[sound];
  	soundcount= soundcount +1;
  	sonar_readings = SensorValue[sonar];
  	sonarcount= sonarcount +1;
  	tot= lightcount + soundcount + sonarcount;
  	wait1Msec(1000);

  	while (time1[T1] >= 10000)
  	{
  		motor[motorB] = 0;
    	motor[motorC] = 0;
    	nxtDisplayString(1, "Light:", minLight, maxLight);
    	nxtDisplayString(2, "Min=%i Max=%i", minLight, maxLight);
    	nxtDisplayString(3, "Noise:", minSound, maxSound);
    	nxtDisplayString(4, "Min:%i Max:%i", minSound, maxSound);
    	nxtDisplayString(5, "Distance:", minSonar, maxSonar);
    	nxtDisplayString(6, "Min:%i Max:%i", minSonar, maxSonar);
    	nxtDisplayString(7, "Tot Readings:%i", tot);
    }
}
mightor
Site Admin
Posts: 1079
Joined: 25 Sep 2010, 15:02
Location: Rotterdam, Netherlands
Contact:

Re: How to draw Bar charts on NXT with Robotc

Post by mightor »

| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests