/*---------------------------------------------------------------------------- * main: blink LED and check button state *----------------------------------------------------------------------------*/ int main (void) { int32_t max_num = LED_GetCount() - 1; int32_t num = 0; int32_t dir = 1; SystemCoreClockConfigure(); // configure HSI as System Clock SystemCoreClockUpdate(); LED_Initialize(); Buttons_Initialize(); SysTick_Config(SystemCoreClock / 1000); // SysTick 1 msec interrupts for (;;) { LED_On(num); // Turn specified LED on Delay(500); // Wait 500ms while (Buttons_GetState() & (1 << 0)); // Wait while holding USER button LED_Off(num); // Turn specified LED off Delay(500); // Wait 500ms while (Buttons_GetState() & (1 << 0)); // Wait while holding USER button num += dir; // Change LED number if (dir == 1 && num == max_num) { dir = -1; // Change direction to down } else if (num == 0) { dir = 1; // Change direction to up } } }
/***************************************************************************** Function : LOS_EvbGetKeyVal Description : Get GIOP Key value Input : int KeyNum Output : None Return : KeyVal *****************************************************************************/ unsigned int LOS_EvbGetKeyVal(int KeyNum) { unsigned int KeyVal = LOS_GPIO_ERR; //add you code here. #ifdef LOS_ATMSAMG55xx KeyVal = Buttons_GetState(); #endif return KeyVal; }
bool Putz01HandleButtons (void) { int i = 1; static uint32_t tickEvent = EVENT_INTERVAL; while (Buttons_GetState()) { if (i) puts ("Putz01HandleButtons() Looping\r"); i = 0; } if (HAL_GetTick() > tickEvent) { static bool onOff = false; LED_SetOut(onOff ? 2 : 1); onOff = !onOff; tickEvent = HAL_GetTick() + EVENT_INTERVAL; } return true; }
/*---------------------------------------------------------------------------- * main: initialize and start the system *----------------------------------------------------------------------------*/ int main (void) { uint32_t button_msk = (1U << Buttons_GetCount()) - 1; osKernelInitialize (); // initialize CMSIS-RTOS // initialize peripherals SystemCoreClockConfigure(); // configure System Clock SystemCoreClockUpdate(); LED_Initialize(); // LED Initialization Buttons_Initialize(); // Buttons Initialization // create threads tid_blinkLED = osThreadCreate (osThread(blinkLED), NULL); osKernelStart (); // start thread execution for (;;) { // main must not be terminated! osDelay(500); while (Buttons_GetState() & (button_msk)); // Wait while holding USER button osSignalSet(tid_blinkLED, 0x0001); } }
int main() { SysTick_Config(SystemCoreClock/100); magazyn = malloc(sizeof(Element)*1200); Timer3Conf(); Joystick_Initialize(); Buttons_Initialize(); initDisplay(); lcdClean(); Timer3Disable(); Timer1Conf(); lcdMenu(); while(1) { while(tickCounter<10); tickCounter=0; switch(Buttons_GetState()) { case BUTTON_INT0: //lcdClean(); initSnake(); game = 1; while(game == 1) { //while(tickCounter<10); //tickCounter=0; inputControl = 0; switch(Joystick_GetState()) { case JOYSTICK_UP: inputControl = 1; break; case JOYSTICK_LEFT: inputControl = 2; break; case JOYSTICK_DOWN: inputControl = 4; break; case JOYSTICK_RIGHT: inputControl = 8; break; default: inputControl = oldControl; } if(inputControl == forbidden) inputControl = oldControl; if(reactCount > 0) { game = react(inputControl); --reactCount; } } lcdString(250, 150, "Koniec gry"); while(1); break; case BUTTON_KEY1: lcdString(250, 150, "Opcja 2"); while(1); break; case BUTTON_KEY2: lcdString(250, 150, "Opcja 3"); while(1); break; } } return 0; }
void AppShooter() { while (!stopShooter) { joyMsk = Joystick_GetState(); btnMsk = Buttons_GetState(); if (timerTick_01 > 2) { if (ballTimer != 0) { ballTimer--; } if ( ((btnMsk & 1) != 0) && (ballTimer == 0) ) { ballTimer = 8; newBall = true; } if (joyMsk != 0) { osMutexWait(planeVar_mutex_id, osWaitForever); // RIGHT if ((plane_x < GLCD_WIDTH - 10) && ((joyMsk & 2) != 0)) { plane_x += 10; } // LEFT if ((plane_x > 0) && ((joyMsk & 1) != 0)) { plane_x -= 10; } // UP if ((plane_y > 20) && ((joyMsk & 8) != 0)) { plane_y -= 10; } // DOWN if ((plane_y < GLCD_HEIGHT - 10) && ((joyMsk & 16) != 0)) { plane_y += 10; } osMutexRelease(planeVar_mutex_id); } timerTick_01 = 0; S_MoveBall(newBall); newBall = false; } if ( timerTick_02 > 12 ) { S_MoveObjects (); timerTick_02 = 0; } } osThreadTerminate (idThreadPlane); osDelay(500); if (playerScore > machineScore) { GLCD_SetForegroundColor (GLCD_COLOR_GREEN); GLCD_DrawString ((GLCD_WIDTH-16*9)/2, GLCD_HEIGHT/2-16, "YOU WIN !"); } else { GLCD_SetForegroundColor (GLCD_COLOR_RED); GLCD_DrawString ((GLCD_WIDTH-16*11)/2, GLCD_HEIGHT/2-16, "YOU LOSE !"); } osDelay(2000); }
int main (void) { int32_t max_num = LED_GetCount() - 1; int32_t num = 0; int32_t dir = 1; uint32_t keyMsk, adcVal; int32_t key = -1; int32_t adc = -1; SystemCoreClockUpdate(); LED_Initialize(); /* LED Initialization */ ADC_Initialize(); /* A/D Converter Init */ Buttons_Initialize(); /* Button initialization */ GLCD_Initialize(); /* Initialize the GLCD */ SysTick_Config(SystemCoreClock/100); /* Generate interrupt each 10 ms */ GLCD_SetBackgroundColor (GLCD_COLOR_WHITE); GLCD_ClearScreen (); GLCD_SetBackgroundColor (GLCD_COLOR_BLUE); GLCD_SetForegroundColor (GLCD_COLOR_WHITE); GLCD_SetFont (&GLCD_Font_16x24); GLCD_DrawString (0*16, 0*24, " STM32303C-EVAL Demo"); GLCD_DrawString (0*16, 1*24, " Blinky Example "); GLCD_DrawString (0*16, 2*24, " www.keil.com "); GLCD_SetBackgroundColor (GLCD_COLOR_WHITE); GLCD_SetForegroundColor (GLCD_COLOR_BLUE); GLCD_DrawString (0*16, 5*24, "LEDs: "); GLCD_DrawString (0*16, 6*24, "AD value: "); GLCD_DrawString (0*16, 7*24, "Buttons : "); GLCD_SetForegroundColor (GLCD_COLOR_LIGHT_GREY); GLCD_DrawString (9*16, 5*24, "0123"); while (1) { /* Force refresh */ key = -1; adc = -1; if (LEDOn) { LEDOn = 0; LED_On (num); /* Turn specified LED on */ GLCD_SetForegroundColor (GLCD_COLOR_RED); GLCD_DrawChar ((9+num)*16, 5*24, numStr[num]); } if (LEDOff) { LEDOff = 0; LED_Off (num); /* Turn specified LED off */ GLCD_SetForegroundColor (GLCD_COLOR_LIGHT_GREY); GLCD_DrawChar ((9+num)*16, 5*24, numStr[num]); num += dir; /* Change LED number */ if (dir == 1 && num == max_num) { dir = -1; /* Change direction to down */ } else if (num == 0) { dir = 1; /* Change direction to up */ } } keyMsk = Buttons_GetState(); /* Show buttons state */ if (key ^ keyMsk) { GLCD_SetForegroundColor (GLCD_COLOR_BLACK); if (keyMsk & KEY_USER ) { GLCD_DrawString (9*16, 7*24, "Key"); } GLCD_SetForegroundColor (GLCD_COLOR_LIGHT_GREY); if (!(keyMsk & KEY_USER )) { GLCD_DrawString (9*16, 7*24, "Key"); } } ADC_StartConversion(); /* Show A/D conversion bargraph */ adcVal = ADC_GetValue(); if (adc ^ adcVal) { adc = adcVal; GLCD_SetForegroundColor (GLCD_COLOR_GREEN); GLCD_DrawBargraph (9*16, 6*24, 160, 20, (adcVal * 100) / ((1 << ADC_GetResolution()) - 1)); } } }