/* Program to indicate light sensor readings
 * Henry Walker and Jerod Weinman
 */

#include <stdio.h>
#include <MyroC.h>

int
main()
{
  rConnect("/dev/rfcomm0");
  
  /*
    The return value of rGetLightTxt ranges from 65408 for very dark to 0 for
    very bright. The second argument (in our case integer 3) is the number of
    times the sensor samples the light. For details, see MyroC.h  */

  int lightReading = rGetLightTxt("center", 3);  

  printf ("beep based on the intensity of an initial light reading\n");
  printf ("initial light sensor reading:  %d\n", lightReading);

  int threshold = 65000;

  while ( threshold > 25000 )
  {
    if (lightReading < threshold) 
    {
      rBeep(1, 500);
      printf ("reading under %d\n", threshold);
    }

    threshold -= 5000;
  }

  rDisconnect();

  return 0;
} //main
