Page 1 of 1

How to draw Bar charts on NXT with Robotc

Posted: 27 Apr 2013, 19:47
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);
    }
}

Re: How to draw Bar charts on NXT with Robotc

Posted: 28 Apr 2013, 05:13
by mightor