Go Down

Topic: Monitor two sensors to do different tasks simultaneously ? (Read 1 time) previous topic - next topic

dtokez

Hi all. I want to use two PIR sensors, basically if sensor #1 is tripped, I want to turn on light #1, delay for a while then fade off. if sensor #2 is tripped I want to turn on light #2, delay for a while then fade off.

Thinking about how I would program it, if sensor #1 has tripped and the arduino is in the delay stage of the code with the light on, it wont be able to run through the rest of the code and poll the other sensor pin to see if that has tripped also?

is there a simple way around this?

thanks  XD

Nick Gammon


pluggy

IMO delay() should never have been included in the processing language.   Its a travesty and noobs can't see past it.  I have one Arduino (Duemilanove) monitoring 3 electric meters, 1 gas meter, 2 light sensors, 5 digital thermometers, blinking an led that varies by electric use, updates an LCD display every few seconds and outputs everything it knows by serial every 2 seconds, besides running the central heating in its spare time. Not a solitary delay in the whole sketch, because basically it wouldn't work if there was.

bubulindo

Delay comes with AVR-GCC and it is useful in interfaces where a few miliseconds are needed before the next operation and millis would end up making the code more complex and not better.

Delay was never meant to be used for full seconds.


Not a solitary delay in the whole sketch, because basically it wouldn't work if there was.


my LCD library has this on it:

Code: [Select]
if (! (_displayfunction & LCD_8BITMODE)) {
    // this is according to the hitachi HD44780 datasheet
    // figure 24, pg 46

    // we start in 8bit mode, try to set 4 bit mode
    write4bits(0x03);
    delayMicroseconds(4500); // wait min 4.1ms

    // second try
    write4bits(0x03);
    delayMicroseconds(4500); // wait min 4.1ms
   
    // third go!
    write4bits(0x03);
    delayMicroseconds(150);

    // finally, set to 4-bit interface
    write4bits(0x02);
  } else {


Not a single delay?
Eu não sou o teu criado. Se respondo no fórum é para ajudar todos mediante a minha disponibilidade e disposição. Responder por mensagem pessoal iria contra o propósito do fórum e por isso evito-o.
Se realmente pretendes que eu te ajude por mensagem pessoal, então podemos chegar a um acordo e contrato onde me pagas pela ajuda que eu fornecer e poderás então definir os termos de confidencialidade do meu serviço. De forma contrária toda e qualquer ajuda que eu der tem de ser visível a todos os participantes do fórum (será boa ideia, veres o significado da palavra fórum).
Nota também que eu não me responsabilizo por parvoíces escritas neste espaço pelo que se vais seguir algo dito por mim, entende que o farás por tua conta e risco.

Dito isto, mensagens pessoais só se forem pessoais, ou seja, se já interagimos de alguma forma no passado ou se me pretendes convidar para uma churrascada com cerveja (paga por ti, obviamente).

dtokez

Thanks for the responses. I see what you mean about noobs getting stuck and set in the 'delay' way, this is the first out of a few simple projects that I won't be able to use it.

Thanks Nick for the link, looks good I will check it out

Go Up