I want to build an IR switch. What I mean is to have an IR transmitter (IR LED) and on the other side to have an IR receiver. I want to sent lets say the pulse: ON-(1sec delay)-OFF-(1sec delay)-ON and the IR receiver to accept the pulse and do nothing. However, when an object "cuts" the IR connection and the IR receiver does not get the pulse to give me a signal (for example Light ON a green LED on pin 13). My concern is how do I implement this, since they have to work in parallel, because If I implement this in void loop(), there should be the one after the other, meaning:
Any sample/test code how to start with? I have never used timers before! It's totally new to me! I am googling it however to find something helpful and well written!
larryd:
Show us your current ‘complete’ code, we can discuss changes necessary.
Use CTRL T to format your code.
Attach the sketch between code tags, use the </> icon in the posting menu.
[code]Paste your sketch here[/code]
See attachment:
Thank you for the code! It runs ok! I embedded to my central code, and on the void setup() field I remote all the other functions/commands and the result is that it cannot run. My concern is that if it affected by other commands, such as Serial.println I don't know...
Just curious. I have faced such incompatibility between commands in the same code again in the past. I went "down" searching to assembly and registers links for days without success. Is this something that has to do with the compiler?
“I have faced such incompatibility between commands”
This needs to be explained to us better.
Any poorly written code, on any controller, can lock up other code from running.
If you call a function that ‘waits’ for an external event rather than ‘checking’ for the event, you have blocking code.
Get into the habit of always writing non blocking code.
My concern is that if it affected by other commands, such as Serial.println I don't know...
Try it!
It won't break just because you write duff code! The joy of this hobby is being able to try stuff, if it doesn't work modify it until it does, when it works you can congratulate yourself. Don't be scared to experiment.