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@4:97d107efa17e, 2020-10-28 (annotated)
- Committer:
- Marcelocostanzo
- Date:
- Wed Oct 28 13:02:18 2020 +0000
- Revision:
- 4:97d107efa17e
- Parent:
- 3:95a3a1fbc807
- Child:
- 6:d6e4872d38fe
Funcionando todos bracos independentes
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Marcelocostanzo | 0:24b2f1c78160 | 1 | #include "mbed.h" |
Marcelocostanzo | 4:97d107efa17e | 2 | |
Marcelocostanzo | 4:97d107efa17e | 3 | //---Pinos de enable dos braços---- |
Marcelocostanzo | 4:97d107efa17e | 4 | DigitalOut enable_ch1(PC_10); |
Marcelocostanzo | 4:97d107efa17e | 5 | DigitalOut enable_ch2(PC_11); |
Marcelocostanzo | 4:97d107efa17e | 6 | DigitalOut enable_ch3(PC_12); |
Marcelocostanzo | 0:24b2f1c78160 | 7 | |
Marcelocostanzo | 4:97d107efa17e | 8 | //---Pinos de canais dos braços---- |
Marcelocostanzo | 4:97d107efa17e | 9 | PwmOut in_ch1(PA_8); |
Marcelocostanzo | 4:97d107efa17e | 10 | PwmOut in_ch2(PA_9); |
Marcelocostanzo | 4:97d107efa17e | 11 | PwmOut in_ch3(PA_10); |
Marcelocostanzo | 0:24b2f1c78160 | 12 | |
Marcelocostanzo | 4:97d107efa17e | 13 | //---Pino de ADC da X-NUCLEO ---- |
Marcelocostanzo | 1:08226e87671c | 14 | AnalogIn pot(PB_1); |
Marcelocostanzo | 1:08226e87671c | 15 | |
Marcelocostanzo | 4:97d107efa17e | 16 | //---Pino do led da NUCLEO---- |
Marcelocostanzo | 0:24b2f1c78160 | 17 | DigitalOut myled(LED1); |
Marcelocostanzo | 0:24b2f1c78160 | 18 | |
Marcelocostanzo | 4:97d107efa17e | 19 | //---Pino do butao da NUCLEO---- |
Marcelocostanzo | 0:24b2f1c78160 | 20 | DigitalIn sw(PC_13); |
Marcelocostanzo | 0:24b2f1c78160 | 21 | |
Marcelocostanzo | 4:97d107efa17e | 22 | //---Pinos do serial-USB da NUCLEO---- |
Marcelocostanzo | 0:24b2f1c78160 | 23 | Serial pc(USBTX, USBRX); |
Marcelocostanzo | 0:24b2f1c78160 | 24 | |
Marcelocostanzo | 4:97d107efa17e | 25 | //---Prototipo das Funções---- |
Marcelocostanzo | 4:97d107efa17e | 26 | void motor_start(float SPEED, unsigned int MOTOR); |
Marcelocostanzo | 4:97d107efa17e | 27 | void motor_stop(unsigned int MOTOR); |
Marcelocostanzo | 0:24b2f1c78160 | 28 | |
Marcelocostanzo | 4:97d107efa17e | 29 | //---Programa principal------- |
Marcelocostanzo | 0:24b2f1c78160 | 30 | int main() |
Marcelocostanzo | 0:24b2f1c78160 | 31 | { |
Marcelocostanzo | 4:97d107efa17e | 32 | //---Configura o periodo do PWM---- |
Marcelocostanzo | 4:97d107efa17e | 33 | in_ch1.period_ms(1); |
Marcelocostanzo | 4:97d107efa17e | 34 | in_ch2.period_ms(1); |
Marcelocostanzo | 4:97d107efa17e | 35 | in_ch3.period_ms(1); |
Marcelocostanzo | 4:97d107efa17e | 36 | |
Marcelocostanzo | 4:97d107efa17e | 37 | //---Inicia o PWM com 0% de duty-cicle---- |
Marcelocostanzo | 4:97d107efa17e | 38 | in_ch1.write(0); |
Marcelocostanzo | 4:97d107efa17e | 39 | in_ch2.write(0); |
Marcelocostanzo | 4:97d107efa17e | 40 | in_ch3.write(0); |
Marcelocostanzo | 4:97d107efa17e | 41 | |
Marcelocostanzo | 4:97d107efa17e | 42 | //---Inicia os braços em Z (alta impedancia)---- |
Marcelocostanzo | 4:97d107efa17e | 43 | enable_ch1 = 2; |
Marcelocostanzo | 4:97d107efa17e | 44 | enable_ch2 = 2; |
Marcelocostanzo | 4:97d107efa17e | 45 | enable_ch3 = 2; |
Marcelocostanzo | 4:97d107efa17e | 46 | |
Marcelocostanzo | 4:97d107efa17e | 47 | //---Configura o baudrate da serial para 115200--- |
Marcelocostanzo | 0:24b2f1c78160 | 48 | pc.baud(115200); |
Marcelocostanzo | 0:24b2f1c78160 | 49 | |
Marcelocostanzo | 4:97d107efa17e | 50 | pc.printf("Started\r"); //Iniciando |
Marcelocostanzo | 0:24b2f1c78160 | 51 | |
Marcelocostanzo | 0:24b2f1c78160 | 52 | while(1) |
Marcelocostanzo | 0:24b2f1c78160 | 53 | { |
Marcelocostanzo | 4:97d107efa17e | 54 | motor_start(0.5, 1); //Liga o motor 1 com 50% de duty-cicle |
Marcelocostanzo | 4:97d107efa17e | 55 | wait_ms(500); |
Marcelocostanzo | 4:97d107efa17e | 56 | motor_start(0.5, 2); //Liga o motor 2 com 50% de duty-cicle |
Marcelocostanzo | 4:97d107efa17e | 57 | wait_ms(500); |
Marcelocostanzo | 4:97d107efa17e | 58 | motor_start(0.5, 3); //Liga o motor 3 com 50% de duty-cicle |
Marcelocostanzo | 4:97d107efa17e | 59 | wait_ms(500); |
Marcelocostanzo | 4:97d107efa17e | 60 | |
Marcelocostanzo | 4:97d107efa17e | 61 | motor_stop(1); //Desliga o motor 1 |
Marcelocostanzo | 4:97d107efa17e | 62 | wait_ms(500); |
Marcelocostanzo | 4:97d107efa17e | 63 | motor_stop(2); //Desliga o motor 2 |
Marcelocostanzo | 4:97d107efa17e | 64 | wait_ms(500); |
Marcelocostanzo | 4:97d107efa17e | 65 | motor_stop(3); //Desliga o motor 3 |
Marcelocostanzo | 4:97d107efa17e | 66 | wait_ms(500); |
Marcelocostanzo | 0:24b2f1c78160 | 67 | } |
Marcelocostanzo | 0:24b2f1c78160 | 68 | } |
Marcelocostanzo | 0:24b2f1c78160 | 69 | |
Marcelocostanzo | 4:97d107efa17e | 70 | //---Função de controle dos braços---------- |
Marcelocostanzo | 4:97d107efa17e | 71 | void motor_start(float SPEED, unsigned int MOTOR) |
Marcelocostanzo | 0:24b2f1c78160 | 72 | { |
Marcelocostanzo | 4:97d107efa17e | 73 | if(MOTOR == 1) |
Marcelocostanzo | 4:97d107efa17e | 74 | { |
Marcelocostanzo | 4:97d107efa17e | 75 | enable_ch1 = 1; |
Marcelocostanzo | 4:97d107efa17e | 76 | in_ch1.write(SPEED); |
Marcelocostanzo | 4:97d107efa17e | 77 | } |
Marcelocostanzo | 0:24b2f1c78160 | 78 | |
Marcelocostanzo | 4:97d107efa17e | 79 | if(MOTOR == 2) |
Marcelocostanzo | 0:24b2f1c78160 | 80 | { |
Marcelocostanzo | 4:97d107efa17e | 81 | enable_ch2 = 1; |
Marcelocostanzo | 4:97d107efa17e | 82 | in_ch2.write(SPEED); |
Marcelocostanzo | 0:24b2f1c78160 | 83 | } |
Marcelocostanzo | 0:24b2f1c78160 | 84 | |
Marcelocostanzo | 4:97d107efa17e | 85 | if(MOTOR == 3) |
Marcelocostanzo | 4:97d107efa17e | 86 | { |
Marcelocostanzo | 4:97d107efa17e | 87 | enable_ch3 = 1; |
Marcelocostanzo | 4:97d107efa17e | 88 | in_ch3.write(SPEED); |
Marcelocostanzo | 4:97d107efa17e | 89 | } |
Marcelocostanzo | 4:97d107efa17e | 90 | } |
Marcelocostanzo | 4:97d107efa17e | 91 | |
Marcelocostanzo | 4:97d107efa17e | 92 | //---Função de desligamento dos braços---------- |
Marcelocostanzo | 4:97d107efa17e | 93 | void motor_stop(unsigned int MOTOR) |
Marcelocostanzo | 4:97d107efa17e | 94 | { |
Marcelocostanzo | 4:97d107efa17e | 95 | if(MOTOR == 1) |
Marcelocostanzo | 4:97d107efa17e | 96 | { |
Marcelocostanzo | 4:97d107efa17e | 97 | enable_ch1 = 2; //alta impedancia - Z |
Marcelocostanzo | 4:97d107efa17e | 98 | in_ch1.write(0); |
Marcelocostanzo | 4:97d107efa17e | 99 | } |
Marcelocostanzo | 0:24b2f1c78160 | 100 | |
Marcelocostanzo | 4:97d107efa17e | 101 | if(MOTOR == 2) |
Marcelocostanzo | 4:97d107efa17e | 102 | { |
Marcelocostanzo | 4:97d107efa17e | 103 | enable_ch2 = 2; //alta impedancia - Z |
Marcelocostanzo | 4:97d107efa17e | 104 | in_ch2.write(0); |
Marcelocostanzo | 4:97d107efa17e | 105 | } |
Marcelocostanzo | 4:97d107efa17e | 106 | |
Marcelocostanzo | 4:97d107efa17e | 107 | if(MOTOR == 3) |
Marcelocostanzo | 4:97d107efa17e | 108 | { |
Marcelocostanzo | 4:97d107efa17e | 109 | enable_ch3 = 2; //alta impedancia - Z |
Marcelocostanzo | 4:97d107efa17e | 110 | in_ch3.write(0); |
Marcelocostanzo | 4:97d107efa17e | 111 | } |
Marcelocostanzo | 4:97d107efa17e | 112 | } |
Marcelocostanzo | 4:97d107efa17e | 113 |