Premiers ajustements

This commit is contained in:
Samuel 2024-01-31 21:55:47 +01:00
parent 6ac3a83c4e
commit 73a667d505

117
main.c
View File

@ -13,10 +13,21 @@
#define PIN_SENS_A_M1 0 #define PIN_SENS_A_M1 0
#define PIN_SENS_B_M1 1 #define PIN_SENS_B_M1 1
int result0, result1; #define PINCE_OUVERTE 0
#define PINCE_PLANTE 1
#define PINCE_POT 1
#define ASCENSEUR_BAS 0
#define ASCENSEUR_HAUT 1
#define ASCENSEUR_LACHE_POT_JARDINIERE 2
#define ASCENSEUR_LACHE_PLANTE 2
unsigned result0, result1;
int joystic_clicker; int joystic_clicker;
int pince; int pince = PINCE_OUVERTE;
int ascenceur; int ascenceur = ASCENSEUR_BAS;
int M1_INITIALISE() int M1_INITIALISE()
@ -82,7 +93,23 @@ int AdcRead1()
void init_bouton(uint8_t bouton){
gpio_init(bouton);
gpio_set_dir(bouton, GPIO_IN);
gpio_pull_up(bouton);
}
int bouton_appui(uint8_t bouton){
static uint8_t etat_bouton[32]={1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1};
if(gpio_get(bouton) == 1 && gpio_get(bouton) != etat_bouton[bouton]){
etat_bouton[bouton] = gpio_get(bouton);
return 1;
}else{
etat_bouton[bouton] = gpio_get(bouton);
}
return 0;
}
void main() void main()
@ -107,18 +134,26 @@ void main()
adc_init(); adc_init();
adc_gpio_init(26); adc_gpio_init(26);
adc_gpio_init(27); adc_gpio_init(27);
// Boutons
init_bouton(2);
init_bouton(6);
init_bouton(10);
init_bouton(14);
ascenceur = ASCENSEUR_BAS;
pince = PINCE_OUVERTE;
while (1) while (1)
{ {
// Voie X // Voie X
result1 = AdcRead1(); result1 = AdcRead1()/16;
message[0] = result1/16;
// Voie Y // Voie Y
result0 = AdcRead0(); result0 = AdcRead0()/16;
message[1] = result0/16; message[0] = 255 - result0;
message[1] = result1;
//clic sur le joystic //clic sur le joystic
gpio_init(1); gpio_init(1);
@ -127,7 +162,13 @@ void main()
joystic_clicker = gpio_get(1); joystic_clicker = gpio_get(1);
if (!joystic_clicker) if (!joystic_clicker)
{ {
message[2] = result1/16; if(result1 > 135){
message[2] = 220;
}else if (result1 < 122){
message[2] = 30;
}else{
message[2] = 128;
}
message[1] = 128; message[1] = 128;
message[0] = 128; message[0] = 128;
} }
@ -136,19 +177,50 @@ void main()
message[2] = 128; message[2] = 128;
} }
// Pince
// Bouton plante
if(bouton_appui(6)){
if(pince == PINCE_OUVERTE){
pince = PINCE_PLANTE;
}else{
pince = PINCE_OUVERTE;
}
}
// Bouton Pot
if(bouton_appui(10)){
if(pince == PINCE_OUVERTE){
pince = PINCE_POT;
}else{
pince = PINCE_OUVERTE;
}
}
// Ascenseur
// Commande simple
if(bouton_appui(2)){
if(ascenceur == ASCENSEUR_BAS){
ascenceur = ASCENSEUR_HAUT;
}else{
ascenceur = ASCENSEUR_BAS;
}
};
// Commande évoluée
if(bouton_appui(14)){
if(ascenceur == ASCENSEUR_HAUT){
if(pince == PINCE_PLANTE){
ascenceur = ASCENSEUR_LACHE_PLANTE;
}
if(pince == PINCE_POT){
ascenceur = ASCENSEUR_LACHE_POT_JARDINIERE;
}
}else{
ascenceur = ASCENSEUR_HAUT;
}
}
//pince
gpio_init(2);
gpio_set_dir(2, GPIO_IN);
gpio_pull_up(2);
pince = gpio_get(2);
message [3] = pince; message [3] = pince;
gpio_init(6);
gpio_set_dir(6, GPIO_IN);
gpio_pull_up(6);
ascenceur = gpio_get(6);
message[4] = ascenceur; message[4] = ascenceur;
@ -157,7 +229,8 @@ void main()
printf(">Rz:%d\n", message[2]); printf(">Rz:%d\n", message[2]);
printf(">pince:%d\n", message[3]); printf(">pince:%d\n", message[3]);
printf(">ascenceur:%d\n", message[4]); printf(">ascenceur:%d\n", message[4]);
sleep_ms(100); printf(">result0:%d\n", result0);
sleep_ms(25);
communication_envoyer_message(message, 254); communication_envoyer_message(message, 254);
} }
M1_INITIALISE(); M1_INITIALISE();