Isabelle Murollo
/
Projeto_CCM_Maquinas_MotorDC
Centro de Controle de Motores parte 2
Diff: dc.cpp
- Revision:
- 4:1dcc28a7a849
- Child:
- 5:6f3ae0856d64
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dc.cpp Thu Dec 01 19:38:52 2022 +0000 @@ -0,0 +1,80 @@ +/******************************************* +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 "); + } + } +} \ No newline at end of file