Last active
May 13, 2019 00:05
-
-
Save fabioars/91d3584b72ff1757398a858884e533f3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| // Cria uma estrutura para leitura do circuito | |
| typedef struct { | |
| float potenciaDijuntor; | |
| float corrente; | |
| float tensao; | |
| } Circuito; | |
| // Cria assinatura da função que vai soar o alarme | |
| int soarAlarme(Circuito c); | |
| int main() { | |
| // Define o circuito que vai ser usado | |
| Circuito c; | |
| c.potenciaDijuntor = 35; | |
| c.corrente = 1.5; //sensorCorrente(); | |
| c.tensao = 12; //sensorTensao(); | |
| // Recebe o valor que vai definir se o alarme vai soar ou não | |
| int valorAlarme = soarAlarme(c); | |
| printf("Valor Alarme: %d\n", valorAlarme); | |
| // Cria um circuito de testes que o alarme iria soar | |
| Circuito c2; | |
| c2.potenciaDijuntor = 10; | |
| c2.corrente = 6; | |
| c2.tensao = 500; | |
| valorAlarme = soarAlarme(c2); | |
| printf("Valor Alarme: %d\n", valorAlarme); | |
| return 0; | |
| } | |
| int soarAlarme(Circuito c) { | |
| // Calcula a potência | |
| float potencia = c.corrente * c.tensao; | |
| // Verifica se a potência é maior igual a potência do dijuntor | |
| if (potencia >= c.potenciaDijuntor) { | |
| return 1; // Dispara o alarme | |
| } | |
| return 0; // Não dispara o alarme | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| int main() { | |
| float potenciaDijuntor = 35; | |
| float corrente = 1.5; | |
| float tensao = 12; | |
| int valorAlarme; | |
| if (potenciaDijuntor >= corrente * tensao) { | |
| valorAlarme = 1; | |
| } else { | |
| valorAlarme = 0; | |
| } | |
| return valorAlarme; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment