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.
 
 
 
 
 

112 line
2.5 KiB

  1. /*
  2. * test1.c:
  3. * Simple test program to test the wiringPi functions
  4. * This is a sequencer to make a patter appear on 8 LEDs
  5. * connected to the GPIO pins.
  6. *
  7. * Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
  8. ***********************************************************************
  9. * This file is part of wiringPi:
  10. * https://projects.drogon.net/raspberry-pi/wiringpi/
  11. *
  12. * wiringPi is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Lesser General Public License as published by
  14. * the Free Software Foundation, either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * wiringPi is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Lesser General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Lesser General Public License
  23. * along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
  24. ***********************************************************************
  25. */
  26. #include <wiringPi.h>
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <stdint.h>
  30. // Simple sequencer data
  31. // Triplets of LED, On/Off and delay
  32. uint8_t data [] =
  33. {
  34. 0, 1, 1,
  35. 1, 1, 1,
  36. 0, 0, 0, 2, 1, 1,
  37. 1, 0, 0, 3, 1, 1,
  38. 2, 0, 0, 4, 1, 1,
  39. 3, 0, 0, 5, 1, 1,
  40. 4, 0, 0, 6, 1, 1,
  41. 5, 0, 0, 7, 1, 1,
  42. 6, 0, 1,
  43. 7, 0, 1,
  44. 0, 0, 1, // Extra delay
  45. // Back again
  46. 7, 1, 1,
  47. 6, 1, 1,
  48. 7, 0, 0, 5, 1, 1,
  49. 6, 0, 0, 4, 1, 1,
  50. 5, 0, 0, 3, 1, 1,
  51. 4, 0, 0, 2, 1, 1,
  52. 3, 0, 0, 1, 1, 1,
  53. 2, 0, 0, 0, 1, 1,
  54. 1, 0, 1,
  55. 0, 0, 1,
  56. 0, 0, 1, // Extra delay
  57. 9, 9, 9, // End marker
  58. } ;
  59. int main (void)
  60. {
  61. int pin ;
  62. int dataPtr ;
  63. int l, s, d ;
  64. printf ("Raspberry Pi wiringPi test program\n") ;
  65. if (wiringPiSetup () == -1)
  66. exit (1) ;
  67. for (pin = 0 ; pin < 8 ; ++pin)
  68. pinMode (pin, OUTPUT) ;
  69. pinMode (8, INPUT) ; // Pin 8 SDA0 - Has on-board 2k2 pull-up resistor
  70. dataPtr = 0 ;
  71. for (;;)
  72. {
  73. l = data [dataPtr++] ; // LED
  74. s = data [dataPtr++] ; // State
  75. d = data [dataPtr++] ; // Duration (10ths)
  76. if ((l + s + d) == 27)
  77. {
  78. dataPtr = 0 ;
  79. continue ;
  80. }
  81. digitalWrite (l, s) ;
  82. if (digitalRead (8) == 0) // Pressed as our switch shorts to ground
  83. delay (d * 10) ; // Faster!
  84. else
  85. delay (d * 100) ;
  86. }
  87. return 0 ;
  88. }