/* * * * *
 * conditional-lightSensor-1.c
 *
 * This program find the light intensity in an environment
 * by counting beeps using if statements.
 *
 * Author: Henry M. Walker
 * Based a 7 July 2011 program for the robot battery 
 *   by  Dilan Ustek, Erik Opavsky
 *
 * Date: 2 February 2015
 */

#include "MyroC.h"
#include <stdio.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	
*/

/* processing based on successive light readings
 */
  printf ("beep based on the intensity of successive light readings\n");

  printf ("initial light sensor reading:  %d\n", rGetLightTxt("center", 3));

  if (rGetLightTxt("center", 3) < 65409) 
    {
      rBeep(1, 500);
      printf ("reading under 65409\n");
    }

  if (rGetLightTxt("center", 3) < 60000)
    {
      rBeep(1, 500);
      printf ("reading under 60000\n");
    }

  if (rGetLightTxt("center", 3) < 55000)
    {
      rBeep(1, 500);
      printf ("reading under 55000\n");
    }

  if (rGetLightTxt("center", 3) < 50000)
    {
      rBeep(1, 500);
      printf ("reading under 50000\n");
    }

  if (rGetLightTxt("center", 3) < 45000)
    {
      rBeep(1, 500);
      printf ("reading under 45000\n");
    }

  if (rGetLightTxt("center", 3) < 40000)
    {
      rBeep(1, 500);
      printf ("reading under 40000\n");
    }

  if (rGetLightTxt("center", 3) < 35000)
    {
      rBeep(1, 500);
      printf ("reading under 35000\n");
    }

  if (rGetLightTxt("center", 3) < 30000)
    {
      rBeep(1, 500);
      printf ("reading under 30000\n");
    }

  if (rGetLightTxt("center", 3) < 25000)
    {
      rBeep(1, 500);
      printf ("reading under 25000\n");
    }

  rDisconnect();

  return 0;
} //main
