2020-09-10 13:23:23 +08:00
|
|
|
/*
|
|
|
|
* 声音传感器
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <wiringPi.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <string.h>
|
2023-12-31 10:47:49 +08:00
|
|
|
#include <ctype.h>
|
2020-09-10 13:23:23 +08:00
|
|
|
|
2023-03-25 09:01:17 +08:00
|
|
|
static int is_num(char *str)
|
2020-09-10 13:23:23 +08:00
|
|
|
{
|
2023-03-25 09:01:17 +08:00
|
|
|
int i, len;
|
|
|
|
for (i = 0, len = strlen(str); i < len; i++) {
|
|
|
|
if (isdigit(str[i]) == 0) {
|
|
|
|
printf("不是数字\n");
|
|
|
|
return 1;
|
2020-09-10 13:23:23 +08:00
|
|
|
}
|
|
|
|
}
|
2023-03-25 09:01:17 +08:00
|
|
|
|
|
|
|
return 0;
|
2020-09-10 13:23:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
if (argc != 2) {
|
|
|
|
printf("Parameter error.\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2023-03-25 09:01:17 +08:00
|
|
|
if (is_num(argv[1]) == 1) {
|
2020-09-10 13:23:23 +08:00
|
|
|
printf("Parameter error, parameter 1 is PIN pin value\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int pin = atol(argv[1]);
|
|
|
|
int status = 0;
|
|
|
|
|
|
|
|
wiringPiSetup();
|
|
|
|
|
|
|
|
pinMode(pin, INPUT);
|
|
|
|
|
|
|
|
//pullUpDnControl(pin, PUD_DOWN);
|
|
|
|
|
|
|
|
status = digitalRead(pin);
|
|
|
|
printf("%d\n", status);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|