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.
 
 
 
 
 

54 rivejä
803 B

  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. }