/* * problema1.c * * Created on: Aug 5, 2021 * Author: Internship */ #include "problema1.h" #include "menu.h" int count_time=0,blink_led1_count=0,blink_led0_count=0,count_btn1=0,count_btn0=0,blink_state0_show=0,blink_state1_show=0,blink_state1=0,blink_state0=0,count_debounce0=0,count_debounce1=0; bool past_button1_state=1,past_button0_state=1,pressed_btn1=1,pressed_btn0=1,problema1_show=true; void debounce_pb0() { live_button0_state=stare_pb0; if(past_button0_state != live_button0_state) { count_debounce0++; if(count_debounce0 >= DEBOUNCE_TIME) { count_debounce0 = 0; } else { live_button0_state = past_button0_state; } } } void debounce_pb1() { live_button1_state=stare_pb1; if(past_button1_state != live_button1_state) { count_debounce1++; if(count_debounce1 >= DEBOUNCE_TIME) { count_debounce1 = 0; } else { live_button1_state = past_button1_state; } } } void problema1_print() { printf("\f"); printf("\n Problema1\n\n Control leds\n with PB0 and PB1\n\n Press PB0+PB1 to go\n back."); } void Problema1(){ if(problema1_show==true){ problema1_print(); problema1_show=false; } live_button0_state=stare_pb0; live_button1_state=stare_pb1; /* Button PB0 pressing(Led toggle) and long press(Led blink 1 second frequency) */ if(live_button0_state==0){ count_btn0++; } else{ count_btn0=0; } if(count_btn0==long_press){ blink_state0=1; blink_state0_show=1; } if(blink_state0==1){ blink_led0_count++; if(blink_led0_count>100){ BSP_LedToggle(0); blink_led0_count=0; } } if(blink_state0_show==1){ blink_state0_show=0; } if(live_button0_state==0 && past_button0_state==1){ blink_state0=0; count_btn0=0; past_button0_state=0; pressed_btn0=!pressed_btn0; if(!pressed_btn0){ BSP_LedToggle(0); } else{ BSP_LedClear(0); } } if(live_button0_state == 1){ past_button0_state = 1; } /* Button PB1 pressing(Led toggle) and double press(Led blink 2 seconds frequency) */ if(count_btn1==1){ count_time++; } if(count_time>short_press){ count_btn1=0; count_time=0; } if(count_btn1==2 && count_time<short_press){ blink_state1=1; count_time=0; blink_state1_show=1; count_btn1=0; } if(blink_state1==1){ blink_led1_count++; if(blink_led1_count>200){ BSP_LedToggle(1); blink_led1_count=0; } } if(blink_state1_show==1){ blink_state1_show=0; } if(live_button1_state==0 && past_button1_state==1){ blink_state1=0; past_button1_state=0; pressed_btn1=!pressed_btn1; count_btn1++; if(!pressed_btn1){ BSP_LedToggle(1); } else{ BSP_LedClear(1); } } if(live_button1_state==1){ past_button1_state=1; } /* Go back to the menu */ if(live_button0_state==0 && live_button1_state==0){ BSP_LedClear(0); BSP_LedClear(1); problema1_show=true; state=menuShow; } } /* * problema1.h * * Created on: Aug 5, 2021 * Author: Internship */ #include <stdlib.h> #include <stdio.h> #include "em_device.h" #include <stdint.h> #include "em_chip.h" #include "em_cmu.h" #include "bsp.h" #include "em_adc.h" #include "em_gpio.h" #include "em_emu.h" #include "display.h" #include "capsense_touchh3.h" #include "textdisplay.h" #include "capsenseconfig_spaceinvaders.h" #include "retargettextdisplay.h" #include "../emlib/em_timer.h" #include "bspconfig.h" #ifndef SRC_PROBLEMA1_H_ #define SRC_PROBLEMA1_H_ #define DEBOUNCE_TIME 30 #define long_press 70 #define short_press 50 #define stare_pb0 GPIO_PinInGet(BSP_GPIO_PB0_PORT,BSP_GPIO_PB0_PIN) #define stare_pb1 GPIO_PinInGet(BSP_GPIO_PB1_PORT,BSP_GPIO_PB1_PIN) bool pressed_btn0, pressed_btn1, past_button0_state, past_button1_state, problema1_show,live_button0_state, live_button1_state; int count_btn0, count_btn1, blink_led0_count, blink_led1_count, count_time, blink_state0_show, blink_state1_show, blink_state0, blink_state1; void Problema1(); void problema1_print(); void debounce_pb0(); void debounce_pb1(); #endif /* SRC_PROBLEMA1_H_ */ /* * menu.c * * Created on: Aug 10, 2021 * Author: Internship */ #include "menu.h" #include "problema1.h" #include "problema2.h" int arrow=1; void MenuSelection() /* Function for rendering the main Menu */ { if(arrow>NR_OPTIUNI) { arrow=1; } printf("\f\n\n"); printf("Internship AROBS 2021\n\n"); MOVE_CURSOR8; printf("MENU\n\n"); MOVE_CURSOR6; printf("Program 1"); if(arrow==1) { printf(" <<"); } printf("\n\n"); MOVE_CURSOR6; printf("Program 2"); if(arrow==2) { printf(" <<"); } printf("\n\n"); MOVE_CURSOR6; printf("Program 3"); if(arrow==3) { printf(" <<"); } printf("\n\n\n\t PB1- choose\n\t PB0- select"); } void Menu_Init() { state=menuShow; } /* Using the PB0 and PB1 buttons to choose a problem */ void Menu() { live_button0_state=stare_pb0; live_button1_state=stare_pb1; switch(state) { case menuShow: MenuSelection(); state=menuSelect; break; case menuSelect: if(live_button1_state==0 && past_button1_state==1) { past_button1_state=0; arrow++; state=menuShow; } if(live_button0_state==0 && arrow==1 && past_button0_state==1) { past_button0_state=0; state=problema1; } if(live_button0_state==0 && arrow==2 && past_button0_state==1) { past_button0_state=0; state=problema2; } if(live_button0_state==0 && arrow==3 && past_button0_state==1) { past_button0_state=0; state=problema3; } if(live_button1_state==1) { past_button1_state=1; } if(live_button0_state==1) { past_button0_state=1; } break; case problema1: Problema1(); break; case problema2: Problema2(); break; case problema3: Problema3(); break; } }