/* * * * *
 * conditional-lightSensor-2.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	
*/

/* process on the basis of one initial reading
 */

  printf ("beep based on the intensity of an initial light reading\n");

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

  printf ("initial light sensor reading:  %d\n", lightReading);

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

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

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

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

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

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

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

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

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

  rDisconnect();

  return 0;
} //main
