C   25

array-index.c

Guest on 15th January 2022 09:18:37 AM

  1. /* * * * *
  2.  * array-index.c
  3.  *
  4.  * Make the Scribbler move in different speeds and times by putting
  5.  * different numbers to different arrays and giving them
  6.  * as parameters to the commands forward and turn.
  7.  *
  8.  * Authors: Dilan Ustek, Erik Opavsky
  9.  * Modified for this lab: Dilan Ustek
  10.  *
  11.  * Further modifications:  Henry M. Walker
  12.  *
  13.  */
  14.  
  15. #include "MyroC.h"
  16.  
  17. int
  18. main()
  19. {
  20.  
  21.   rConnect ("/dev/rfcomm0");
  22.   rSetForwardnessTxt("scribbler-forward");
  23.  
  24.   int i;
  25.  
  26.   /* the various speeds and times in two seperate arrays */
  27.   double speed[] = {.3, .2, .4, 1, 1, .3, .2, .5};
  28.  
  29.   /* Since the array declaration supplies 8 numbers, this could also be declared
  30.         double speed[8] = {.3, .2, .4, 1, 1, .3, .2, .5};
  31.  
  32.      If array size is more than 8, more space is allocated, but only
  33.      the first part of the array is initialized:
  34.         double speed[10] = {.3, .2, .4, 1, 1, .3, .2, .5};
  35.   */
  36.  
  37.   /* go forward and turn for the various speeds given by the speed array */
  38.   rForward (speed[0], 0.5);
  39.   rTurn (speed[1], 0.5);
  40.   rForward (speed[2], 0.5);
  41.   rTurn (speed[3], 0.5);
  42.   rForward (speed[4], 0.5);
  43.   rTurn (speed[5], 0.5);
  44.   rForward (speed[6], 0.5);
  45.   rTurn (speed[7], 0.5);
  46.  
  47.   /* beep when done */
  48.   rBeep (1, 500);
  49.  
  50.   rDisconnect();
  51.  
  52.   return 0;
  53. } /* main */

Raw Paste


Login or Register to edit or fork this paste. It's free.