2023-12-15 17:33:44 +00:00
|
|
|
/*****
|
2023-10-22 16:48:14 +00:00
|
|
|
* Copyright (c) 2023 - Poivron Robotique
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*/
|
|
|
|
#include "pico/stdlib.h"
|
2023-12-15 17:33:44 +00:00
|
|
|
#include "hardware/pwm.h"
|
2023-10-22 16:48:14 +00:00
|
|
|
#include <stdio.h>
|
2024-01-12 17:53:51 +00:00
|
|
|
#include "hardware/adc.h"
|
2023-12-15 17:33:44 +00:00
|
|
|
#define LED_VERTE 25
|
|
|
|
#define PIN_VITESSE_M1 2
|
2024-01-12 17:53:51 +00:00
|
|
|
#define PIN_SENS_A_M1 0
|
2023-12-15 17:33:44 +00:00
|
|
|
#define PIN_SENS_B_M1 1
|
2024-01-12 17:53:51 +00:00
|
|
|
|
|
|
|
uint16_t result1 = 0;
|
|
|
|
uint16_t result0 = 0;
|
2023-12-15 17:33:44 +00:00
|
|
|
int M1_INITIALISE()
|
2023-10-22 16:48:14 +00:00
|
|
|
{
|
2023-12-15 17:33:44 +00:00
|
|
|
gpio_init(PIN_VITESSE_M1);
|
|
|
|
gpio_init(PIN_SENS_A_M1);
|
|
|
|
gpio_init(PIN_SENS_B_M1);
|
|
|
|
|
|
|
|
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);
|
2024-01-12 17:53:51 +00:00
|
|
|
|
|
|
|
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);
|
2023-12-15 17:33:44 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int M1_AVANCE()
|
|
|
|
{
|
|
|
|
|
|
|
|
gpio_put(PIN_VITESSE_M1, 1);
|
|
|
|
gpio_put(PIN_SENS_A_M1, 1);
|
|
|
|
gpio_put(PIN_SENS_B_M1, 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int M1_RECULE()
|
|
|
|
{
|
|
|
|
|
|
|
|
gpio_put(PIN_VITESSE_M1, 1);
|
|
|
|
gpio_put(PIN_SENS_A_M1, 0);
|
|
|
|
gpio_put(PIN_SENS_B_M1, 1);
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-10-22 16:48:14 +00:00
|
|
|
}
|
2024-01-12 17:53:51 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-12-15 17:33:44 +00:00
|
|
|
|
|
|
|
|
2024-01-12 17:53:51 +00:00
|
|
|
int AdcRead1()
|
|
|
|
{
|
|
|
|
adc_select_input(1);
|
|
|
|
uint16_t resultadc= adc_read();
|
|
|
|
return resultadc;
|
|
|
|
}
|
|
|
|
|
2023-12-15 17:33:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
stdio_init_all();
|
|
|
|
|
|
|
|
// CLignottement LED
|
|
|
|
gpio_set_function(LED_VERTE, GPIO_FUNC_PWM);
|
|
|
|
pwm_set_wrap(4, 100);
|
|
|
|
pwm_set_chan_level(4, PWM_CHAN_B, 25);
|
|
|
|
pwm_set_enabled(4, true);
|
|
|
|
|
2024-01-12 17:53:51 +00:00
|
|
|
// 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);
|
2023-12-15 17:33:44 +00:00
|
|
|
|
2024-01-12 17:53:51 +00:00
|
|
|
}
|
2023-12-15 17:33:44 +00:00
|
|
|
M1_INITIALISE();
|
2024-01-12 17:53:51 +00:00
|
|
|
|
2023-12-15 17:33:44 +00:00
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
M1_AVANCE();
|
2024-01-12 17:53:51 +00:00
|
|
|
sleep_ms(1000);
|
2023-12-15 17:33:44 +00:00
|
|
|
M1_RECULE();
|
2024-01-12 17:53:51 +00:00
|
|
|
sleep_ms(1000);
|
2023-12-15 17:33:44 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|