/******* * square-move-2.c * * Program uses a struct to store a move by the Scribbler 2 robot * * Author: Henry M. Walker * Date: 15 March 2012 * Revised 18 October 2016 * * Motivated by an example by April O'Neill and Erik Opavsky * Date: 4 August 2011 *******/ #include "MyroC.h" #include struct movement { double speed; double time; }; /* set speed and action for a move by the Scribbler 2 robot */ /* must pass address of pointer to get values out of procedure */ void initialize (struct movement *move) { (*move).speed = 0.8; (*move).time = 2.0; } /* print values in struct movement struct */ void printMove (struct movement move) { printf ("robot action: time = %lf, speed = %lf\n", move.time, move.speed); } /* move robot */ void moveRobot (struct movement move) { rForward (move.speed, move.time); } int main() { rConnect ("/dev/rfcomm0"); /* Declare information for one robot struct movement */ struct movement action; /* Initialize, print, and execute a robot movement */ initialize (&action); // address allows this variable to change printMove (action); moveRobot (action); /* beep after movement */ rBeep (1, 600); rDisconnect(); return 0; } // main