Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 

81 linhas
2.0 KiB

  1. // WiringPi test program: Kernel char device interface / sysfs successor
  2. // Compile: gcc -Wall wiringpi_test3_device.c -o wiringpi_test3_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 = 24; //BCM 19
  11. const int GPIOIN = 25; //BCM 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 WiringPi GPIO%d (output) and GPIO%d (input) via GPIO device)\n", GPIO, GPIOIN);
  37. printf(" testing pullUpDnControl and pinMode PM_OFF\n");
  38. if (wiringPiSetupGpioDevice(WPI_PIN_WPI) == -1) {
  39. printf("wiringPiSetupGpioDevice 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. }