您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 

81 行
1.9 KiB

  1. // WiringPi test program: Kernel char device interface / sysfs successor
  2. // Compile: gcc -Wall wiringpi_test2_device.c -o wiringpi_test2_device -lwiringPi
  3. #include <wiringPi.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <signal.h>
  7. #include <string.h>
  8. #include <time.h>
  9. #include <sys/time.h>
  10. const int GPIO = 19;
  11. const int GPIOIN = 26;
  12. const int ToggleValue = 4;
  13. void CheckGPIO(int out) {
  14. int in = digitalRead(GPIOIN);
  15. int read = digitalRead(GPIO);
  16. int pass = 0;
  17. if (out==in && in==read) {
  18. pass = 1;
  19. }
  20. printf("GPIO%d = %d (GPIO%d = %d) -> %s\n", GPIOIN, in, GPIO, read, pass ? "passed":"failed" );
  21. }
  22. void digitalWriteEx(int pin, int mode) {
  23. digitalWrite(pin, mode);
  24. printf("out = %d ", mode);
  25. delayMicroseconds(5000);
  26. CheckGPIO(mode);
  27. }
  28. void pullUpDnControlEx (int pin ,int mode) {
  29. pullUpDnControl (pin, mode);
  30. int out = mode==PUD_UP ? 1:0;
  31. printf("in = %4s ", mode==PUD_UP ? "up":"down");
  32. delayMicroseconds(5000);
  33. CheckGPIO(out);
  34. }
  35. int main (void) {
  36. printf("WiringPi GPIO test program 2 (using GPIO%d (output) and GPIO%d (input) via sys)\n", GPIO, GPIOIN);
  37. printf(" testing pullUpDnControl and pinMode PM_OFF\n");
  38. if (wiringPiSetupSys() == -1) {
  39. printf("wiringPiSetupSys failed\n\n");
  40. exit(EXIT_FAILURE);
  41. }
  42. pinMode(GPIOIN, INPUT);
  43. pinMode(GPIO, OUTPUT);
  44. printf("\nTest output\n");
  45. digitalWriteEx(GPIO, HIGH);
  46. delayMicroseconds(600000);
  47. digitalWriteEx(GPIO, LOW);
  48. delayMicroseconds(600000);
  49. printf("\nTest output off with pull up\n");
  50. pinMode(GPIO, OUTPUT);
  51. digitalWriteEx(GPIO, LOW);
  52. pullUpDnControl (GPIO, PUD_UP);
  53. pinMode(GPIO, PM_OFF);
  54. delayMicroseconds(600000);
  55. printf("out = off ");
  56. CheckGPIO(HIGH);
  57. delayMicroseconds(600000);
  58. printf("\nTest output off with pull down\n");
  59. pullUpDnControl (GPIO, PUD_DOWN);
  60. pinMode(GPIO, PM_OFF);
  61. delayMicroseconds(600000);
  62. printf("out = off ");
  63. CheckGPIO(LOW);
  64. delayMicroseconds(600000);
  65. return(EXIT_SUCCESS);
  66. }