Contrôle par liaison série
This commit is contained in:
parent
88ffe4f03a
commit
609e4659a7
46
main.c
46
main.c
@ -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);
|
|
||||||
gpio_put(9,true);
|
|
||||||
gpio_put(25,true);
|
|
||||||
sleep_ms(5000);
|
|
||||||
printf("kartoffen\n");
|
|
||||||
while(1){
|
|
||||||
bouton_Presser = gpio_get(8);
|
|
||||||
printf(">a:%d\n", bouton_Presser );
|
|
||||||
|
|
||||||
gpio_put(25,bouton_Presser);
|
sleep_ms(3000);
|
||||||
if(bouton_Presser){
|
printf("kartoffen\n");
|
||||||
printf("bouton a ete presse\n");
|
const uint32_t my_delay=1;
|
||||||
|
while(1){
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user