Classwork

Classwork

Skeleton code

Remember to add the function prototypes in main.c for the declaration of the functions, as follow:

/* main.c */
/* USER CODE BEGIN PFP */
void gpio_classwork(void);
void tft_classwork(void);
/* USER CODE END PFP */

Task 1 :GPIO

  • When BTN1 is held, LED1 should be on. (@1)

  • When BTN2 is held, LED2 should be flashing (toggle in 50ms).(@1)

  • When both BTN1 and BTN2 are held, the following sequence is conducted:(@2)

    • LED1 and LED3 are on while LED2 are flashing.

    • After 1 second, LED1 and LED3 are flashing while LED2 are on.

    • After 1 second, repeat from step 1.

  • Keyword: Finite State Machine

  • LED1 RED

  • LED2 GREEN

  • LED3 BLUE

  • BTN1 RED one

  • BTN2 GREEN one

  • Order: BTN2 -> BTN1 -> BTN1 & BTN2

Task 2 :TFT

  • Print the time elapsed with the format of mm:ss:sssZ where sssZ means millisecond. e.g. 00:23:109 (@2)

  • Print a 50px * 50px square directly under the elapsed time where its color changes when 1 second passed.(@2)

  • Keywords: HAL_GetTick

  • Hints:

    • Integer division

    • 1 min = 60 second, 1 second = 1000 milliseconds

    • Read the function prototypes in Core/Inc/lcd/lcd.h for more tft_print functions that you can use.

    • The actual size of square printed on TFT should be larger than this one

Last updated