What I want to do is to check if any of the digital pins 2-13 are on by light up a line in the LED built in matrix that corresponds to the pins that are HIGH.
I have define a frames.h tab where I have various frames that draw solid lines in the LED Matrix of the Arduino Uno R4 WiFi built in board.
const uint32_t LedLine1[] = {
0x80080080,
0x8008008,
0x800800,
66
};
const uint32_t LedLine2[] = {
0x40040040,
0x4004004,
0x400400,
66
};
etc through LedLine12 or frames. In total 12 frames.
Then in the void loop() section I have if statements that check if the a specific digital pin is HIGH and if so, render the corresponding LED matrix frame.
// Check the state of the pin and display result in the LED Matrix
if (digitalRead(2) == HIGH) {
matrix.loadFrame(LedLine1);
}
if (digitalRead(3) == HIGH) {
matrix.loadFrame(LedLine2);
}
if (digitalRead(4) == HIGH) {
matrix.loadFrame(LedLine3);
}
etc thorough checking all ping through digital pin 13.
The problem I am having is that the matrix displays only the last frame loaded but does not keep the other frames on if the corresponding pins are HIGH. I need to overlay all the frames of the HIGH pins at the same time and not clear the previous by the load of the last if statement that is TRUE.
What I want to have are all lines light up that correspond to the digital pin that is HIGH. basically a visual check of the on/off without having to have anything attached to the pin that drives it. This to facilitate validation on the actual board of the pins without having to connect to hardware to check if it a specific pin went HIGH.
Andy suggestion on how to do this overlay of frames for each one loop sequence?
It sounds like you need to use a boolean or operation to produce a combined output fram
Something like this if LedLine1 and LedLine2 are both active (UNTESTED)
const uint32_t LedLine1[] = {
0x80080080,
0x8008008,
0x800800,
66
};
const uint32_t LedLine2[] = {
0x40040040,
0x4004004,
0x400400,
66
};
uint32_t output[4];
for (int x = 0; x < 4; x++)
{
output[x] = LedLine1[x] | LedLine2[x];
}
Then you use the output array as the loadFrame() parameter
matrix.loadFrame(output);
As I said, this is untested
I have tested this and it works
#include "Arduino_LED_Matrix.h"
ArduinoLEDMatrix matrix;
const uint32_t LedLine1[] = {
0x80080080,
0x8008008,
0x800800,
66
};
const uint32_t LedLine2[] = {
0x40040040,
0x4004004,
0x400400,
66
};
uint32_t output[4];
void setup()
{
Serial.begin(115200);
matrix.begin();
for (int x = 0; x < 4; x++)
{
output[x] = LedLine1[x] | LedLine2[x];
}
}
void loop()
{
matrix.loadFrame(LedLine1); //line 1
delay(500);
matrix.loadFrame(LedLine2); //line 2
delay(500);
matrix.loadFrame(output); //combined lines
delay(500);
matrix.clear();
delay(500);
}
Obviously you need to test which lines should be active in the combined array and merge them together as required before displaying it
I will test it on my sketch and let you know the results. I am a newbie so it may take me a few tries.
If you put the input pins in an array and the LED frames in an array you could iterate through the array, test whether each pin is HIGH and, if so, merge in the LED frame from the corresponding entry in the LED frame array
It would be even neater to put the input pins and corresponding LED frame data in an array of structs and iterate through that but I suspect that might be a step too far for you at the moment
Come back if you get stuck or want any more help
I conceptually understand what you have described but I need to practice more with arrays.
I opted for dealing with a bit at the time and it worked!! The LEDs remain on during the validation cycles.
The pic shows, skipping pin 0 and 1, starting with pin two, pin2 & 3 are HIGH, then 4&5 are LOW, 6 HIGH, 7 & 8 & 9 & 0 are LOW, 11 HIGH and finally 12 & 3 LOW.
Which matches the string that I parse to set the pins HIGH or LOW
String inputString = "110010000100"; // Example input to parse with 12 characters
Thanks for your help.
Please post your working sketch
Why bother setting the state of the pins ? You could set the output directly by parsing the input ?
I am doing a WiFi garden irrigation & light control system that will have one master board and two slave boards. The master will send a string to the slaves that would determine what pin to set HIGH to control relays for light or water valve actuators. It is in progress at the moment but when I have it more stable I will definitely post it so I can get feed back on how to make it more elegant. Right now is just crude but working 70%. Next, working on NTP section to get the date/time to control scheduled irrigation.
Thanks for the feedback but I am not sure what part the LED matrix on the Uno R4 plays in your plans
The boards will be out on the yard mounted on a weather proof box and if something is not working I can troubleshoot visually on the matrix if it is the board, not receiving data, not connected to network, etc. or one of the other items such as relays or actuators. Easier than un-mounting or bringing my laptop to the yard because I wont be able to un-mount the board easily. So my plan is using the LDE matrix to provide easy ready status for the major processes and pin status.
If you use NTP, you have a network connection. Then you can generate a simple page in the browser where you can monitor the status of the connected board. I'm not familiar with Arduino Uno R4 WiFi board but if it supports OTA then updating the running program can be done wirelessly without unplugging anything and without carrying the laptop anywhere. If this board doesn't have OTA you might consider replacing it with an ESP8266 or ESP32 microcontroller - I used OTA with ESP8266, I didn't with ESP32, but I think it supports it.
You are totally correct p . That is on "my to-learn-tasks" how to do OTA updates eventually so I can manage the code updates from the comfort of my man cave. I heard I can do similar task using Arduino Cloud. I would rather do it without a third piece of service but not sure if my board supports natively or self contained within my home network.
In this video you can see how Wemos D1 mini generates a very simple web page on my home network. If you want something similar, you don't need an additional Cloud service.