Pico2ButtonTest1V01.c


1
#include <stdio.h>
2
#include "pico/stdlib.h"
3
4
#define LEDpin 25
5
6
#define Button3 3
7
8
void showPulls(){
9
  int v=0 ;
10
  v=gpio_is_pulled_up (Button3) ;
11
  printf("gpio_is_pulled_up (Button3)=%d\n",v) ;
12
  v=gpio_is_pulled_down (Button3) ;
13
  printf("gpio_is_pulled_down (Button3)=%d\n",v) ;
14
  }
15
16
void showButton(){
17
  int kk=0 ;  
18
  printf("showButton\n") ;
19
  while(1){
20
    int v=gpio_get(Button3) ;
21
    gpio_put(LEDpin,v) ;
22
    printf("k=%4d pinX=%d\n",kk++,v) ;
23
    sleep_ms(100) ;
24
    }
25
  }
26
27
#define up 1
28
#define down 0
29
30
void setup1(){
31
  printf("setup1\n") ;
32
33
  gpio_init(LEDpin);
34
  gpio_set_dir(LEDpin, GPIO_OUT);
35
36
  gpio_init(Button3);
37
  gpio_set_pulls (Button3, up , down ) ;
38
  gpio_set_dir(Button3, GPIO_IN);
39
  showPulls() ;
40
  showButton() ;
41
  }    
42
43
void wait(int nn){
44
  for(int kk=0 ; kk<nn ; kk++){
45
    printf("wait k=%d\n",kk) ;
46
    sleep_ms(1000) ;
47
    }
48
  }
49
50
int main(){
51
  stdio_init_all();
52
  wait(8) ;
53
  printf("Pico2ButtonTest1V01\n") ;
54
  setup1() ;
55
  }