Advertisement
RuiViana

Threads_MRS

Jul 5th, 2016
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.78 KB | None | 0 0
  1. #include <Thread.h>                         // Bibioteca das threads
  2. #include <ThreadController.h>               // Bibioteca de controle das threads    
  3. Thread Servo1;                              // Define thread de
  4. Thread Leds;                                // Define thread
  5. //Thread Leds2;                             // Define thread
  6.  
  7. #include <Servo.h>
  8. Servo myservo;
  9. int pos = 0;
  10. //-------------------------------------
  11. void setup()
  12. {
  13.   Servo1.setInterval(1);                    // Thread de 200 ms para
  14.   Servo1.onRun(RodaServo);                  // Executa função de
  15.   Leds.setInterval(1);                      // Thread de 200 ms para
  16.   Leds.onRun(LigaLed);                      // Executa função
  17.  
  18.   pinMode(2, OUTPUT);
  19.   pinMode(3, OUTPUT);
  20.   pinMode(4, OUTPUT);
  21.   pinMode(5, OUTPUT);
  22.   pinMode(6, OUTPUT);
  23.   pinMode(7, OUTPUT);
  24.   pinMode(8, OUTPUT);
  25.   pinMode(9, OUTPUT);
  26.  
  27.   pinMode(11, OUTPUT);
  28.   pinMode(12, OUTPUT);
  29.   pinMode(13, OUTPUT);
  30.   myservo.attach(10);
  31. }
  32. //--------------------------------------
  33. void loop()
  34. {
  35.   if (Servo1.shouldRun())                    // Se deve executar função Conta_Tempo()
  36.     Servo1.run();                            // Execute função Conta_Tempo()
  37.  
  38.   if (Leds.shouldRun())                     // Se deve executar função Le_Moedeiro()
  39.     Leds.run();                             // Execute função Le_Moedeiro()
  40. }
  41. //--------------------------------------
  42. void RodaServo()
  43. {
  44.   for (pos = 0; pos <= 180; pos += 1)     // goes from 0 degrees to 180 degrees
  45.   { // in steps of 1 degree
  46.     myservo.write(pos);                   // tell servo to go to position in variable 'pos'
  47.     delay(15);                            // waits 15ms for the servo to reach the position
  48.   }
  49.   for (pos = 180; pos >= 0; pos -= 1)     // goes from 180 degrees to 0 degrees
  50.   {
  51.     myservo.write(pos);                   // tell servo to go to position in variable 'pos'
  52.     delay(15);                            // waits 15ms for the servo to reach the position
  53.   }
  54. }
  55. //--------------------------------------
  56. void LigaLed()
  57. {
  58.   digitalWrite(11, HIGH);
  59.   digitalWrite(13, LOW);
  60.   delay(50);
  61.   digitalWrite(12, HIGH);
  62.   digitalWrite(11, LOW);
  63.   delay(50);
  64.   digitalWrite(13, HIGH);
  65.   digitalWrite(12, LOW);
  66.   delay(50);
  67.   digitalWrite(2, HIGH);
  68.   digitalWrite(6, HIGH);
  69.   delay(100);
  70.   digitalWrite(3, HIGH);
  71.   digitalWrite(7, HIGH);
  72.   delay(100);
  73.   digitalWrite(4, HIGH);
  74.   digitalWrite(8, HIGH);
  75.   delay(100);
  76.   digitalWrite(5, HIGH);
  77.   digitalWrite(9, HIGH);
  78.   delay(100);
  79.   digitalWrite(2, LOW);
  80.   digitalWrite(6, LOW);
  81.   delay(100);
  82.   digitalWrite(3, LOW);
  83.   digitalWrite(7, LOW);
  84.   delay(100);
  85.   digitalWrite(4, LOW);
  86.   digitalWrite(8, LOW);
  87.   delay(100);
  88.   digitalWrite(5, LOW);
  89.   digitalWrite(9, LOW);
  90.   delay(100);
  91.  
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement