IFD:Designing Networked Objects/César Felipe Daher: Difference between revisions

From Medien Wiki
Line 81: Line 81:
[[File:LEDcommand_flowchart.png]]
[[File:LEDcommand_flowchart.png]]


As an example for the columns:
This logic was translated into the following function (for columns):
<pre>
<pre>
//check is the retrieved tweet
int findDirHor (String check) {
int findDirHor (String check) {
   if (check.indexOf("left") != std::string::npos && check.indexOf("right") != std::string::npos) {
   if (check.indexOf("left") != std::string::npos && check.indexOf("right") != std::string::npos) {
     Serial.println("left and right");
     Serial.println("left and right");
     return 0;]
     return 0;
   } if (check.indexOf("right") != std::string::npos) {
   } if (check.indexOf("right") != std::string::npos) {
     Serial.println("right");
     Serial.println("right");
Line 98: Line 99:
}
}
</pre>
</pre>
However, since the LEDs are declared in a 3x3 array, the indexes mustn't ever exceed 2 or go below 0. Therefore, the function for applying the index change was written taking these cases into consideration.
<pre>
//val is returned from the findDirHor() function
void columnIndex (int val) {
  if (j == 0 && val == -1) { j = 2;
  } else if (j == 2 && val == 1) {  j = 0;
  } else { j = j + val;
  }}</pre>