main.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*********************************************************************
  2. * analog example for Versa1.0
  3. * Analog capture on connectors K1, K2, K3 and K5.
  4. *********************************************************************/
  5. #define BOARD Versa1
  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. analogInitTouch(); // enable capacitive touch (for K5)
  18. analogSelect(0,K1); // assign connector K1 to analog channel 0
  19. analogSelect(1,K2);
  20. analogSelect(2,K3);
  21. analogSelectTouch(3,K5); // assign connector K5 to analog channel 3, but configure it for capacitive touch measurement.
  22. }
  23. void loop() {
  24. // ---------- Main loop ------------
  25. fraiseService(); // listen to Fraise events
  26. analogService(); // analog management routine
  27. if(delayFinished(mainDelay)) // when mainDelay triggers :
  28. {
  29. delayStart(mainDelay, 5000); // re-init mainDelay
  30. analogSend(); // send analog channels that changed
  31. }
  32. }
  33. // Receiving
  34. void fraiseReceiveChar() // receive text
  35. {
  36. unsigned char c;
  37. c=fraiseGetChar();
  38. if(c=='L'){ //switch LED on/off
  39. c=fraiseGetChar();
  40. digitalWrite(LED, c!='0');
  41. }
  42. else if(c=='E') { // echo text (send it back to host)
  43. printf("C");
  44. c = fraiseGetLen(); // get length of current packet
  45. while(c--) printf("%c",fraiseGetChar());// send each received byte
  46. putchar('\n'); // end of line
  47. }
  48. }