main.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*********************************************************************
  2. * analog example for 8X2A
  3. * Analog capture on connectors K2, K3, K4 and K5.
  4. *********************************************************************/
  5. #define BOARD 8X2A
  6. #include <fruit.h>
  7. #include <analog.h>
  8. t_delay mainDelay;
  9. void setup(void) {
  10. //----------- Setup ----------------
  11. fruitInit();
  12. //pinModeDigitalOut(LED); // set the LED pin mode to digital out
  13. //digitalClear(LED); // clear the LED
  14. delayStart(mainDelay, 5000); // init the mainDelay to 5 ms
  15. //----------- Analog setup ----------------
  16. analogInit(); // init analog module
  17. analogSelect(0,K2); // assign connector K1 to analog channel 0
  18. analogSelect(1,K3);
  19. analogSelect(2,K4);
  20. analogSelect(3,K5);
  21. }
  22. void loop() {
  23. // ---------- Main loop ------------
  24. fraiseService(); // listen to Fraise events
  25. analogService(); // analog management routine
  26. if(delayFinished(mainDelay)) // when mainDelay triggers :
  27. {
  28. delayStart(mainDelay, 5000); // re-init mainDelay
  29. analogSend(); // send analog channels that changed
  30. }
  31. }
  32. // Receiving
  33. void fraiseReceiveChar() // receive text
  34. {
  35. unsigned char c;
  36. c=fraiseGetChar();
  37. if(c=='L'){ //switch LED on/off
  38. c=fraiseGetChar();
  39. //digitalWrite(LED, c!='0');
  40. }
  41. else if(c=='E') { // echo text (send it back to host)
  42. printf("C");
  43. c = fraiseGetLen(); // get length of current packet
  44. while(c--) printf("%c",fraiseGetChar());// send each received byte
  45. putchar('\n'); // end of line
  46. }
  47. }