Uso de la función millis

Necesito hacer un semáforo con una función milis en lugar de delay el problema es que no pasa del primer led.

Código:
const int PinV=6,PinA=7,PinR=8;
long previousMillis = 0;
int i=0;
long interval = 0; 
void setup() {
  pinMode(PinV, OUTPUT);
  pinMode(PinA, OUTPUT);
  pinMode(PinR, OUTPUT);
  int tiempo, tiempo2, tiempo3,a,b,c;//Variables para control de tiempos
}
void loop(){
  int tiempo, a;
  tiempo = analogRead(0);//Declarando el PIN analogo para entrada de Voltaje
  tiempo = map(tiempo, 0, 1023, 0, 60);//Definiendo el rango de numeros que necesito para los tiempos max 60s
  a=0;//Se define como variable contadora se iguala a 0 para el inicio
  unsigned long currentMillis = millis();
  if(currentMillis - tiempo > interval) {
    tiempo = currentMillis;   
      if(i==0){
        digitalWrite(PinV, HIGH);
        digitalWrite(PinA, LOW);
        digitalWrite(PinR, LOW);
        interval=2000;
      }
      else if(i==1 or i==3 or i==5 or i==7 or i==9){
        interval=250;
        digitalWrite(PinA, LOW);
        digitalWrite(PinV, HIGH);
        digitalWrite(PinR, LOW);
      }
      else if(i==2 or i==4 or i==6 or i==8){
        interval=250;
        digitalWrite(PinA, LOW);
        digitalWrite(PinV, LOW);
        digitalWrite(PinR, LOW);
      }
      else if(i==10){
        interval=2000;
        digitalWrite(PinV, LOW);
        digitalWrite(PinR, LOW);
        digitalWrite(PinA, HIGH);
      }
      else if (i==11){
        digitalWrite(PinV, LOW);
        digitalWrite(PinA, LOW);
        digitalWrite(PinR, HIGH);
        i=-1;
      }
      i++; 
}
}
 
¿Existe el comparador 'or' en ese lenguaje?
 
Buenas a todos, estoy realizando un sencillo proyecto en arduino que basicamente consiste en encender un Led de forma intermitente durante 1.5 segundos cada 4 segundos (un flasheo que dura 1.5 segundos en intervalos de 4 segundos) para iniciar el flasheo quiero usar un pulsador conectado al pin Digital 2 de manera que con una pulsación inicie y con otra se detenga. Hasta acá todo bien en mi codigo pero sucede que muchas veces al cerrar el pulsador el conteo no empieza inmediatamente si no que tengo que esperar los 4 segundos iniciales de retardo para que empiece a funcionar, y la idea es que el led en el momento de cerrar el pulsador encienda por 1.5 segundos, apague y espere 4 segundos antes de volver a encender y asi todo el ciclo. Dejo mi codigo por aca

Código:
int pbuttonPin = 2;// connect output to push button
int relayPin = 13;// Connected to relay (LED)

int val = 0; // push value from pin 2
int lightON = 0;//light status
int pushed = 0;//push status
int start =0;

const long interval = 4000;
unsigned long previousMillis = 0;        // will store last time LED was updated


void setup() {
  // Robojax.com code and video tutorial for push button ON and OFF
  Serial.begin(9600);
  pinMode(pbuttonPin, INPUT_PULLUP);
  pinMode(relayPin, OUTPUT);
 digitalWrite(relayPin, HIGH);// keep the load OFF at the begining. If you wanted to be ON, change the HIGH to LOW
}

void wipers() {

  unsigned long currentMillis = millis();


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

    // set the LED with the ledState of the variable:
    digitalWrite(relayPin, HIGH);
  //delay(1500);
    // digitalWrite(ledPin, LOW);

   if (currentMillis - previousMillis >= 5500) {

      digitalWrite(relayPin, LOW);

       previousMillis = currentMillis;
    }
}
}
void loop() {
// Robojax.com code and video tutorial for push button ON and OFF
  val = digitalRead(pbuttonPin);// read the push button value

  if(val == HIGH && lightON == LOW){

    pushed = 1-pushed;
    delay(100);
  }   

  lightON = val;

      if(pushed == HIGH){
        Serial.println("Light OFF");
        digitalWrite(relayPin, LOW);
       start=0;
      
      }else{
       Serial.println("Light ON");

        // digitalWrite(relayPin, HIGH);

   wipers();
  }
        delay(100);
  
      }
 
Buenos días a todos. Necesito su ayuda o al menos una orientacion sobre como terminar este proyecto.
Estoy creando: Un control de escobillas para vehículo.
Funcionamiento: Con un pulsador (palanca) al presionarse (1) una vez la funcion intermitente se pone en marcha esto es un ciclo que corre de esta forma: Cada 4 segundos el LED 13 enciende por un periodo de 1.5 segundos. Al presionar nuevamente el pulsador la función intermitente se detiene. (ESTA PARTE YA FUNCIONA)
Necesito ayuda para: Se requiere que desde el momento en que el pulsador es accionado el LED13 se encienda, si el pulsador se mantiene apretado por un periodo indefinido (mayor a 4 segundos) al desconectarse el LED13 se apaga, acaba su función. Si el pulsador es accionado y liberado en un tiempo menor a 4 segundos corre la función arriba descrita (con (1)vez el intermitente se activa a la (2)da vez el intermitente se apaga.

Espero que se entienda lo que quiero hacer y alguien me pueda hechar un cable sobre como lograrlo. Dejo mi codigo como lo tengo.

Código:
int pbuttonPin = 2;// connect output to push button
int relayPin = 13;// Connected to relay (LED)

int val = 0; // push value from pin 2
int lightON = 0;//light status
int pushed = 0;//push status
int start =0;

const long interval = 4000;
unsigned long previousMillis = 0;        // will store last time LED was updated


void setup() {
  // Robojax.com code and video tutorial for push button ON and OFF
 // Serial.begin(9600);
  pinMode(pbuttonPin, INPUT_PULLUP);
  pinMode(relayPin, OUTPUT);
 digitalWrite(relayPin, LOW);// keep the load OFF at the begining. If you wanted to be ON, change the HIGH to LOW
}

void wipers() {

  unsigned long currentMillis = millis();


       if (currentMillis - previousMillis >= interval) {

    digitalWrite(relayPin, HIGH);

   if (currentMillis - previousMillis >= 5500) {

      digitalWrite(relayPin, LOW);

       previousMillis = currentMillis;
    }
}
}
void loop() {
// Robojax.com code and video tutorial for push button ON and OFF
  val = digitalRead(pbuttonPin);// read the push button value

  if(val == HIGH && lightON == LOW){

   previousMillis = millis() - interval;  // Permite que el LED encienda y se haga el conteo desde el momento en que el PULSADOR es accionado.

    pushed = 1-pushed;
    delay(100);
  }   

  lightON = val;

      if(pushed == HIGH){
            //  Serial.println("Light OFF");
        digitalWrite(relayPin, LOW);
      
      
      }else{

   wipers();
  }
        delay(80);
  
      }
 
Buenas, paso a comentarles que ya he resuelto el proyecto anterior del control de escobillas ("wipers control") gracias a la Libreria EasyButton de Evert Arias que facilita por mucho todos los proyectos que tengan que ver con uso de pulsadores, tiempo de rebote, doble pulsacion etc.
 
Atrás
Arriba