From 7163302347c89abfcdd5427006ae134240faf46c Mon Sep 17 00:00:00 2001 From: Samuel Date: Sat, 16 Dec 2023 12:12:55 +0100 Subject: [PATCH] Pilotage moteurs --- .vscode/settings.json | 3 +- CMakeLists.txt | 2 ++ main.c | 84 +++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 86 insertions(+), 3 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index c988ddf..bb4c38d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,6 @@ { "files.associations": { - + "stdlib.h": "c", + "stdio.h": "c" } } \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 7171dd2..fe8743c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,8 @@ target_include_directories(Mon_Projet PRIVATE Mon_Projet_ULD_API/inc/) target_link_libraries(Mon_Projet hardware_i2c + hardware_adc + hardware_pwm hardware_uart pico_stdlib pico_multicore diff --git a/main.c b/main.c index f79df64..396efd3 100644 --- a/main.c +++ b/main.c @@ -4,13 +4,93 @@ * SPDX-License-Identifier: BSD-3-Clause */ #include "pico/stdlib.h" +#include "hardware/pwm.h" +#include "hardware/adc.h" #include +#define MOTEUR1_PIN_SENS1 2 +#define MOTEUR1_PIN_SENS2 3 +#define MOTEUR1_PIN_ACTIVATION 0 + +#define MOTEUR2_PIN_SENS1 4 +#define MOTEUR2_PIN_SENS2 5 +#define MOTEUR2_PIN_ACTIVATION 1 + +int sens_moteur1 = 0; +int sens_moteur2 = 0; + +void upload_motor(void); + void main(void) { stdio_init_all(); + + gpio_init(MOTEUR1_PIN_SENS1); + gpio_set_dir(MOTEUR1_PIN_SENS1, GPIO_OUT); + gpio_init(MOTEUR1_PIN_SENS2); + gpio_set_dir(MOTEUR1_PIN_SENS2, GPIO_OUT); + gpio_init(MOTEUR2_PIN_SENS1); + gpio_set_dir(MOTEUR2_PIN_SENS1, GPIO_OUT); + gpio_init(MOTEUR2_PIN_SENS2); + gpio_set_dir(MOTEUR2_PIN_SENS2, GPIO_OUT); + + gpio_init(MOTEUR1_PIN_ACTIVATION); + gpio_init(MOTEUR2_PIN_ACTIVATION); + + gpio_set_function(MOTEUR1_PIN_ACTIVATION, GPIO_FUNC_PWM); + gpio_set_function(MOTEUR2_PIN_ACTIVATION, GPIO_FUNC_PWM); + + pwm_set_wrap(0, 1000); + pwm_set_chan_level(0, PWM_CHAN_A, 800); + + pwm_set_enabled(0, true); + + sens_moteur1 = 1; + sens_moteur2 = 1; + + upload_motor(); + while(1){ - printf("Exemple\n"); - sleep_ms(1000); + tight_loop_contents(); } } + +void upload_motor(void) +{ + switch(sens_moteur1) + { + case 0: + gpio_put(MOTEUR1_PIN_SENS1, 0); + gpio_put(MOTEUR1_PIN_SENS2, 0); + break; + + case 1: + gpio_put(MOTEUR1_PIN_SENS1, 1); + gpio_put(MOTEUR1_PIN_SENS2, 0); + break; + + case 2: + gpio_put(MOTEUR1_PIN_SENS1, 0); + gpio_put(MOTEUR1_PIN_SENS2, 1); + break; + } + + switch(sens_moteur2) + { + case 0: + gpio_put(MOTEUR2_PIN_SENS1, 0); + gpio_put(MOTEUR2_PIN_SENS2, 0); + break; + + case 1: + gpio_put(MOTEUR2_PIN_SENS1, 1); + gpio_put(MOTEUR2_PIN_SENS2, 0); + break; + + case 2: + gpio_put(MOTEUR2_PIN_SENS1, 0); + gpio_put(MOTEUR2_PIN_SENS2, 1); + break; + } + +} \ No newline at end of file