Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
44 lines (35 sloc) 1002 Bytes
#ifndef _SENSORS_H_
#define _SENSORS_H_
#include "sound.h"
#include "defines.h"
#define ULTRASONIC_MAX 255
#define ULTRASONIC_SCALE 0.01
struct sensor_t
{
int light_value;
int color_value;
int color_red;
int color_green;
int color_blue;
float ultrasonic_left;
float ultrasonic_right;
};
sensor_t sensors;
void update_sensors()
{
sensors.light_value = Sensor(LIGHT_SENSOR_ID);
ReadSensorHTColor(COLOR_SENSOR_ID, sensors.color_value, sensors.color_red, sensors.color_green, sensors.color_blue);
sensors.ultrasonic_left = SensorUS(ULTRASONIC_LEFT_SENSOR_ID);
sensors.ultrasonic_right = SensorUS(ULTRASONIC_RIGHT_SENSOR_ID);
}
float get_ultrasonic_distance(int id)
{
if(id == ULTRASONIC_RIGHT_SENSOR_ID)
return sensors.ultrasonic_right*ULTRASONIC_SCALE;
else if(ULTRASONIC_LEFT_SENSOR_ID)
return sensors.ultrasonic_left*ULTRASONIC_SCALE;
else
do_beep_ultrasonic_error();
return -1;
}
#endif // _SENSORS_H_