File tree Expand file tree Collapse file tree 3 files changed +24
-5
lines changed
Expand file tree Collapse file tree 3 files changed +24
-5
lines changed Original file line number Diff line number Diff line change 2424#include <bcm2835.h>
2525#include <unistd.h>
2626
27- #define DHTPIN RPI_GPIO_P1_07
2827#define MAXTIMINGS 100
2928
3029#define DHT11 11
@@ -38,20 +37,30 @@ int main(int argc, char **argv)
3837 if (!bcm2835_init ())
3938 return 1 ;
4039
41- if (argc != 2 ) {
42- printf ("usage: %s [11|22|2302]\n" , argv [0 ]);
40+ if (argc != 3 ) {
41+ printf ("usage: %s [11|22|2302] GPIOpin#\n" , argv [0 ]);
42+ printf ("example: %s 2302 4 - Read from an AM2302 connected to GPIO #4\n" , argv [0 ]);
4343 return 2 ;
4444 }
4545 int type = 0 ;
4646 if (strcmp (argv [1 ], "11" ) == 0 ) type = DHT11 ;
4747 if (strcmp (argv [1 ], "22" ) == 0 ) type = DHT22 ;
48- if (strcmp (argv [1 ], "2303 " ) == 0 ) type = AM2302 ;
48+ if (strcmp (argv [1 ], "2302 " ) == 0 ) type = AM2302 ;
4949 if (type == 0 ) {
5050 printf ("Select 11, 22, 2303 as type!\n" );
5151 return 3 ;
5252 }
53+
54+ int dhtpin = atoi (argv [2 ]);
5355
54- readDHT (type , DHTPIN );
56+ if (dhtpin <= 0 ) {
57+ printf ("Please select a valid GPIO pin #\n" );
58+ return 3 ;
59+ }
60+
61+
62+ printf ("Using pin #%d\n" , dhtpin );
63+ readDHT (type , dhtpin );
5564 return 0 ;
5665
5766} // main
Original file line number Diff line number Diff line change 1+ CC = gcc
2+ CFLAGS = -std=c99 -I. -lbcm2835
3+ DEPS =
4+ OBJ = Adafruit_DHT.o
5+
6+ % .o : % .c $(DEPS )
7+ $(CC ) -c -o $@ $< $(CFLAGS )
8+
9+ Adafruit_DHT : $(OBJ )
10+ gcc -o $@ $^ $(CFLAGS )
You can’t perform that action at this time.
0 commit comments