Isabelle Murollo
/
Projeto_CCM_Maquinas_MotorDC
Centro de Controle de Motores parte 2
Revision 5:6f3ae0856d64, committed 24 months ago
- Comitter:
- isabellemm
- Date:
- Fri Dec 02 15:58:02 2022 +0000
- Parent:
- 4:1dcc28a7a849
- Commit message:
- Serial
Changed in this revision
dc.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 1dcc28a7a849 -r 6f3ae0856d64 dc.cpp --- a/dc.cpp Thu Dec 01 19:38:52 2022 +0000 +++ b/dc.cpp Fri Dec 02 15:58:02 2022 +0000 @@ -1,80 +1,32 @@ -/******************************************* -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); +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); +int main() +{ pc.baud(115200); + led = 0; + char c; - //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 "); + pc.printf("Centro de Controle de Motores\n"); + pc.printf("-----------------------------\n"); + pc.printf("\rAperte 1 para ligar o motor CC\n"); + pc.printf("Aperte 2 para ligar o motor de passo\n\r"); + while (true) { + pc.scanf("%c", &c); + //c = pc.getc(); + pc.printf("%c", c); + + switch(c){ + case 'a': + led = 1; + pc.printf("apertou\n"); + break; + + case 's': + led = 0; + break; } } } \ No newline at end of file