> For the complete documentation index, see [llms.txt](https://hkust-robotics-team.gitbook.io/hkust-robotics-team-software-tutorial/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hkust-robotics-team.gitbook.io/hkust-robotics-team-software-tutorial/tutorial/tutorial-2-basic-io/classwork.md).

# Classwork

## **Classwork**

### Skeleton code

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

```c
/* 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

![](https://i.imgur.com/zF0Q2Lg.gif)

* 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:
  * $$1234 \mod 10 = 4$$
  * Integer division &#x20;
    * $$\frac{1234}{10} = 123$$
  * 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.
* ![](https://i.imgur.com/2K6QaHR.gif)
  * The actual size of square printed on TFT should be larger than this one

> :warning: Don't use`__forceinline static void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)` as it seems to cause error
