/* 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>

/* List musical notes for a C major chord */
const int pitchC6 = 1047;
const int pitchE6 = 1319;
const int pitchG6 = 1568;
const int pitchC7 = 2092;

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");
  printf ("move forward and turn right");
  /* rForward, rTurnRight, rTurnLeft require speed and duration
     max speed forward is 1.0
     duration in seconds
  */
  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);

  /* Part 2: robot moves forward and left three times 
             while playing a descending musical chord 
  */
  printf ("starting Part 2\n");
  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);

  /* 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");
  
  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);

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

  return 0;
}
