Barobo
PortalSign In
HomeShopTutorialsFree CurriculumHour of Code
RoboBlockly for Learning Math and Coding

LArduino Ultrasonic 5: Plot Distance vs. Time

Piano
Linkbot Image Mindstorm Image
0x121110987654321y121110987654321
Grid:
Tics Lines:
Width px
Hash Lines:
Width px
Labels:
Font px
Trace Lines:
Robot 1:
Width px
Robot 2:
Width px
Robot 3:
Width px
Robot 4:
Width px
Labels: x-axis y-axis Show Grid
Grid: 12x12 inches 24x24 inches 36x36 inches
72x72 inches 96x96 inches 192x192 inches
Quad: 4 Quadrants 1 Quadrant 1&4 Quadrants
Units: US Customary Metric
Background: Background Image

Robot 1

0
S
M
L
Initial Position:
( in, in)
Initial Angle:
deg
Current Position: (0 in, 0 in)
Current Angle: 90 deg
Wheel Radius:
Track Width:
in

Robot 2

0
S
M
L
Initial Position:
( in, in)
Initial Angle:
deg
Current Position: (3 in, 0 in)
Current Angle: 90 deg
Wheel Radius:
Track Width:
in

Robot 3

0
S
M
L
Initial Position:
( in, in)
Initial Angle:
deg
Current Position: (6 in, 0 in)
Current Angle: 90 deg
Wheel Radius:
Track Width:
in

Robot 4

0
S
M
L
Initial Position:
( in, in)
Initial Angle:
deg
Current Position: (9 in, 0 in)
Current Angle: 90 deg
Wheel Radius:
Track Width:
in
LArduino Ultrasonic 5: Plot Distance vs. Time
/* Code generated by RoboBlockly v2.5 */
/* Problem Statement: 
    Modify the pre-placed code so that it plots the distance
    vs. time measurements at 1/2-second intervals for 10
    seconds.
    */
#include <robot.h>
#include <chplot.h>
CLinkbotI robot1;
CPlot plot;
double t;
double distance;
int count;

// Get distance from sensor at 1/2 second intervals
// and create a distance vs time plot on the grid
// Set up trigger and echo pins on sensor
robot1.pinMode(9, OUTPUT);
robot1.pinMode(8, INPUT);
// Label x and y axes
plot.label(PLOT_AXIS_X, "Time (secs)");
plot.label(PLOT_AXIS_Y, "Distance (inches)");
// Set time value to 0 to start
t = 0;
// Read distance 21 times at 1/2-sec intervals (0 to
// 10 seconds)
count = 0;
while(count < 21) {
  distance = robot1.readUltrasonicSensor(9, 8);
  // Plot the point on the grid
  plot.point(t, distance);
  // Wait 1/2 second before reading the sensor again
  robot1.delay(500);
  // Update time value (add 1/2 second)
  t = t + 0.5;
  count = count + 1;
}

plot.axisRange(PLOT_AXIS_XY, 0, 12);
plot.ticsRange(PLOT_AXIS_XY, 1);
plot.sizeRatio(1);
plot.plotting();
Load Blocks
Hardware
LArduino
Workspace Show Ch Save File
Problem Statement:

Modify the pre-placed code so that it plots the distance vs. time measurements at 1/2-second intervals for 10 seconds.


		
Rubbish bin
Time