Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
main.cpp
- Committer:
- Marcelocostanzo
- Date:
- 2020-10-28
- Revision:
- 4:97d107efa17e
- Parent:
- 3:95a3a1fbc807
File content as of revision 4:97d107efa17e:
#include "mbed.h"
//---Pinos de enable dos braços----
DigitalOut enable_ch1(PC_10);
DigitalOut enable_ch2(PC_11);
DigitalOut enable_ch3(PC_12);
//---Pinos de canais dos braços----
PwmOut in_ch1(PA_8);
PwmOut in_ch2(PA_9);
PwmOut in_ch3(PA_10);
//---Pino de ADC da X-NUCLEO ----
AnalogIn pot(PB_1);
//---Pino do led da NUCLEO----
DigitalOut myled(LED1);
//---Pino do butao da NUCLEO----
DigitalIn sw(PC_13);
//---Pinos do serial-USB da NUCLEO----
Serial pc(USBTX, USBRX);
//---Prototipo das Funções----
void motor_start(float SPEED, unsigned int MOTOR);
void motor_stop(unsigned int MOTOR);
//---Programa principal-------
int main()
{
//---Configura o periodo do PWM----
in_ch1.period_ms(1);
in_ch2.period_ms(1);
in_ch3.period_ms(1);
//---Inicia o PWM com 0% de duty-cicle----
in_ch1.write(0);
in_ch2.write(0);
in_ch3.write(0);
//---Inicia os braços em Z (alta impedancia)----
enable_ch1 = 2;
enable_ch2 = 2;
enable_ch3 = 2;
//---Configura o baudrate da serial para 115200---
pc.baud(115200);
pc.printf("Started\r"); //Iniciando
while(1)
{
motor_start(0.5, 1); //Liga o motor 1 com 50% de duty-cicle
wait_ms(500);
motor_start(0.5, 2); //Liga o motor 2 com 50% de duty-cicle
wait_ms(500);
motor_start(0.5, 3); //Liga o motor 3 com 50% de duty-cicle
wait_ms(500);
motor_stop(1); //Desliga o motor 1
wait_ms(500);
motor_stop(2); //Desliga o motor 2
wait_ms(500);
motor_stop(3); //Desliga o motor 3
wait_ms(500);
}
}
//---Função de controle dos braços----------
void motor_start(float SPEED, unsigned int MOTOR)
{
if(MOTOR == 1)
{
enable_ch1 = 1;
in_ch1.write(SPEED);
}
if(MOTOR == 2)
{
enable_ch2 = 1;
in_ch2.write(SPEED);
}
if(MOTOR == 3)
{
enable_ch3 = 1;
in_ch3.write(SPEED);
}
}
//---Função de desligamento dos braços----------
void motor_stop(unsigned int MOTOR)
{
if(MOTOR == 1)
{
enable_ch1 = 2; //alta impedancia - Z
in_ch1.write(0);
}
if(MOTOR == 2)
{
enable_ch2 = 2; //alta impedancia - Z
in_ch2.write(0);
}
if(MOTOR == 3)
{
enable_ch3 = 2; //alta impedancia - Z
in_ch3.write(0);
}
}