選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 

58 行
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 <stdlib.h>
  5. #include <signal.h>
  6. #include <string.h>
  7. #include <time.h>
  8. #include <sys/time.h>
  9. const int GPIO = 19;
  10. const int GPIOIN = 26;
  11. const int ToggleValue = 4;
  12. int main (void) {
  13. printf("WiringPi GPIO test program 1 (using GPIO%d (output) and GPIO%d (input))\n", GPIO, GPIOIN);
  14. printf(" testing digitalWrite, digitalRead and pullUpDnControl\n");
  15. if (wiringPiSetupGpio() == -1) {
  16. printf("wiringPiSetupGpio failed\n\n");
  17. exit(EXIT_FAILURE);
  18. }
  19. pinMode(GPIOIN, INPUT);
  20. pinMode(GPIO, OUTPUT);
  21. printf("toggle %d times ...\n", ToggleValue);
  22. for (int loop=1; loop<ToggleValue; loop++) {
  23. digitalWriteEx(GPIO, GPIOIN, LOW);
  24. delayMicroseconds(600000);
  25. digitalWriteEx(GPIO, GPIOIN, HIGH);
  26. delayMicroseconds(600000);
  27. }
  28. digitalWrite(GPIO, LOW);
  29. printf("\nWiringPi GPIO test program (using GPIO%d (input pull up/down) and GPIO%d (input))\n", GPIO, GPIOIN);
  30. pullUpDnControl (GPIO, PUD_UP);
  31. pinMode(GPIO, INPUT);
  32. delayMicroseconds(3000000);
  33. pullUpDnControl (GPIOIN, PUD_OFF);
  34. for (int loop=1; loop<ToggleValue; loop++) {
  35. pullUpDnControlEx (GPIO, GPIOIN, PUD_DOWN);
  36. delayMicroseconds(600000);
  37. pullUpDnControlEx (GPIO, GPIOIN, PUD_UP);
  38. delayMicroseconds(600000);
  39. }
  40. //Error wrong direction - only for fun
  41. digitalWrite(GPIO, LOW);
  42. return(EXIT_SUCCESS);
  43. }