Isabelle Murollo
/
Projeto_CCM_Maquinas_MotorDC
Centro de Controle de Motores parte 2
motor_DC_v2.txt
- Committer:
- isabellemm
- Date:
- 17 months ago
- Revision:
- 4:1dcc28a7a849
File content as of revision 4:1dcc28a7a849:
#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 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(); } 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: "); while(1){ pc.printf("recomeca\n"); //recebe.printf("aaaa"); mensagem = recebe.getc(); //recebe.scanf("%c", &mensagem); pc.printf("%c\n", mensagem); if (mensagem == 'a'){ estado = 0; lcd.printf("\roi\n"); } if(estado == 1){ //recebe.printf("%c", ligado); pc.printf("ligado\n"); 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); pc.printf("deslig\n"); //recebe.printf("%c", desligado); } } }