Skip to content

Commit ed95b9c

Browse files
committed
Implemented last pressed key
1 parent 25d5f94 commit ed95b9c

File tree

7 files changed

+11181
-11102
lines changed

7 files changed

+11181
-11102
lines changed

Core/Src/main.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ char default_artist[23] = "No artist playing\0";
8585
// Buffer to store the received data from UART
8686
uint8_t RX_DATA[44];
8787

88+
// Last key pressed
89+
char last_key[2] = " ";
90+
8891
/* USER CODE END PV */
8992

9093
/* Private function prototypes -----------------------------------------------*/
@@ -220,7 +223,7 @@ void ADC_read(void)
220223
static uint32_t last_update_time_4 = 0;
221224
uint32_t current_time_4 = HAL_GetTick();
222225

223-
if (current_time_4 - last_update_time_4 >= 100)
226+
if (current_time_4 - last_update_time_4 >= 100)
224227
{
225228
last_update_time_4 = current_time_4;
226229

@@ -251,6 +254,8 @@ void ADC_read(void)
251254
display_values3[0] = (int)converted_result3 / 10 + 48; // Convert the result to a string
252255
display_values3[1] = (int)converted_result3 % 10 + 48; // Convert the result to a string
253256
display_values3[2] = '\0'; // Null-terminate the string
257+
258+
sendThroughUART();
254259
}
255260
}
256261
/**
@@ -303,8 +308,9 @@ void updateScreen()
303308
u8g2_DrawStr(&u8g2, 50, 18, hoursandminutes);
304309
u8g2_DrawLine(&u8g2, 0, 20, 128, 20);
305310
u8g2_DrawLine(&u8g2, 20, 0, 20, 20);
306-
u8g2_DrawCircle(&u8g2, 10, 10, 7, U8G2_DRAW_ALL);
307311
u8g2_SetFont(&u8g2, u8g2_font_t0_12b_tf);
312+
u8g2_DrawCircle(&u8g2, 10, 10, 7, U8G2_DRAW_ALL);
313+
u8g2_DrawStr(&u8g2, 8, 13, last_key);
308314
u8g2_DrawStr(&u8g2, 20, 55, "Listening to:");
309315
u8g2_DrawStr(&u8g2, 2, 70, song);
310316
u8g2_DrawStr(&u8g2, 50, 80, "by");
@@ -363,30 +369,39 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
363369
{
364370
case BUT1_Pin:
365371
HAL_UART_Transmit(&huart1, (uint8_t *)"key1\0", 5, 1000);
372+
last_key[0] = '1';
366373
break;
367374
case BUT2_Pin:
368375
HAL_UART_Transmit(&huart1, (uint8_t *)"key2\0", 5, 1000);
376+
last_key[0] = '2';
369377
break;
370378
case BUT3_Pin:
371379
HAL_UART_Transmit(&huart1, (uint8_t *)"key3\0", 5, 1000);
380+
last_key[0] = '3';
372381
break;
373382
case BUT4_Pin:
374383
HAL_UART_Transmit(&huart1, (uint8_t *)"key4\0", 5, 1000);
384+
last_key[0] = '4';
375385
break;
376386
case BUT5_Pin:
377387
HAL_UART_Transmit(&huart1, (uint8_t *)"key5\0", 5, 1000);
388+
last_key[0] = '5';
378389
break;
379390
case BUT6_Pin:
380391
HAL_UART_Transmit(&huart1, (uint8_t *)"key6\0", 5, 1000);
392+
last_key[0] = '6';
381393
break;
382394
case BUT7_Pin:
383395
HAL_UART_Transmit(&huart1, (uint8_t *)"key7\0", 5, 1000);
396+
last_key[0] = '7';
384397
break;
385398
case BUT8_Pin:
386399
HAL_UART_Transmit(&huart1, (uint8_t *)"key8\0", 5, 1000);
400+
last_key[0] = '8';
387401
break;
388402
case BUT9_Pin:
389403
HAL_UART_Transmit(&huart1, (uint8_t *)"key9\0", 5, 1000);
404+
last_key[0] = '9';
390405
break;
391406
default:
392407
break;
@@ -491,8 +506,6 @@ int main(void)
491506
// update the screen
492507
updateScreen();
493508

494-
sendThroughUART();
495-
496509
updateHour();
497510

498511
/* USER CODE END WHILE */

Debug/Core/Src/main.cyclo

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
../Core/Src/main.c:97:9:u8x8_stm32_gpio_and_delay 6
2-
../Core/Src/main.c:122:9:u8x8_byte_4wire_hw_spi 6
3-
../Core/Src/main.c:147:6:clearOLED 2
4-
../Core/Src/main.c:155:6:setFirstHour 1
5-
../Core/Src/main.c:166:6:getHour 1
6-
../Core/Src/main.c:182:6:updateHour 4
7-
../Core/Src/main.c:218:6:ADC_read 4
8-
../Core/Src/main.c:255:6:HAL_UART_RxCpltCallback 2
9-
../Core/Src/main.c:282:6:updateScreen 3
10-
../Core/Src/main.c:325:6:constructSkeleton 2
11-
../Core/Src/main.c:348:6:HAL_GPIO_EXTI_Callback 18
12-
../Core/Src/main.c:399:6:sendThroughUART 1
13-
../Core/Src/main.c:417:5:main 3
14-
../Core/Src/main.c:503:6:SystemClock_Config 3
15-
../Core/Src/main.c:550:13:MX_ADC1_Init 5
16-
../Core/Src/main.c:622:13:MX_SPI1_Init 2
17-
../Core/Src/main.c:660:13:MX_USART1_UART_Init 2
18-
../Core/Src/main.c:693:13:MX_GPIO_Init 1
19-
../Core/Src/main.c:752:6:Error_Handler 1
1+
../Core/Src/main.c:100:9:u8x8_stm32_gpio_and_delay 6
2+
../Core/Src/main.c:125:9:u8x8_byte_4wire_hw_spi 6
3+
../Core/Src/main.c:150:6:clearOLED 2
4+
../Core/Src/main.c:158:6:setFirstHour 1
5+
../Core/Src/main.c:169:6:getHour 1
6+
../Core/Src/main.c:185:6:updateHour 4
7+
../Core/Src/main.c:221:6:ADC_read 5
8+
../Core/Src/main.c:267:6:HAL_UART_RxCpltCallback 2
9+
../Core/Src/main.c:294:6:updateScreen 3
10+
../Core/Src/main.c:338:6:constructSkeleton 2
11+
../Core/Src/main.c:361:6:HAL_GPIO_EXTI_Callback 18
12+
../Core/Src/main.c:421:6:sendThroughUART 1
13+
../Core/Src/main.c:439:5:main 3
14+
../Core/Src/main.c:522:6:SystemClock_Config 3
15+
../Core/Src/main.c:569:13:MX_ADC1_Init 5
16+
../Core/Src/main.c:641:13:MX_SPI1_Init 2
17+
../Core/Src/main.c:679:13:MX_USART1_UART_Init 2
18+
../Core/Src/main.c:712:13:MX_GPIO_Init 1
19+
../Core/Src/main.c:771:6:Error_Handler 1

Debug/Core/Src/main.o

660 Bytes
Binary file not shown.

Debug/Core/Src/main.su

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
../Core/Src/main.c:97:9:u8x8_stm32_gpio_and_delay 24 static
2-
../Core/Src/main.c:122:9:u8x8_byte_4wire_hw_spi 24 static
3-
../Core/Src/main.c:147:6:clearOLED 8 static
4-
../Core/Src/main.c:155:6:setFirstHour 16 static
5-
../Core/Src/main.c:166:6:getHour 4 static
6-
../Core/Src/main.c:182:6:updateHour 16 static
7-
../Core/Src/main.c:218:6:ADC_read 24 static
8-
../Core/Src/main.c:255:6:HAL_UART_RxCpltCallback 24 static
9-
../Core/Src/main.c:282:6:updateScreen 24 static
10-
../Core/Src/main.c:325:6:constructSkeleton 8 static
11-
../Core/Src/main.c:348:6:HAL_GPIO_EXTI_Callback 24 static
12-
../Core/Src/main.c:399:6:sendThroughUART 8 static
13-
../Core/Src/main.c:417:5:main 8 static
14-
../Core/Src/main.c:503:6:SystemClock_Config 88 static
15-
../Core/Src/main.c:550:13:MX_ADC1_Init 24 static
16-
../Core/Src/main.c:622:13:MX_SPI1_Init 8 static
17-
../Core/Src/main.c:660:13:MX_USART1_UART_Init 8 static
18-
../Core/Src/main.c:693:13:MX_GPIO_Init 40 static
19-
../Core/Src/main.c:752:6:Error_Handler 4 static,ignoring_inline_asm
1+
../Core/Src/main.c:100:9:u8x8_stm32_gpio_and_delay 24 static
2+
../Core/Src/main.c:125:9:u8x8_byte_4wire_hw_spi 24 static
3+
../Core/Src/main.c:150:6:clearOLED 8 static
4+
../Core/Src/main.c:158:6:setFirstHour 16 static
5+
../Core/Src/main.c:169:6:getHour 4 static
6+
../Core/Src/main.c:185:6:updateHour 16 static
7+
../Core/Src/main.c:221:6:ADC_read 24 static
8+
../Core/Src/main.c:267:6:HAL_UART_RxCpltCallback 24 static
9+
../Core/Src/main.c:294:6:updateScreen 24 static
10+
../Core/Src/main.c:338:6:constructSkeleton 8 static
11+
../Core/Src/main.c:361:6:HAL_GPIO_EXTI_Callback 24 static
12+
../Core/Src/main.c:421:6:sendThroughUART 8 static
13+
../Core/Src/main.c:439:5:main 8 static
14+
../Core/Src/main.c:522:6:SystemClock_Config 88 static
15+
../Core/Src/main.c:569:13:MX_ADC1_Init 24 static
16+
../Core/Src/main.c:641:13:MX_SPI1_Init 8 static
17+
../Core/Src/main.c:679:13:MX_USART1_UART_Init 8 static
18+
../Core/Src/main.c:712:13:MX_GPIO_Init 40 static
19+
../Core/Src/main.c:771:6:Error_Handler 4 static,ignoring_inline_asm

Debug/Screen_example.elf

320 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)