analog_outputs.c 964 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /* Set analog voltage on slow analog output */
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include "rp.h"
  5. int main (int argc, char **argv) {
  6. float value [4];
  7. // Voltages can be provided as an argument (default is 1V)
  8. for (int i=0; i<4; i++) {
  9. if (argc > (1+i)) {
  10. value [i] = atof(argv[1+i]);
  11. } else {
  12. value [i] = 1.0;
  13. }
  14. printf("Voltage setting for AO[%i] = %1.1fV\n", i, value [i]);
  15. }
  16. // Initialization of API
  17. if (rp_Init() != RP_OK) {
  18. fprintf(stderr, "Red Pitaya API init failed!\n");
  19. return EXIT_FAILURE;
  20. }
  21. // Setting a voltage for each ananlog output
  22. for (int i=0; i<4; i++) {
  23. int status = rp_AOpinSetValue(i, value[i]);
  24. if (status != RP_OK) {
  25. printf("Could not set AO[%i] voltage.\n", i);
  26. }
  27. }
  28. // wait for user input
  29. getchar();
  30. // Releasing resources
  31. rp_Release();
  32. return EXIT_SUCCESS;
  33. }