diff --git a/CMakeLists.txt b/CMakeLists.txt index 63a3def..d8f703d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,7 @@ target_link_libraries(Mon_Projet hardware_i2c hardware_uart hardware_pwm + hardware_adc pico_stdlib pico_multicore ) diff --git a/main.c b/main.c index a337170..d2c98b3 100644 --- a/main.c +++ b/main.c @@ -6,11 +6,14 @@ #include "pico/stdlib.h" #include "hardware/pwm.h" #include - +#include "hardware/adc.h" #define LED_VERTE 25 #define PIN_VITESSE_M1 2 -#define PIN_SENS_A_M1 0 +#define PIN_SENS_A_M1 0 #define PIN_SENS_B_M1 1 + +uint16_t result1 = 0; +uint16_t result0 = 0; int M1_INITIALISE() { gpio_init(PIN_VITESSE_M1); @@ -20,6 +23,10 @@ int M1_INITIALISE() gpio_set_dir(PIN_VITESSE_M1, GPIO_OUT); gpio_set_dir(PIN_SENS_A_M1, GPIO_OUT); gpio_set_dir(PIN_SENS_B_M1, GPIO_OUT); + + gpio_set_function(PIN_VITESSE_M1, GPIO_FUNC_PWM); + pwm_set_wrap(PIN_VITESSE_M1, 100); + pwm_set_chan_level(PIN_VITESSE_M1, PWM_CHAN_B, 50); } @@ -44,11 +51,33 @@ int M1_RECULE() } +int Adc_Init() +{ + adc_init(); + adc_gpio_init(26); + adc_gpio_init(27); +} +int AdcRead0() +{ + adc_select_input(0); + uint16_t resultadc = adc_read(); + return resultadc; +} +int AdcRead1() +{ + adc_select_input(1); + uint16_t resultadc= adc_read(); + return resultadc; +} + + + + void main() @@ -61,16 +90,33 @@ void main() pwm_set_chan_level(4, PWM_CHAN_B, 25); pwm_set_enabled(4, true); - //Moteur 1 + // ADC + adc_init(); + adc_gpio_init(26); + adc_gpio_init(27); + + while (1) + { + // Voie Y + result0 = AdcRead0(); + printf(">result:%d\n",result0-2048); + // Voie X + result1 = AdcRead1(); + printf(">result1:%d\n",result1-2048); + printf("test\n",result0); + + sleep_ms(100); + + } M1_INITIALISE(); + while(1) { - M1_AVANCE(); - sleep_ms(3000); + sleep_ms(1000); M1_RECULE(); - sleep_ms(3000); + sleep_ms(1000); }