aps de maquinas eletricas stephanie liu

Dependencies:   mbed

Committer:
stephanie_liu
Date:
Tue Sep 14 02:00:01 2021 +0000
Revision:
0:4e66272535f2
aps 1 - stephanie liu;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
stephanie_liu 0:4e66272535f2 1 #include "mbed.h"
stephanie_liu 0:4e66272535f2 2 //configuração de portas
stephanie_liu 0:4e66272535f2 3 AnalogIn POT(A5);
stephanie_liu 0:4e66272535f2 4 PwmOut ENA(D2);
stephanie_liu 0:4e66272535f2 5 DigitalOut IN1A(D5);
stephanie_liu 0:4e66272535f2 6 DigitalOut IN2A(D4);
stephanie_liu 0:4e66272535f2 7 InterruptIn ENCONDER(D3);
stephanie_liu 0:4e66272535f2 8
stephanie_liu 0:4e66272535f2 9 Timer tempo;
stephanie_liu 0:4e66272535f2 10 int pulsos =0;
stephanie_liu 0:4e66272535f2 11 const int HIGH = 1;
stephanie_liu 0:4e66272535f2 12 const int LOW = 0;
stephanie_liu 0:4e66272535f2 13 const int fonte = 12;
stephanie_liu 0:4e66272535f2 14
stephanie_liu 0:4e66272535f2 15 //abertura de porta serial com a conexão USB
stephanie_liu 0:4e66272535f2 16 Serial pc(USBTX, USBRX);
stephanie_liu 0:4e66272535f2 17
stephanie_liu 0:4e66272535f2 18
stephanie_liu 0:4e66272535f2 19 void Contador_BD(){pulsos++;}
stephanie_liu 0:4e66272535f2 20
stephanie_liu 0:4e66272535f2 21 void Motor_A(float duty_cyle){
stephanie_liu 0:4e66272535f2 22 IN1A = LOW;
stephanie_liu 0:4e66272535f2 23 IN2A = HIGH;
stephanie_liu 0:4e66272535f2 24 ENA.write(duty_cyle);
stephanie_liu 0:4e66272535f2 25 }
stephanie_liu 0:4e66272535f2 26
stephanie_liu 0:4e66272535f2 27 int main(){
stephanie_liu 0:4e66272535f2 28 pc.baud(9600);
stephanie_liu 0:4e66272535f2 29 tempo.start();
stephanie_liu 0:4e66272535f2 30 ENCONDER.fall(&Contador_BD);
stephanie_liu 0:4e66272535f2 31 while(true){
stephanie_liu 0:4e66272535f2 32 float velocidade = POT.read();
stephanie_liu 0:4e66272535f2 33 Motor_A(velocidade);
stephanie_liu 0:4e66272535f2 34 if(tempo.read_ms() >= 1000){
stephanie_liu 0:4e66272535f2 35 pc.printf("TENSAO ARMADURA: %f\n\r", fonte*velocidade);
stephanie_liu 0:4e66272535f2 36 pc.printf("RPM: %d\n\r",pulsos*2);
stephanie_liu 0:4e66272535f2 37 pulsos=0;
stephanie_liu 0:4e66272535f2 38 tempo.reset();
stephanie_liu 0:4e66272535f2 39 }
stephanie_liu 0:4e66272535f2 40
stephanie_liu 0:4e66272535f2 41 }
stephanie_liu 0:4e66272535f2 42 }