30-05-2018, 21:37
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ć.
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.