From 609e4659a7c18145dc8955b10d0aa269418687f3 Mon Sep 17 00:00:00 2001 From: Samuel Date: Tue, 3 Feb 2026 21:15:35 +0100 Subject: [PATCH] =?UTF-8?q?Contr=C3=B4le=20par=20liaison=20s=C3=A9rie?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.c | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/main.c b/main.c index cc2822d..146536a 100644 --- a/main.c +++ b/main.c @@ -5,27 +5,41 @@ */ #include "pico/stdlib.h" #include +#define PIN_STEP 19 +#define PIN_DIR 18 + bool bouton_Presser = false; void main(void) { stdio_init_all(); - gpio_init(8); - gpio_init(9); - gpio_set_function(8,GPIO_IN); - gpio_set_function(9,GPIO_OUT); - gpio_set_function(25,GPIO_OUT); - gpio_pull_down(8); - gpio_put(9,true); - gpio_put(25,true); - sleep_ms(5000); + gpio_init(PIN_STEP); + gpio_init(PIN_DIR); + gpio_set_dir(PIN_STEP, GPIO_OUT); + gpio_set_dir(PIN_DIR, GPIO_OUT); + + sleep_ms(3000); printf("kartoffen\n"); + const uint32_t my_delay=1; while(1){ - bouton_Presser = gpio_get(8); - printf(">a:%d\n", bouton_Presser ); - - gpio_put(25,bouton_Presser); - if(bouton_Presser){ - printf("bouton a ete presse\n"); + sleep_ms(my_delay); + gpio_put(PIN_STEP, 1); + sleep_ms(my_delay); + gpio_put(PIN_STEP, 0); + int key = getchar_timeout_us(0); // get any pending key press but don't wait + if (key != PICO_ERROR_TIMEOUT) { + if(key == 'u' || key == 'U'){ + gpio_put(PIN_DIR, 1); + gpio_set_dir(PIN_STEP, GPIO_OUT); + } + if(key == 'd' || key == 'D'){ + gpio_put(PIN_DIR, 0); + gpio_set_dir(PIN_STEP, GPIO_OUT); + } + if(key == 's' || key == 'D'){ + gpio_put(PIN_DIR, 0); + gpio_set_dir(PIN_STEP, GPIO_IN); + } + printf("%c %d\n", key,key); }