/* Program combining Scribbler 2 motion and sound
 *
 * Part 1: robot moves forward and right three times 
 *         while playing an ascending musical chord 
 * Part 2: robot moves forward and left three times 
 *         while playing a descending musical chord
 * Part 3: repeats Part 1
 *
 * Author:  Henry M. Walker
 * Date created:  12 May 2016
 * 
 */

#include <MyroC.h>
#include <stdio.h>
#include "scale-notes.h"

/*
  Procedure to move the robot forward
     and right three times while playing
     an ascending musical chord
 */
void
forward_right (void)
{
  printf ("move forward and turn right\n");
  rForward (1.0, 1.0);
  rBeep (0.5, pitchC6);
  rTurnRight (0.7, 0.75);
  
  printf ("move forward and turn right again\n");
  rForward (1.0, 1.0);
  rBeep (0.5, pitchE6);
  rTurnRight (0.7, 0.5);
  
  printf ("move and turn a third time\n");
  rForward (1.0, 1.0);
  rBeep (0.5, pitchG6);
  rTurnRight (0.7, 0.25);

  rBeep (0.5, pitchC7);
} // forward_right


/*
  Procedure to move the robot forward
     and left three times while playing
     an descending musical chord
 */
void
forward_left (void)
{
  printf ("move forward and turn left\n");

  rForward (1.0, 1.0);
  rBeep (0.5, pitchC7);
  rTurnLeft (0.7, 0.25);
  
  printf ("move forward and turn left again\n");
  rForward (1.0, 1.0);
  rBeep (0.5, pitchG6);
  rTurnLeft (0.7, 0.5);
  
  printf ("move and turn a third time\n");
  rForward (1.0, 1.0);
  rBeep (0.5, pitchE6);
  rTurnLeft (0.7, 0.75);

  rBeep (0.5, pitchC6);
} // forward_left


/* Main program entry */
int
main (void)
{
  rConnect ("/dev/rfcomm0");

  /* Part 1: robot moves forward and right three times 
             while playing an ascending musical chord 
  */
  printf ("starting Part 1\n");
  forward_right ();
  
  /* Part 2: robot moves forward and left three times 
             while playing a descending musical chord 
  */
  printf ("starting Part 2\n");
  forward_left ();

  /* Part 3: robot moves forward and right three times 
             while playing an ascending musical chord 
  */
  printf ("starting Part 3\n");
  printf ("Part 3 repeats Part 1\n");
  forward_right ();

  // finish with no errors
  printf ("Enough of this; I am going to stop now\n");
  rDisconnect ();

  return 0;
} // main
