void digital_out( int port, int value ) /* Set port of expansion board to value */ { if ( port == 0 ) port = 0; else if ( port == 1 ) port = 4096; else if ( port == 2 ) port = 2048; else if ( port == 3 ) port = 6144; else if ( port == 4 ) port = 1024; else if ( port == 5 ) port = 5120; else if ( port == 6 ) port = 3072; else if ( port == 7 ) port = 7168; else port = -1; if ( ( port > -1 ) && ( ( value == 0 ) || ( value == 1 ) ) ) peek( 16384 + port + 512 * value ); else printf( "Parameter error: digital_out" ); }
Verbesserung der Störunempfindlichkeit bei den IR-Proxies
int ir_detect( void ) /* Neue Version von Klaus und Michael, die etwas stabiler gegenueber Messfehlern ist! */ /* ir_detect returns: */ /* 0b00 => no reflection, 0b01 => reflection on right, */ /* 0b10 => reflection on left, 0b11 => reflection on both sides */ { /* Local variables */ int val1, val2, val3; val1 = peek( 0x100A ) & 0b10000; /* IR Detector connected to PE4 */ bit_set( 0x1008, 0b1000 ); /* Turn on Left emitter, PD3 */ msleep( 1L ); /* Wait 1 millisecond */ val2 = peek( 0x100A ) & 0b10000; /* Should be Low if signal detected */ bit_clear( 0x1008, 0b1000 ); /* Turn off Left emitter */ bit_set( 0x1008, 0b0100 ); /* Turn on Right emitter, PD2 */ msleep( 1L ); /* Wait 1 millisecond */ val3 = peek( 0x100A ) & 0b10000; bit_clear( 0x1008, 0b0100 ); /* Turn emitter off */ msleep( 1L ); /* For detection, detector must be high when emitter is off, */ val1 = val1 & peek( 0x100A ); /* Should be High again */ /* jede 0 (Hindernis obwohl kein Emmiter an ist!) merken! */ return ( ( val1 & ~val2 ) >> 3 ) | ( ( val1 & ~val3 ) >> 4 ); /* HI -> LOW */ }
Abfragen der Reflexlichtschranke über dem Magneten
int rls_threshold = 6; int RLS( void ) /* Abfragen der Reflexlichtschranke: 0 = kein Objekt, 1 = unsicher, 2 = Objekt vorhanden */ { /* Local variables */ int res = 0; digital_out( 6, OFF ); if ( analog( 7 ) < rls_threshold ) return ( 1 ); digital_out( 6, ON ); if ( analog( 7 ) < rls_threshold ) res = 2; digital_out( 6, OFF ); if ( analog( 7 ) < rls_threshold ) return ( 1 ); return ( res ); }
Zurück zu den Hardware-Erweiterungen