main.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*********************************************************************
  2. * dimmer example for Versa1.0
  3. * Connect dimmer board to Versa1's VNH2 port.
  4. *********************************************************************/
  5. #define BOARD Versa1
  6. #include <fruit.h>
  7. #include <dimmer.h>
  8. #include <switch.h>
  9. t_delay mainDelay;
  10. //----------- Setup ----------------
  11. void setup(void) {
  12. fruitInit();
  13. dimmerInit(); // init dimmer module
  14. delayStart(mainDelay, 20000); // init the mainDelay to 20 ms
  15. //----------- Switch setup ----------------
  16. switchInit(); // init switch module
  17. switchSelect(0,K1); // assign connector K1 to switch channel 0
  18. switchSelect(1,K2);
  19. switchSelect(2,K3);
  20. switchSelect(3,K4);
  21. }
  22. // ---------- Main loop ------------
  23. void loop() {
  24. fraiseService();// listen to Fraise events
  25. dimmerService(); // dimmer management routine
  26. switchService(); // switch management routine
  27. if(delayFinished(mainDelay)) // when mainDelay triggers :
  28. {
  29. delayStart(mainDelay, 20000); // re-init mainDelay
  30. //dimmerPrintDebug(); //
  31. switchSend();
  32. }
  33. }
  34. // ---------- Interrupts ------------
  35. void highInterrupts()
  36. {
  37. dimmerHighInterrupt();
  38. }
  39. void lowInterrupts()
  40. {
  41. dimmerLowInterrupt();
  42. }
  43. // ---------- Receiving ------------
  44. void fraiseReceive() // receive raw bytes
  45. {
  46. unsigned char c=fraiseGetChar();
  47. if(c==40) dimmerReceive(); // if first byte is 40, then call dimmer receive function.
  48. }