piface.c 803 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * piface.c:
  3. * Simple test for the PiFace
  4. *
  5. * Read the buttons and output the same to the LEDs
  6. */
  7. #include <wiringPi.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <stdint.h>
  11. int outputs [4] = { 0,0,0,0 } ;
  12. void scanButton (int button)
  13. {
  14. if (digitalRead (button) == LOW)
  15. {
  16. outputs [button] ^= 1 ;
  17. digitalWrite (button, outputs [button]) ;
  18. }
  19. while (digitalRead (button) == LOW)
  20. delay (1) ;
  21. }
  22. int main (void)
  23. {
  24. int pin, button ;
  25. printf ("Raspberry Pi wiringPiFace test program\n") ;
  26. if (wiringPiSetupPiFace () == -1)
  27. exit (1) ;
  28. // Enable internal pull-ups
  29. for (pin = 0 ; pin < 8 ; ++pin)
  30. pullUpDnControl (pin, PUD_UP) ;
  31. for (;;)
  32. {
  33. for (button = 0 ; button < 4 ; ++button)
  34. scanButton (button) ;
  35. delay (1) ;
  36. }
  37. return 0 ;
  38. }