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

test1.c 1.4 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * test1.c:
  3. * Simple test program to test the wiringPi functions
  4. */
  5. #include <wiringPi.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <stdint.h>
  9. // Simple sequencer data
  10. // Triplets of LED, On/Off and delay
  11. uint8_t data [] =
  12. {
  13. 0, 1, 1,
  14. 1, 1, 1,
  15. 0, 0, 0, 2, 1, 1,
  16. 1, 0, 0, 3, 1, 1,
  17. 2, 0, 0, 4, 1, 1,
  18. 3, 0, 0, 5, 1, 1,
  19. 4, 0, 0, 6, 1, 1,
  20. 5, 0, 0, 7, 1, 1,
  21. 6, 0, 1,
  22. 7, 0, 1,
  23. 0, 0, 1, // Extra delay
  24. // Back again
  25. 7, 1, 1,
  26. 6, 1, 1,
  27. 7, 0, 0, 5, 1, 1,
  28. 6, 0, 0, 4, 1, 1,
  29. 5, 0, 0, 3, 1, 1,
  30. 4, 0, 0, 2, 1, 1,
  31. 3, 0, 0, 1, 1, 1,
  32. 2, 0, 0, 0, 1, 1,
  33. 1, 0, 1,
  34. 0, 0, 1,
  35. 0, 0, 1, // Extra delay
  36. 9, 9, 9, // End marker
  37. } ;
  38. int main (void)
  39. {
  40. int pin ;
  41. int dataPtr ;
  42. int l, s, d ;
  43. printf ("Raspberry Pi wiringPi test program\n") ;
  44. if (wiringPiSetup () == -1)
  45. exit (1) ;
  46. for (pin = 0 ; pin < 8 ; ++pin)
  47. pinMode (pin, OUTPUT) ;
  48. pinMode (8, INPUT) ; // Pin 8 SDA0 - Has on-board 2k2 pull-up resistor
  49. dataPtr = 0 ;
  50. for (;;)
  51. {
  52. l = data [dataPtr++] ; // LED
  53. s = data [dataPtr++] ; // State
  54. d = data [dataPtr++] ; // Duration (10ths)
  55. if ((l + s + d) == 27)
  56. {
  57. dataPtr = 0 ;
  58. continue ;
  59. }
  60. digitalWrite (l, s) ;
  61. if (digitalRead (8) == 0) // Pressed as our switch shorts to ground
  62. delay (d * 10) ; // Faster!
  63. else
  64. delay (d * 100) ;
  65. }
  66. return 0 ;
  67. }