174 lines
2.6 KiB
C
174 lines
2.6 KiB
C
/*****
|
|
* Copyright (c) 2023 - Poivron Robotique
|
|
*
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
*/
|
|
#include "communication.h"
|
|
#include "pico/stdlib.h"
|
|
#include "hardware/pwm.h"
|
|
#include <stdio.h>
|
|
#include "hardware/adc.h"
|
|
#define LED_VERTE 25
|
|
#define PIN_VITESSE_M1 2
|
|
#define PIN_SENS_A_M1 0
|
|
#define PIN_SENS_B_M1 1
|
|
|
|
int result0, result1;
|
|
int joystic_clicker;
|
|
int pince;
|
|
int ascenceur;
|
|
|
|
|
|
int M1_INITIALISE()
|
|
{
|
|
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);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
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()
|
|
{
|
|
char message [256];
|
|
stdio_init_all();
|
|
|
|
// Communication
|
|
communication_init();
|
|
|
|
// Pour envoyer un message
|
|
// communication_envoyer_message(message, 254);
|
|
|
|
|
|
// 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);
|
|
|
|
// ADC
|
|
adc_init();
|
|
adc_gpio_init(26);
|
|
adc_gpio_init(27);
|
|
|
|
while (1)
|
|
{
|
|
// Voie X
|
|
result1 = AdcRead1();
|
|
|
|
message[0] = result1/16;
|
|
|
|
// Voie Y
|
|
result0 = AdcRead0();
|
|
|
|
message[1] = result0/16;
|
|
|
|
//clic sur le joystic
|
|
gpio_init(1);
|
|
gpio_pull_up(1);
|
|
gpio_set_dir(1, GPIO_IN);
|
|
joystic_clicker = gpio_get(1);
|
|
if (!joystic_clicker)
|
|
{
|
|
message[2] = result1/16;
|
|
message[1] = 128;
|
|
message[0] = 128;
|
|
}
|
|
else
|
|
{
|
|
message[2] = 128;
|
|
}
|
|
|
|
|
|
|
|
//pince
|
|
gpio_init(2);
|
|
gpio_set_dir(2, GPIO_IN);
|
|
gpio_pull_up(2);
|
|
pince = gpio_get(2);
|
|
message [3] = pince;
|
|
|
|
gpio_init(6);
|
|
gpio_set_dir(6, GPIO_IN);
|
|
gpio_pull_up(6);
|
|
ascenceur = gpio_get(6);
|
|
message[4] = ascenceur;
|
|
|
|
|
|
printf(">x:%d\n", message[0]);
|
|
printf(">Y:%d\n", message[1]);
|
|
printf(">Rz:%d\n", message[2]);
|
|
printf(">pince:%d\n", message[3]);
|
|
printf(">ascenceur:%d\n", message[4]);
|
|
sleep_ms(100);
|
|
communication_envoyer_message(message, 254);
|
|
}
|
|
M1_INITIALISE();
|
|
while(1)
|
|
{
|
|
M1_AVANCE();
|
|
sleep_ms(1000);
|
|
M1_RECULE();
|
|
sleep_ms(1000);
|
|
|
|
}
|
|
|
|
}
|