Skip to content

Instantly share code, notes, and snippets.

@OtacilioN
Created September 9, 2020 02:16
Show Gist options
  • Save OtacilioN/75009ed3089739e3eae94d23623d9516 to your computer and use it in GitHub Desktop.
Save OtacilioN/75009ed3089739e3eae94d23623d9516 to your computer and use it in GitHub Desktop.
Faça a Seguinte prática usando a IDE Mbed e a placa STM-Núcleo e poste aqui o código fonte: O sistema deve conter um contador que é incrementado a cada 500 milisegundos; Ao ser pressionado o botão de usuário deverá ser enviado o valor do contador pela serial e esse deverá ser resetado; Se for recebido pela Serial o valor ASCII "g" o led verde da…
#include "millis.h"
#include "mbed.h"
DigitalOut ledVerde(LED1);
DigitalOut ledExterno(PA_9,0);
DigitalIn botao(USER_BUTTON, PullUp);
Serial pc(SERIAL_TX, SERIAL_RX);
volatile char c = '\0';
void onCharReceived()
{
c = pc.getc();
if(c == 'g')
{
ledVerde = !ledVerde;
}
if(c == 'r')
{
ledExterno = !ledExterno;
}
}
int main(){
millisStart();
pc.attach(&onCharReceived);
unsigned long int startTime = millis();
unsigned long int debounceStartTime = millis();
unsigned int contador = 0;
while(1){
unsigned long int currentTime = millis();
if(currentTime - startTime > 500){
startTime = millis();
contador++;
}
if(botao == 0){
if(currentTime - debounceStartTime > 150){
pc.printf("%d\n", contador);
contador = 0;
debounceStartTime = millis();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment