/*
 * led-state-2.c
 *
 *  Created on: Oct 3, 2018
 *      Author: corrado
 */

#include "stm32_unict_lib.h"

int main(void)
{
	GPIO_init(GPIOB);
	GPIO_config_output(GPIOB, 0);
	GPIO_config_input(GPIOB, 10);
	int prev_state = GPIO_read(GPIOB, 10);
	int flash_state = 0;
	for(;;) {
		int current_state = GPIO_read(GPIOB, 10);
		if (prev_state == 1 && current_state == 0)
			flash_state = !flash_state;

		if (flash_state == 1) {
			GPIO_toggle(GPIOB, 0);
			delay_ms(500);
		}
		else
			GPIO_write(GPIOB,0, 0);

		prev_state = current_state;
	}
	return 0;
}

