Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <IRremote.h>
- #include <Servo.h>
- Servo myservo; // create servo object to control a servo
- // twelve servo objects can be created on most boards
- int RECV_PIN = 3;
- IRrecv irrecv(RECV_PIN);
- decode_results results;
- int pos = 5; // variable to store the servo position
- long timeUpdate = millis();
- int servospeed;
- bool timerStatus;
- bool stopStatus;
- bool isStopped;
- int timerStart;
- int bPause = 0;
- int pauseTimer;
- void setup() {
- myservo.attach(2);
- Serial.begin(9600);
- irrecv.enableIRIn(); // Start the receiver
- timerStatus = false;
- isStopped = true;
- myservo.write(5);
- }
- void loop() {
- // MAIN LOOP
- if (irrecv.decode(&results) && timeUpdate + 500 < millis()) {
- irrecv.resume(); // Receive the next value
- // Serial.println("Чекаем канал порта");
- Serial.println(results.value);
- if (results.value == 16753245)
- {
- servospeed = 4;
- bPause = 0;
- Serial.println("1 speed");
- if (isStopped == 1){isStopped = false;}
- }
- else if (results.value == 16736925)
- {
- servospeed = 4;
- bPause = 500;
- Serial.println("2 speed");
- if (isStopped == 1){isStopped = 0;}
- }
- else if (results.value == 16769565)
- {
- servospeed = 4;
- bPause = 1000;
- Serial.println("3 speed");
- if (isStopped == 1){isStopped = 0;}
- }
- else if (results.value == 16726215)
- {
- timerStatus = false;
- if (isStopped == 0){isStopped = 1;}
- Serial.println("STOP");
- myservo.write(5);
- }
- else if (results.value == 16738455 && isStopped != 1)
- {
- timerStatus = !timerStatus;
- timerStart = millis();
- Serial.print("timer is: ");
- Serial.println(timerStatus);
- }
- else {
- timeUpdate = millis();
- // irrecv.resume(); // Receive the next value
- }
- timeUpdate = millis();
- }
- if (pauseTimer + bPause < millis() && isStopped != 1){
- Serial.println("Двигаем мотор");
- 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(2); // waits 2ms 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(servospeed); // waits XX ms for the servo to reach the position
- }
- pauseTimer = millis();
- Serial.println("Обнуляем таймер мотора");
- }
- } // end of loop
RAW Paste Data