Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. #include "mbed.h"
  2.  
  3. InterruptIn device1(p11);
  4. InterruptIn device2(p12);
  5. InterruptIn device3(p13);
  6.  
  7. DigitalOut led1(LED1);
  8. DigitalOut led2(LED2);
  9. DigitalOut led3(LED3);
  10.  
  11. Serial pc(USBTX, USBRX);
  12. Timer t;
  13.  
  14. int interruptionMoments[3];
  15. int toPrint[3];
  16. bool hasToPrint = false;
  17. bool cagada = false;
  18. int interruptionQty = 0;
  19. int tandaTime;
  20. int currentInterruptTime = 0;
  21.  
  22. void interruptionCommon(int deviceId, DigitalOut led){
  23. currentInterruptTime = t.read_us();
  24.  
  25. if (interruptionQty == 0) {
  26. tandaTime = currentInterruptTime + 1000000;
  27. }
  28.  
  29. if (currentInterruptTime > tandaTime) {
  30. if (interruptionQty < 3) {
  31. led1 = led2 = led3 = false;
  32. led = true;
  33. }
  34. cagada = interruptionQty != 3;
  35. hasToPrint = true;
  36. for (int i=0; i<3; toPrint[i] = interruptionMoments[i], i++);
  37. tandaTime = currentInterruptTime + 1000000;
  38. interruptionQty = 0;
  39. }
  40.  
  41. interruptionMoments[deviceId-1] = currentInterruptTime;
  42. interruptionQty++;
  43. }
  44.  
  45. void device1Interruption() {
  46. led1 = !led1;
  47. interruptionCommon(1, led1);
  48. }
  49.  
  50. void device2Interruption() {
  51. led2 = !led2;
  52. interruptionCommon(2, led2);
  53. }
  54.  
  55. void device3Interruption() {
  56. led3 = !led3;
  57. interruptionCommon(3, led3);
  58. }
  59.  
  60.  
  61. int main() {
  62. pc.printf("Hello World!\n");
  63. device1.rise(&device1Interruption);
  64. device2.rise(&device2Interruption);
  65. device3.rise(&device3Interruption);
  66.  
  67. tandaTime = 2147483647;
  68. t.start();
  69. while(1) {
  70. if (hasToPrint) {
  71. pc.printf("%i\t%i\t%i\t%i\n", toPrint[0], toPrint[1], toPrint[2], cagada);
  72. hasToPrint = false;
  73. }
  74. }
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement