Contrôle par liaison série

This commit is contained in:
Samuel 2026-02-03 21:15:35 +01:00
parent 88ffe4f03a
commit 609e4659a7

44
main.c
View File

@ -5,27 +5,41 @@
*/ */
#include "pico/stdlib.h" #include "pico/stdlib.h"
#include <stdio.h> #include <stdio.h>
#define PIN_STEP 19
#define PIN_DIR 18
bool bouton_Presser = false; bool bouton_Presser = false;
void main(void) void main(void)
{ {
stdio_init_all(); stdio_init_all();
gpio_init(8); gpio_init(PIN_STEP);
gpio_init(9); gpio_init(PIN_DIR);
gpio_set_function(8,GPIO_IN); gpio_set_dir(PIN_STEP, GPIO_OUT);
gpio_set_function(9,GPIO_OUT); gpio_set_dir(PIN_DIR, GPIO_OUT);
gpio_set_function(25,GPIO_OUT);
gpio_pull_down(8); sleep_ms(3000);
gpio_put(9,true);
gpio_put(25,true);
sleep_ms(5000);
printf("kartoffen\n"); printf("kartoffen\n");
const uint32_t my_delay=1;
while(1){ while(1){
bouton_Presser = gpio_get(8); sleep_ms(my_delay);
printf(">a:%d\n", bouton_Presser ); gpio_put(PIN_STEP, 1);
sleep_ms(my_delay);
gpio_put(25,bouton_Presser); gpio_put(PIN_STEP, 0);
if(bouton_Presser){ int key = getchar_timeout_us(0); // get any pending key press but don't wait
printf("bouton a ete presse\n"); 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);
} }