summaryrefslogtreecommitdiff
path: root/project/Core/Src/Activties/activity9.c
blob: 0ca1e7b26cc449621cca4b9d0ac3a05af4b20df2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
 * activity9.c
 *
 *  Created on: Oct 23, 2025
 *      Author: sowgro
 */

#include "GPIO.h"
#include <stdint.h>
#include "stm32l4xx.h"
#include "LED.h"
#include <stdio.h>

// write a function that prints on/off when the blue button is pressed

void activity9_run() {
	GPIO_Init();
	int prev_status = -1;
	for (;;) {
		int status = !(B1_GPIO_Port->IDR & B1_Pin);
		if (status != prev_status) {
			prev_status = status;
			if (status) {
				printf("on\r\n");
				LED_On();
			} else {
				printf("off\r\n");
				LED_Off();
			}
		}
	}
}