void setup(){ //run once initialization code here, i.e. OledInit() will probably go here DeviceInit(); score=0; showStrtScrn(); calibratedAccel=getAccelY(); switch(CheckSwitches()){ case 0: maxBullet=5;break; case 1: maxBullet=4;break; case 2:maxBullet=3;break; case 3: maxBullet=2;break; default: maxBullet=5; }; lives=4; updateLED(lives); initStuff(); OrbitOledClear(); OrbitOledSetFillPattern(OrbitOledGetStdPattern(1)); }
int main( void ) { int i; int led = 0; uint16_t prevSwitches = 0; InitHardware(); InitADC(); InitMotors(); eeprom_read_block( &gMemParam, &gEEParam, sizeof( gMemParam )); if ( gMemParam.thresh_hi == 0xFF ) { gMemParam.thresh_hi = 0x80; } if ( gMemParam.thresh_lo == 0xFF ) { gMemParam.thresh_lo = 0x10; } #if CFG_LOG_USE_STDIO fdevopen( UART0_PutCharStdio, UART0_GetCharStdio ); LogInit( stdout ); #endif // The first handle opened for read goes to stdin, and the first handle // opened for write goes to stdout. So u0 is stdin, stdout, and stderr Log( "*****\n" ); Log( "***** Line Maze program\n" ); Log( "*****\n" ); LCD_Init( 2, 16 ); LCD_Printf( " SRS Sample Bot " ); LCD_MoveTo( 0, 1 ); LCD_Printf( "Second line" ); Log( "\n" ); MENU_Init( gTopMenu ); LED_OFF( GREEN ); while( 1 ) { uint16_t switches; uint8_t pinc; uint8_t pind; int8_t error; LED_TOGGLE( GREEN ); led++; if ( led >= 6 ) { led = 0; } error = GetLineError(); if ( MENU_IsActive() ) { MENU_Event( MENU_EVENT_TIMER ); } else { if ( MENU_IsModified() ) { eeprom_write_block( &gMemParam, &gEEParam, sizeof( gMemParam )); MENU_ClearModified(); LCD_Clear(); LCD_Printf( "EEPROM Updated\n" ); Log( "EEPROM Updated\n" ); ms_spin( 1000 ); } //switches = EXP_TransferWord( ~( 1 << ( led + 2 )), EXP_OUT_LED_MASK ); switches = EXP_TransferWord( 0, 0 ); Log( "SW:%04x ", switches ); if ( switches != prevSwitches ) { LCD_Clear(); prevSwitches = switches; } for ( i = 0; i < 8; i++ ) { Log( "%02x ", gLineADC[ i ]); } //Log( "C: %02x\n", PINC ); switch (( switches & 0xF0 ) >> 4 ) { case 0: { LCD_MoveTo( 0, 0 ); LCD_Printf( " SRS Sample Bot " ); LCD_MoveTo( 0, 1 ); LCD_Printf( "Second line" ); break; } case 1: { LCD_MoveTo( 0, 0 ); LCD_Printf( "Joy: %c%c%c%c%c", (( switches & 0x4000 ) == 0 ) ? 'L' : ' ', (( switches & 0x2000 ) == 0 ) ? 'R' : ' ', (( switches & 0x0800 ) == 0 ) ? 'U' : ' ', (( switches & 0x0400 ) == 0 ) ? 'D' : ' ', (( switches & 0x1000 ) == 0 ) ? 'X' : ' ' ); LCD_MoveTo( 0, 1 ); LCD_Printf( "S1:%d S2:%d S3:%d", ( switches & 0x0200 ) == 0, ( switches & 0x0100 ) == 0, ( PIND & ( 1 << 6 )) == 0 ); break; } case 2: { LCD_MoveTo( 0, 0 ); LCD_Printf( "L %02x %02x %02x %02x %02x", gLineADC[ 0 ], gLineADC[ 1 ], gLineADC[ 2 ], gLineADC[ 3 ], gLineADC[ 4 ] ); LCD_MoveTo( 0, 1 ); LCD_Printf( "E %02x %02x %3d B %02x", gADC[ 0 ], gADC[ 7 ], error, gADC[ 6 ] ); break; } default: { LCD_MoveTo( 0, 0 ); LCD_Printf( "Setting: %d", ( switches & 0xF0 ) >> 4 ); break; } } pinc = PINC; pind = PIND; Log( " QL:%d%d QR:%d%d EC-L:%d EC-R:%d Err:%2d L:%5b H:%5b\n", ( ENCODER_L_A_PIN & ENCODER_L_A_MASK ) != 0, ( ENCODER_L_B_PIN & ENCODER_L_B_MASK ) != 0, ( ENCODER_R_A_PIN & ENCODER_R_A_MASK ) != 0, ( ENCODER_R_B_PIN & ENCODER_R_B_MASK ) != 0, gEncoderCountL, gEncoderCountR, error, gLowMask, gHighMask ); } // Tick rate is 100/sec so waiting for 50 waits for 1/2 sec for ( i = 0; i < 50; i++ ) { WaitForTimer0Rollover(); CheckSwitches(); #if 1 if ( UART0_IsCharAvailable() ) { char ch = UART0_GetChar(); if ( ch == ' ' ) { DebugKey(); } else { Log( "Read: '%c'\n", ch ); } } #endif } } return 0; }