
|
|
Since this sketch will have a tendancy to have a lot of user data, I am placing that data into a separate file. You should not have to add anything to the sketch itself unless you need to add channels or to add multiple transmitter codes to a channel.
The text above is a simplified look at the receiver. There are a few more lines of code in the sketch - mostly to send the information on the OLED display, but this is generally the heart of what happens. There are three sections here, and we can show a simple block diagram of each section below.
Configuring the Receiver.
Prior to configuring the receiver, we must know the transmit code for each button we want to program. If the OLED monitor is attached, the transmit code will be displayed each time the receiver detects a transmission. If the OLED monitor is not attached, the Arduino IDE itself can be used to display this information (the NANO must be connected to the computer).
From the IDE, click on the SERIAL MONITOR button and a new screen will appear. Ensure "9600baud" is selected in the lower right corner of the screen.
This is actually the diagnostic printout from the receiver. It contains not only the received code (yellow arrow) but additional information that will be used in future projects. For now, all we need is the code (typically 7 or 8 digits). As mentioned, the receiver has a configuration file, "devices.h". This file contains the transmitter's code assignments for each button to be programmed. Not only does the receiver recognize the transmitter codes that are mapped to it's relays, it can also recognize any other code in the distributed system. There is a database of sorts that contains each known code and it's function, regardless of whether or not those codes trip a relay on the receiver. When encountering these codes, they will be displayed if the monitor is connected. And if those codes are ALSO defined for one of the relays, it will also trip that relay.
In the first section, you will see the assignment for MOTOROUT, DIMMER1, DIMMER2, and MOTORIN. These are the channel assignments. In fact, if you look at MOTOROUT, you will see that we have already assigned 5592332 for the motor function. to assign the 4 channels you desire to the MOTOROUT, DIMMER1, DIMMER2, and MOTORIN functions, simply determine their code as shown above, then put those codes into the four define statements. You will need to upload the sketch again after doing this. Next, you will encounter a define statement called DEVICECOUNT. It needs to be adjusted anytime you add or remove from the database. More on that later. But for now, just remember where it is in thie file. In the last section, you will see a structured array containing both the transmitter code, and a label describing the function. There are 18 records in this array, which of course matches the number in DEVICECOUNT. The transmit code must always be first, followed by the function name in quotes. The function name can be anything, 12 spaces or less. However, all names should be 12 characters long, with leading spaces before and after the label. When the receiver detects an incoming code, it will search on the codes in the array, and if it finds one, it will display the corresponding label describing the function. To add a record, you can simply insert it in any line within the array. There are no performance considerations from the first to last record. One caution though, pay close attention to the syntax, and especially the lack of a comma after the last line. If you add or remove records, be sure to adjust the count in DEVICECOUNT. Again, I put most, if not all of the user variables into the devices.h file so later updates of the program will not require reloading all of this information. In fact, unless you have added to the case statements (described in the prevous section), you should not have to make any changes to the program file. In a future project, I will be expanding the 4 Channel receiver to 8 channels. When I do that, we will be modifying the sketch and be adding Latching logic (the current receiver is only momentary). So this project will grow over time.
Running out of Memory.
As mentioned previously, if too many additional codes or functions are added to the sketch, the program might become unstable. In that case, you can do the following to reduce memory needs.
Note that while I could have added a function to center the labels without needing to add spaces to the names (which will save memory), I made them all 16 characters for ease of formatting by the user. However, if needed in future releases, I can add that functionality.
Construction Video
|