Isabelle Murollo
/
Projeto_CCM_Maquinas_MotorDC
Centro de Controle de Motores parte 2
dc.cpp
- Committer:
- isabellemm
- Date:
- 17 months ago
- Revision:
- 4:1dcc28a7a849
- Child:
- 5:6f3ae0856d64
File content as of revision 4:1dcc28a7a849:
/******************************************* Motor de DC *******************************************/ #include "mbed.h" #include "TextLCD.h" Serial pc(USBTX, USBRX); 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 = 'a'; char desligado = 'b'; int estado = 0; // motor DigitalOut IN1A (D5); DigitalOut IN2A (D4); PwmOut ENA (D2); // 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(); } int main(){ enable.rise(&muda_e); debounce.start(); ENA.write(0); pc.baud(115200); //Inicializando display LCD lcd.setCursor(TextLCD::CurOff_BlkOn); lcd.setBacklight(TextLCD::LightOn); lcd.printf("Motor 1: \n\nMotor 2: "); while(1){ if(estado == 1){ //pc.printf("%c", ligado); lcd.setAddress(9,0); lcd.printf("ON "); if (POT.read()>0.1f){ ENA.write(POT.read()); if (dir.read() == 0){ IN1A = 1; IN2A = 0; lcd.setAddress(13,0); lcd.printf("HORARIO"); } else{ IN1A = 0; IN2A = 1; lcd.setAddress(13,0); lcd.printf("ANTIHOR"); } } } else{ ENA.write(0); //pc.printf("%c",desligado); lcd.setAddress(9,0); lcd.printf("OFF "); } } }