i need a help i cant create single inverse signal by millis. my code cyclical delay but i need single by millis
please who can help to show me example
i need a help i cant create single inverse signal by millis. my code cyclical delay but i need single by millis
please who can help to show me example
#define load_button 9
const int ledPin = 11;
const int ledPin2 = 12;
// Variables will change:
int ledState = LOW; // ledState used to set the LED
int ledState2 = LOW;
// Generally, you should use "unsigned long" for variables that hold time
// The value will quickly become too large for an int to store
// will store last time LED was updated
unsigned long previousMillis = 0;
void setup() {
// set the digital pin as output:
pinMode(ledPin, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(load_button, INPUT_PULLUP);
}
void signal(){
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= 0 && currentMillis - previousMillis <= 1000) {
digitalWrite(ledPin,HIGH);
}
else{
digitalWrite(ledPin,LOW);
}
if (currentMillis - previousMillis >= 400 && currentMillis - previousMillis <= 5000) {
digitalWrite(ledPin2,HIGH);
}
else{
digitalWrite(ledPin2,LOW);
}
}
void loop() {
if (digitalRead(load_button) == LOW) {
signal();
}
}
#define load_button 9
const int ledPin = 11;
const int ledPin2 = 12;
// Variables will change:
int ledState = LOW; // ledState used to set the LED
int ledState2 = LOW;
// Generally, you should use "unsigned long" for variables that hold time
// The value will quickly become too large for an int to store
// will store last time LED was updated
unsigned long previousMillis = 0;
void setup() {
// set the digital pin as output:
pinMode(ledPin, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(load_button, INPUT_PULLUP);
}
void signal(){
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= 0 && currentMillis - previousMillis <= 1000) {
digitalWrite(ledPin,HIGH);
}
else{
digitalWrite(ledPin,LOW);
}
if (currentMillis - previousMillis >= 400 && currentMillis - previousMillis <= 5000) {
digitalWrite(ledPin2,HIGH);
}
else{
digitalWrite(ledPin2,LOW);
}
}
void loop() {
if (digitalRead(load_button) == LOW) {
signal();
}
}