You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

56 lines
1.4 KiB

  1. // WiringPi test program: Kernel char device interface / sysfs successor
  2. // Compile: gcc -Wall wiringpi_test1_device.c -o wiringpi_test1_device -lwiringPi
  3. #include "wpi_test.h"
  4. #include <signal.h>
  5. #include <time.h>
  6. #include <sys/time.h>
  7. const int GPIO = 19;
  8. const int GPIOIN = 26;
  9. const int ToggleValue = 4;
  10. int main (void) {
  11. printf("WiringPi GPIO test program 1 (using GPIO%d (output) and GPIO%d (input) via sys)\n", GPIO, GPIOIN);
  12. printf(" testing digitalWrite, digitalRead and pullUpDnControl\n");
  13. if (wiringPiSetupSys() == -1) {
  14. printf("wiringPiSetupSys failed\n\n");
  15. exit(EXIT_FAILURE);
  16. }
  17. pinMode(GPIOIN, INPUT);
  18. pinMode(GPIO, OUTPUT);
  19. printf("toggle %d times ...\n", ToggleValue);
  20. for (int loop=1; loop<ToggleValue; loop++) {
  21. digitalWriteEx(GPIO, GPIOIN, LOW);
  22. delayMicroseconds(600000);
  23. digitalWriteEx(GPIO, GPIOIN, HIGH);
  24. delayMicroseconds(600000);
  25. }
  26. digitalWrite(GPIO, LOW);
  27. printf("\nWiringPi GPIO test program (using GPIO%d (input pull up/down) and GPIO%d (input) via sys)\n", GPIO, GPIOIN);
  28. pullUpDnControl (GPIO, PUD_UP);
  29. pinMode(GPIO, INPUT);
  30. delayMicroseconds(3000000);
  31. pullUpDnControl (GPIOIN, PUD_OFF);
  32. for (int loop=1; loop<ToggleValue; loop++) {
  33. pullUpDnControlEx (GPIO, GPIOIN, PUD_DOWN);
  34. delayMicroseconds(600000);
  35. pullUpDnControlEx (GPIO, GPIOIN, PUD_UP);
  36. delayMicroseconds(600000);
  37. }
  38. //Error wrong direction - only for fun
  39. digitalWrite(GPIO, LOW);
  40. return UnitTestState();
  41. }