Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Thread.h> // Bibioteca das threads
- #include <ThreadController.h> // Bibioteca de controle das threads
- Thread Servo1; // Define thread de
- Thread Leds; // Define thread
- //Thread Leds2; // Define thread
- #include <Servo.h>
- Servo myservo;
- int pos = 0;
- //-------------------------------------
- void setup()
- {
- Servo1.setInterval(1); // Thread de 200 ms para
- Servo1.onRun(RodaServo); // Executa função de
- Leds.setInterval(1); // Thread de 200 ms para
- Leds.onRun(LigaLed); // Executa função
- pinMode(2, OUTPUT);
- pinMode(3, OUTPUT);
- pinMode(4, OUTPUT);
- pinMode(5, OUTPUT);
- pinMode(6, OUTPUT);
- pinMode(7, OUTPUT);
- pinMode(8, OUTPUT);
- pinMode(9, OUTPUT);
- pinMode(11, OUTPUT);
- pinMode(12, OUTPUT);
- pinMode(13, OUTPUT);
- myservo.attach(10);
- }
- //--------------------------------------
- void loop()
- {
- if (Servo1.shouldRun()) // Se deve executar função Conta_Tempo()
- Servo1.run(); // Execute função Conta_Tempo()
- if (Leds.shouldRun()) // Se deve executar função Le_Moedeiro()
- Leds.run(); // Execute função Le_Moedeiro()
- }
- //--------------------------------------
- void RodaServo()
- {
- for (pos = 0; pos <= 180; pos += 1) // goes from 0 degrees to 180 degrees
- { // in steps of 1 degree
- myservo.write(pos); // tell servo to go to position in variable 'pos'
- delay(15); // waits 15ms for the servo to reach the position
- }
- for (pos = 180; pos >= 0; pos -= 1) // goes from 180 degrees to 0 degrees
- {
- myservo.write(pos); // tell servo to go to position in variable 'pos'
- delay(15); // waits 15ms for the servo to reach the position
- }
- }
- //--------------------------------------
- void LigaLed()
- {
- digitalWrite(11, HIGH);
- digitalWrite(13, LOW);
- delay(50);
- digitalWrite(12, HIGH);
- digitalWrite(11, LOW);
- delay(50);
- digitalWrite(13, HIGH);
- digitalWrite(12, LOW);
- delay(50);
- digitalWrite(2, HIGH);
- digitalWrite(6, HIGH);
- delay(100);
- digitalWrite(3, HIGH);
- digitalWrite(7, HIGH);
- delay(100);
- digitalWrite(4, HIGH);
- digitalWrite(8, HIGH);
- delay(100);
- digitalWrite(5, HIGH);
- digitalWrite(9, HIGH);
- delay(100);
- digitalWrite(2, LOW);
- digitalWrite(6, LOW);
- delay(100);
- digitalWrite(3, LOW);
- digitalWrite(7, LOW);
- delay(100);
- digitalWrite(4, LOW);
- digitalWrite(8, LOW);
- delay(100);
- digitalWrite(5, LOW);
- digitalWrite(9, LOW);
- delay(100);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement