Isabelle Murollo
/
Projeto_CCM_Maquinas_MotorDC
Centro de Controle de Motores parte 2
motor_DC.txt
- Committer:
- isabellemm
- Date:
- 16 months ago
- Revision:
- 5:6f3ae0856d64
- Parent:
- 4:1dcc28a7a849
File content as of revision 5:6f3ae0856d64:
#include "mbed.h" #include "TextLCD.h" //Serial pc(USBTX, USBRX); Serial recebe(D14, D15); I2C i2c_lcd(I2C_SDA, I2C_SCL); // SDA, SCL >>> NUCLEO: D14,D15 ou TextLCD_I2C lcd(&i2c_lcd, 0x7e, TextLCD::LCD20x4); // variáveis char ligado = 'c'; char desligado = 'd'; char mensagem; int estado = 0; // motor DigitalOut IN1A (D5); DigitalOut IN2A (D4); PwmOut ENA (D2); // saídas - tirar DigitalOut led (LED1); // entradas InterruptIn enable (D9); DigitalIn dir (D10); AnalogIn POT (A5); // debouncing Timer debounce; void muda_e(){ if (debounce.read_ms()>200){ estado=!estado; } debounce.reset(); } void queda(){ debounce.reset(); } void RX_interrupt(){ /*while (recebe.readable()){ mensagem = recebe.getc(); pc.printf("%c",mensagem); }*/ led=!led; } int main(){ enable.rise(&muda_e); debounce.start(); ENA.write(0); recebe.baud(9600); //Inicializando display LCD lcd.setCursor(TextLCD::CurOff_BlkOn); lcd.setBacklight(TextLCD::LightOn); lcd.printf("Motor 1: \n\nMotor 2: "); //recebe.attach(&RX_interrupt, Serial::RxIrq); while(1){ //mensagem = recebe.getc(); if (mensagem == 'a'){ estado = 1; //pc.printf("liga\n"); } else if (mensagem == 'b'){ estado = 0; //pc.printf("desliga\n"); } if(estado == 1){ recebe.printf("%c", ligado); if (POT.read()>0.1f){ ENA.write(POT.read()); if (dir.read() == 0){ IN1A = 1; IN2A = 0; } else{ IN1A = 0; IN2A = 1; } } } else{ ENA.write(0); recebe.printf("%c", desligado); } } }