digital_push_button.c 699 B

1234567891011121314151617181920212223242526272829303132
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "rp.h"
  4. int main (int argc, char **argv) {
  5. rp_pinState_t state;
  6. // Initialization of API
  7. if (rp_Init() != RP_OK) {
  8. fprintf(stderr, "Red Pitaya API init failed!\n");
  9. return EXIT_FAILURE;
  10. }
  11. // configure DIO[0:7]_N to inputs
  12. for (int i=0; i<8; i++) {
  13. rp_DpinSetDirection (i+RP_DIO0_N, RP_IN);
  14. }
  15. // transfer each input state to the corresponding LED state
  16. while (1) {
  17. for (int i=0; i<8; i++) {
  18. rp_DpinGetState (i+RP_DIO0_N, &state);
  19. rp_DpinSetState (i+RP_LED0, state);
  20. }
  21. }
  22. // Releasing resources
  23. rp_Release();
  24. return EXIT_SUCCESS;
  25. }