2023-10-22 16:48:14 +00:00
|
|
|
#include "pico/stdlib.h"
|
2023-12-16 11:12:55 +00:00
|
|
|
#include "hardware/adc.h"
|
2024-01-09 20:03:50 +00:00
|
|
|
#include "communication.h"
|
2023-10-22 16:48:14 +00:00
|
|
|
#include <stdio.h>
|
2024-01-12 18:05:56 +00:00
|
|
|
#include "moteur.h"
|
2023-12-22 17:21:19 +00:00
|
|
|
|
2024-01-09 20:03:50 +00:00
|
|
|
// Juste pour information - les broches sont re-définies dans i2c_slave
|
|
|
|
#define I2C0_SDA_PIN 16
|
|
|
|
#define I2C0_SCL_PIN 17
|
|
|
|
|
|
|
|
// Juste pour information - les broches sont re-définies dans i2c_master
|
|
|
|
#define I2C1_SDA_PIN 18
|
|
|
|
#define I2C1_SCL_PIN 19
|
|
|
|
|
2024-01-12 17:30:24 +00:00
|
|
|
// Convert te joystick value to an char value
|
|
|
|
uint8_t Conversions_joystick2uint8(uint16_t joystick_value);
|
2023-12-16 11:12:55 +00:00
|
|
|
|
2023-10-22 16:48:14 +00:00
|
|
|
void main(void)
|
|
|
|
{
|
2024-01-12 17:30:24 +00:00
|
|
|
char message[256], reception[256];
|
2024-01-12 18:05:56 +00:00
|
|
|
|
|
|
|
// Init "all"
|
2023-10-22 16:48:14 +00:00
|
|
|
stdio_init_all();
|
2023-12-22 17:21:19 +00:00
|
|
|
Init_motion_motor();
|
2024-01-09 20:03:50 +00:00
|
|
|
communication_init();
|
|
|
|
|
2024-01-12 18:05:56 +00:00
|
|
|
uint vitesse_x = 0;
|
|
|
|
uint vitesse_y = 0;
|
2024-01-09 20:03:50 +00:00
|
|
|
|
2024-01-12 18:05:56 +00:00
|
|
|
while(1){
|
2024-01-09 20:03:50 +00:00
|
|
|
|
2024-01-12 18:05:56 +00:00
|
|
|
if (!(communication_read_message(reception) == I2C_ECHEC))
|
|
|
|
{
|
|
|
|
vitesse_x = reception[0]-128;
|
|
|
|
vitesse_y = reception[1]-128;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
vitesse_x = 0;
|
|
|
|
vitesse_y = 0;
|
2024-01-09 20:03:50 +00:00
|
|
|
}
|
2023-12-22 18:54:12 +00:00
|
|
|
|
2024-01-12 18:05:56 +00:00
|
|
|
Motor1_speed(vitesse_x);
|
|
|
|
Motor2_speed(vitesse_x);
|
|
|
|
Motor3_speed(vitesse_y);
|
|
|
|
Motor4_speed(vitesse_y);
|
2023-12-22 18:54:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-12 17:30:24 +00:00
|
|
|
|
|
|
|
/// @brief Prend un nombre entre 0 et 4096, et sort un nombre entre 0 et 255
|
|
|
|
/// @return un nombre entre 0 et 255
|
|
|
|
uint8_t Conversions_joystick2uint8(uint16_t joystick_value)
|
|
|
|
{
|
|
|
|
uint8_t valeur = joystick_value / 4;
|
|
|
|
return valeur;
|
2023-12-16 11:12:55 +00:00
|
|
|
}
|