• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Przekaźnik regulowny
#4
Pokusiłem się i napisałem sobie program w stylu "Arduinowców", czyli wziąłem przykład "blink without delay" i przerobiłem go pod własne wymagania.
Dodałem warunek włączenia sekwencji załączania przekaźnika, oraz samą sekwencję w pętli nieskończonej z warunkowym przerwaniem po odliczeniu 15-stu załączeń.
Czyli wniosek jest taki:
Skoro mi się udało przerobić kod z przykładu, to każdemu się to powinno udać.


Kod:
const int Przekaznik_Pin =  5;

// Variables will change:
int ledState = LOW;             // ledState used to set the LED

// Generally, you should use "unsigned long" for variables that hold time
// The value will quickly become too large for an int to store
unsigned long previousMillis = 0;        // will store last time LED was updated

// constants won't change:
const long interval = 500;           // interval at which to blink (milliseconds)

void setup() {
    // set the digital pin as output:
    pinMode(Przekaznik_Pin, OUTPUT);
    pinMode(7,INPUT);
}

void loop() {
if(digitalRead(7)==HIGH) {
        int licznik;
        // here is where you'd put code that needs to be running all the time.

        // check to see if it's time to blink the LED; that is, if the difference
        // between the current time and last time you blinked the LED is bigger than
        // the interval at which you want to blink the LED.
        while(1){
            unsigned long currentMillis = millis();

            if (currentMillis - previousMillis >= interval) {
                // save the last time you blinked the LED
                previousMillis = currentMillis;

                // if the LED is off turn it on and vice-versa:
                if (ledState == LOW) {
                    ledState = HIGH;
                    } else {
                    ledState = LOW;
                }

                // set the LED with the ledState of the variable:
                digitalWrite(Przekaznik_Pin, ledState);
                licznik++;
            }
            if(licznik==30) break;
        }
}
}
Jeśli masz problem z kodem lub sprzętem, zadaj pytanie na forum. Nie odpowiadam na PW, jeśli nie dotyczą one spraw forum lub innych tematów prywatnych.

[Obrazek: SsIndaG.jpg]
 
Odpowiedź
  


Wiadomości w tym wątku
Przekaźnik regulowny - przez kanos1 - 30-05-2018, 12:08
RE: Przekaźnik regulowny - przez zbyszko125 - 30-05-2018, 13:33
RE: Przekaźnik regulowny - przez kanos1 - 30-05-2018, 15:12
RE: Przekaźnik regulowny - przez Robson Kerman - 30-05-2018, 21:37
RE: Przekaźnik regulowny - przez kanos1 - 30-05-2018, 23:28
RE: Przekaźnik regulowny - przez kanos1 - 04-06-2018, 12:41
RE: Przekaźnik regulowny - przez Robson Kerman - 04-06-2018, 14:23
RE: Przekaźnik regulowny - przez kanos1 - 04-06-2018, 15:24
RE: Przekaźnik regulowny - przez Robson Kerman - 04-06-2018, 21:29
Przekaźnik regulowny - przez kanos1 - 05-06-2018, 06:58

Skocz do:


Przeglądający: 1 gości