digital_led_blink.c 832 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include "rp.h"
  5. int main (int argc, char **argv) {
  6. int unsigned period = 1000000; // uS
  7. int unsigned led;
  8. // index of blinking LED can be provided as an argument
  9. if (argc > 1) {
  10. led = atoi(argv[1]);
  11. // otherwise LED 0 will blink
  12. } else {
  13. led = 0;
  14. }
  15. printf("Blinking LED[%u]\n", led);
  16. led += RP_LED0;
  17. // Initialization of API
  18. if (rp_Init() != RP_OK) {
  19. fprintf(stderr, "Red Pitaya API init failed!\n");
  20. return EXIT_FAILURE;
  21. }
  22. int unsigned retries = 1000;
  23. while (retries--){
  24. rp_DpinSetState(led, RP_HIGH);
  25. usleep(period/2);
  26. rp_DpinSetState(led, RP_LOW);
  27. usleep(period/2);
  28. }
  29. // Releasing resources
  30. rp_Release();
  31. return EXIT_SUCCESS;
  32. }