[SOLVED]How to use arduino to mimic button input into another?

Hello everyone, hope you're all well. Just had a quick question and hoping for a little bit of guidance as I haven't been able to find any clear information on what Im hoping to do.

I'm fairly new to the arduino world and have only been working on this project for the last 2 weeks or so and doing a heck of a lot of reading and testing. I have some very basic C++ knowledge from several years ago when I did a subject at University.

I have been tinkering with the VGAX library (GitHub - smaffer/vgax: VGA library for Arduino UNO) and have created a simple 2 digit counter which displays on a monitor.

As I understand it, the library uses up all of the timers and hence limits the ability of some libraries as well as some functions. So I ended up using delay to debounce the button (I know against all recommendation) because I couldn't get millis to work.

Anyhow the whole setup works just as expected. However I now wanted the setup to become wireless and have pursued using infrared.

I have carried out the tests and can successfully transmit and read the button signal.

So where I began to run into a problem is that the board had run out of memory and I couldn't implement the IR code for receiving the signal.

So I then cut back and simplified the sketch and managed to integrate the IR into it, but for some reason it doesn't seem to work.

So my question is: Can I use a spare arduino board to receive the IR signal and then connect this board to the other arduino in a way that it will mimic the function of a button being pressed?

I hope that makes sense. Any help would be greatly appreciated and I have added sketches for receiving and sending the ir signal. As well as the current button counter increment sketch and my attempt to include the ir functionality into it.

simpleVGAXdualDigitcounter.ino (10.1 KB)

ButtonSignalSendviaIR.ino (446 Bytes)

ButtonSignalReceiveViaIR.ino (596 Bytes)

VGAXcounterIRattempt.ino (9.9 KB)

Hi everyone. Firstly, just thought I'd say thank you to anybody who may have taken the time to read over my ramblings and download the attached files.

Secondly, through more tireless reading along with plenty of trial and error, I was able to resolve the problem.

I got out the multimeter and began to check the behaviour of the OUTPUT pin and everything was just as it should, but where I was going wrong was with the initial states of pins. Once this was sorted I began to see a trigger on the monitor which was increasing the counter randomly. But after applying a slight delay to it, the infrared button signal began to work as it should.

I have included an image of the setup, as well as the two sketches with the modified code as it could well help someone else.

simpleVGAXdualDigitcounterWorks.ino (9.89 KB)

IR_receive_ButtonTestWorks.ino (470 Bytes)

Learn This.

Arduino has time functions, millis() and micros() that increment from startup.
Both return unsigned long values.

For millisecond timing there is no need to use up hardware timers.
The micros() function has a granularity of 4 (the low 2 bits are always 0).

Unsigned math will give you the right answer as long as you Subtract the start time from the end time to get the difference. That works right through rollover. The interval limit is set by the size of the unsigned variables used, with unsigned long you can measure 49.71~ days in milliseconds.

Learn the very common sense tutorial at that link and you can time lots of simultaneous events without using hardware timer code at all.

One thing.... you will learn to not use delay() or other execution-blocking code, a GOOD thing.

Thanks for the comments GFS, I am indeed aware about delay functions ultimately stopping other processes running in the back ground and definitely agree with you that its better practice to avoid delay.

For some reason the only button format that seemed to work prior to implementing the infrared was one with a delay function. Maybe I just couldn't figure out how to call the equivalent function within the VGAX library.

I had found some useful reading over at one of Nick Gammon's webpages (Gammon Forum : Electronics : Microprocessors : Switches tutorial) and have also found several button libraries that I'm looking at trying to implement now that Ive got the infrared sorted out.

I think this forum is fantastic and great way to help new comers like myself ease into an arduino world where imagination is the only limit.

Thanks

I don't know what VGAX is for or about but when I saw

As I understand it, the library uses up all of the timers and hence limits the ability of some libraries as well as some functions. So I ended up using delay to debounce the button (I know against all recommendation) because I couldn't get millis to work.

I knew that you have a far better option, so I give you a link.

Here's a button and led library with example. I use jumpers for buttons, 4 jumpers and an Uno are all you need to run the example. The library files go in the sketch folder for this example.

ioclasses.h (1009 Bytes)

io_events_202.ino (3.06 KB)

ioclasses.cpp (2.58 KB)