Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- Servo servo1;
- Servo servo2;
- Servo servo3;
- Servo servo4;
- unsigned long prevMillis=0;
- uint16_t time=10000; // 10 sekund v milisekundach
- uint8_t flag=0;
- ISR(PCINT0_vect) // PB
- {
- flag=1;
- }
- ISR(PCINT2_vect) // PD
- {
- flag=1;
- }
- void setup() {
- pinMode(4, OUTPUT); // Vystup pro spinani 10 sekund
- pinMode(5, INPUT_PULLUP); // PCINT21
- pinMode(6, INPUT_PULLUP); // PCINT22
- pinMode(7, INPUT_PULLUP); // PCINT23
- pinMode(8, INPUT_PULLUP); // PCINT0
- servo1.attach(9);
- servo2.attach(10);
- servo3.attach(11);
- servo4.attach(12);
- PCICR |= (1<<PCIE0)|(1<<PCIE2);
- PCMSK0 |= (1<<PCINT0);
- PCMSK2 |= (1<<PCINT23)|(1<<PCINT22)|(1<<PCINT21);
- sei();
- }
- void loop() {
- // time update
- if (flag)
- {
- flag=0;
- prevMillis=millis();
- }
- if (prevMillis+time> millis())
- {
- digitalWrite(4, HIGH);
- }
- else
- {
- digitalWrite(4, LOW);
- }
- if (!digitalRead(5))
- {
- servo1.write(150);
- delay(1);
- }
- else
- {
- servo1.write(0);
- delay(1);
- }
- if (!digitalRead(6))
- {
- servo2.write(150);
- delay(1);
- }
- else
- {
- servo2.write(0);
- delay(1);
- }
- if (!digitalRead(7))
- {
- servo3.write(150);
- delay(1);
- }
- else
- {
- servo3.write(0);
- delay(1);
- }
- if (!digitalRead(8))
- {
- servo4.write(150);
- delay(1);
- }
- else
- {
- servo4.write(0);
- delay(1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement