Hello all, the title may be a bit confusing but all I really have is 2 numbers. A rowState which ranges from 1-5 and a columnState which ranges from 1-5. So what my program does is that it first detects if a "row button" is hit. If one of the 5 row buttons are hit then the state of a variable "rowState" changes to either 1-5 depedning on which button you hit. Then it does the same with the columns. Once i hit a row button and a column button i tell my program to print both of the states to see if it works and it does. Now the question is how would I light up a certain led from a 5 by 5 grid (max7219) using those coordinates so to speak. So if rowState = 1 and columnState = 1 and I ultimately want to have the led (1,1) turn on. Any ideas, Im still kind of a beginner in arduino and I'm surprised I got this far with the project so any help is thankfull.
Ok, that's easy enough and there are a few ways to do it, but the most common way it to use a container "Packet". You want to send the data as < value1 , value2 >. If the first char is '<', then collect the rest until the serial monitor receives '>'. A comma is a good way to split the data into multiple parts, so you will need that too.
So it would be something like this.
if(Serial.available() > 0){
char temp = Serial.read(); // example incomming data <1,23,456,7890>
if( temp == '<' ) // find this char in the buffer, and start collecting the rest after it.
{
while( true ) // just a loop to continuously gather the rest of the chars
// another Serial.available and Serial.read() here.
//look at the incoming char and see if it is a comma or the end of the container '>'
// if it in not a comma or >, then store the char(s) into a temporary array
// if the char IS a comma then increment the arrays index by 1 to store the next char(s)
// keep doing this until the incoming char is > then break out of the while loop and you should have all your data
I have a working example if you want to take a look at it.
So I sort of understand it haha. So the data I'm recieving is rowState and columnState. How would i apply your program to mine. I'm assuming its gonna go after the column check.
// zoomkat 8-6-10 serial I/O string test
// type a string in serial monitor. then send or enter
// for IDE 0019 and later
//A very simple example of sending a string of characters
//from the serial monitor, capturing the individual
//characters into a String, then evaluating the contents
//of the String to possibly perform an action (on/off board LED).
int ledPin = 13;
String readString;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
Serial.println("serial on/off test 0021"); // so I can keep track
}
void loop() {
while (Serial.available()) {
delay(3);
char c = Serial.read();
readString += c;
}
if (readString.length() >0) {
Serial.println(readString);
if(readString.indexOf("on") >=0)
{
digitalWrite(ledPin, HIGH);
}
if(readString.indexOf("off") >=0)
{
digitalWrite(ledPin, LOW);
}
readString="";
}
}