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.
 
 
 
 
 

61 regels
1.5 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. int GPIO = 19;
  8. 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. if (!piBoard40Pin()) {
  18. GPIO = 23;
  19. GPIOIN = 24;
  20. }
  21. pinMode(GPIOIN, INPUT);
  22. pinMode(GPIO, OUTPUT);
  23. printf("toggle %d times ...\n", ToggleValue);
  24. for (int loop=1; loop<ToggleValue; loop++) {
  25. digitalWriteEx(GPIO, GPIOIN, LOW);
  26. delayMicroseconds(600000);
  27. digitalWriteEx(GPIO, GPIOIN, HIGH);
  28. delayMicroseconds(600000);
  29. }
  30. digitalWrite(GPIO, LOW);
  31. printf("\nWiringPi GPIO test program (using GPIO%d (input pull up/down) and GPIO%d (input) via sys)\n", GPIO, GPIOIN);
  32. pullUpDnControl (GPIO, PUD_UP);
  33. pinMode(GPIO, INPUT);
  34. delayMicroseconds(3000000);
  35. pullUpDnControl (GPIOIN, PUD_OFF);
  36. for (int loop=1; loop<ToggleValue; loop++) {
  37. pullUpDnControlEx (GPIO, GPIOIN, PUD_DOWN);
  38. delayMicroseconds(600000);
  39. pullUpDnControlEx (GPIO, GPIOIN, PUD_UP);
  40. delayMicroseconds(600000);
  41. }
  42. //Error wrong direction - only for fun
  43. digitalWrite(GPIO, LOW);
  44. return UnitTestState();
  45. }