|
THS
|
Robots /
Attach/* Add comment - name - cohort - assignment - date - and overview here
// Include the Command Module API
// Pointer to the Sensor Data structure cr8_t *cr8; // Declare any new function prototypes here: // Declare GLOBAL constants used in program: // Declare GLOBAL Variables used in program: // Initialize GLOBAL Variables used in program: // Declaraion for function "main" int main(void) { // Declare LOCAL constants used in function main:
// Declare LOCAL Variables used in function main:
uint8_t display_distance = true;
uint8_t intensity_level;
uint8_t power_color = 255;
// Allocate memory for sensor data structure
cr8 = cr8_alloc();
/* Initialize the Create and Command Module
Sync communications settings. */
cr8_init(cr8);
cr8_adc_enable(ADC_CENTER_1); // distance sensor
cr8_adc_enable(ADC_CENTER_2); // light sensor
// Initialize LOCAL Variables used in function main:
/*
write code for main here!
*/
// run this program forever.
while(1)
{
cr8_update(cr8);
// use the play button to switch between light/distance sensor
if(cr8->button_play)
{
display_distance = (display_distance + 1) % 2; // switch between true/false
while(cr8->button_play)
{ // wait until user has let go of button
cr8_update(cr8);
cr8_delay(15);
}
}
// display external sensor readings on cricket led and power led
if(display_distance)
{ // use distance sensor
lcd_printf("%d", cr8->adc_center1); // dist sensor, unsigned, decimal
intensity_level = cr8->adc_center1 / 4; // max 1023 / 4 - 1 = 255
power_color = 255;
}
else
{ // use light sensor
lcd_printf("%d", cr8->adc_center2); // light sensor, unsigned, decimal
intensity_level = cr8->adc_center2 / 4; // max 1023 / 4 - 1 = 255
power_color = 0;
}
cr8_set_leds(false, false, power_color, intensity_level);
cr8_delay(250);
}
cr8_free(cr8);
return(0);
} // End of function main /* Declare other functions you create here... */ //For example, to define function xxxxx of type integer (int) //with two input parameters, sample_num and code... //int xxxxx(int sample_num, char code) //{
// Declare LOCAL constants used in function xxxxx:
// Declare LOCAL Variables used in function xxxxx:
// Initialize LOCAL Variables ised in function xxxxx:
// Write code for function XXXXX here:
//Return int value for function xxxxx:
// return(1); You must always return a value to sending program
// --in this case a 1 to indicate fn done with no problems.
//} // End of function xxxxx //*/ |