#include <string.h>
#include <stdio.h>
#ifdef __WIN32__
#include <windows.h>
#else
#include <unistd.h>
#define Sleep( msec ) usleep(( msec ) * 1000 )
#endif
const char const *color[] = { "?", "BLACK", "BLUE", "GREEN", "YELLOW", "RED", "WHITE", "BROWN" };
#define COLOR_COUNT (( int )( sizeof( color ) / sizeof( color[ 0 ])))
static bool _check_pressed( uint8_t sn )
{
int val;
return (
ev3_read_keys(( uint8_t *) &val ) && ( val & EV3_KEY_UP ));
}
}
int main( void )
{
char s[ 256 ];
int val;
uint32_t n, i, ii;
uint8_t sn_touch, sn_color, sn_ir;
printf( "Waiting the EV3 brick online...\n" );
printf( "*** ( EV3 ) Hello! ***\n" );
printf( "Found sensors:\n" );
for ( i = 0; i < DESC_LIMIT; i++ ) {
if ( ev3_sensor[ i ].type_inx != SENSOR_TYPE__NONE_ ) {
printf( " mode = %s\n", s );
}
for ( ii = 0; ii < n; ii++ ) {
printf( " value%d = %d\n", ii, val );
}
}
}
}
}
printf( "IR sensor is found\n" );
} else {
printf( "IR sensor is NOT found\n" );
}
printf( "TOUCH sensor is found, press BUTTON for EXIT...\n" );
} else {
printf( "TOUCH sensor is NOT found, press UP on the EV3 brick for EXIT...\n" );
}
printf( "COLOR sensor is found, reading COLOR...\n" );
for ( ; ; ) {
if ( !
get_sensor_value( 0, sn_color, &val ) || ( val < 0 ) || ( val >= COLOR_COUNT )) {
val = 0;
}
printf( "\r(%s)", color[ val ]);
fflush( stdout );
if ( _check_pressed( sn_touch )) break;
Sleep( 200 );
printf( "\r " );
fflush( stdout );
if ( _check_pressed( sn_touch )) break;
Sleep( 200 );
}
} else {
printf( "COLOR sensor is NOT found\n" );
while ( !_check_pressed( sn_touch )) Sleep( 100 );
}
printf( "\n*** ( EV3 ) Bye! ***\n" );
return ( 0 );
}