Allowing users to turn on LEDs for a 3D display











up vote
-1
down vote

favorite












For a website I'm writing, I am allowing users to check boxes which translate into LEDs to turn on for my 3D display.



The code shouldn't need much explaining but it's really killing me. You can see that after each 5 iterations of $beforenext it goes to a whole other loop which does a similar thing with a new input and some other number changes.



Perhaps I could devise a way to do just these 4 in a single loop; I would probably be able to extrapolate to 10.



<?php session_start();

include_once("connect.php");
$x = 1;
$uid = $_SESSION['uid'];
$sql = "SELECT * FROM code3d WHERE current_user_id = $uid";
$res = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($res);
$layer1 = $row['layer1'];
$layer2 = $row['layer2'];
$layer3 = $row['layer3'];
$layer4 = $row['layer4'];
$layer5 = $row['layer5'];
$layer6 = $row['layer6'];
$layer7 = $row['layer7'];
$layer8 = $row['layer8'];
$layer9 = $row['layer9'];
$layer10 = $row['layer10'];
$del = 1;
$g = 0;
$b = 0;
$x = 1;
$countfrom14 = 14;
$positionof36 = 1;
$beforenextlayer = 1;
while ($beforenextlayer <= 5) {
while ($countfrom14 > 0) {
// if ($beforenextlayer >= 5) {
//
// if ($positionof362 == 1) {
// $arraynum = abs($countfrom14 - 14);
// }
// if ($positionof362 == 2) {
// $arraynum = abs($countfrom14 - 28);
// }
// if ($positionof362 == 3) {
// $arraynum = abs($countfrom14 - 42);
// }
// if ($positionof362 == 4) {
// $arraynum = abs($countfrom14 - 56);
// }
// if ($positionof362 == 5) {
// $arraynum = abs($countfrom14 - 70);
// }
// $x = 2;
//}

if ($positionof36 == 1) {
$arraynum = abs($countfrom14 - 14);
}
if ($positionof36 == 2) {
$arraynum = abs($countfrom14 - 28);
}
if ($positionof36 == 3) {
$arraynum = abs($countfrom14 - 42);
}
if ($positionof36 == 4) {
$arraynum = abs($countfrom14 - 56);
}
if ($positionof36 == 5) {
$arraynum = abs($countfrom14 - 70);
}
$lettertonumber = $layer1[$arraynum];
if ($lettertonumber == 'R') {
$r = 255;
}
if ($lettertonumber == 'N') {
$r = 0;
}
echo "strip".$x.".setPixelColor($countfrom14, ".$r.", ".$g.", ".$b.");<br>";
$countfrom14 = $countfrom14 - 1;
} //end of countfrom14 loop

echo "strip".$x.".show(); <br>";
echo "delay(".$del."); <br>";
$countfrom14 = 14;
$positionof36 = $positionof36 + 1;
$beforenextlayer = $beforenextlayer + 1;
} // end of beforenextlayer loop




$beforenextlayer = 5;

$positionof362 = 1;

while (($beforenextlayer >= 5) AND ($beforenextlayer <=10)) {

while ($countfrom14 > 0) {
if ($positionof362 == 1) {
$arraynum = abs($countfrom14 - 14);
}
if ($positionof362 == 2) {
$arraynum = abs($countfrom14 - 28);
}
if ($positionof362 == 3) {
$arraynum = abs($countfrom14 - 42);
}
if ($positionof362 == 4) {
$arraynum = abs($countfrom14 - 56);
}
if ($positionof362 == 5) {
$arraynum = abs($countfrom14 - 70);
}
$x = 2;

$lettertonumber = $layer2[$arraynum];
if ($lettertonumber == 'R') {
$r = 255;
}
if ($lettertonumber == 'N') {
$r = 0;
}
echo "strip".$x.".setPixelColor($countfrom14, ".$r.", ".$g.", ".$b.");<br>";
$x = 1;
if ($positionof36 == 6) {
$arraynum = abs($countfrom14 - 84);
}
if ($positionof36 == 7) {
$arraynum = abs($countfrom14 - 98);
}
if ($positionof36 == 8) {
$arraynum = abs($countfrom14 - 112);
}
if ($positionof36 == 9) {
$arraynum = abs($countfrom14 - 126);
}
if ($positionof36 == 10) {
$arraynum = abs($countfrom14 - 140);
}
$lettertonumber = $layer1[$arraynum];
if ($lettertonumber == 'R') {
$r = 255;
}
if ($lettertonumber == 'N') {
$r = 0;
}
echo "strip".$x.".setPixelColor($countfrom14, ".$r.", ".$g.", ".$b.");<br>";
$countfrom14 = $countfrom14 - 1;
} //end of countfrom14 loop
echo "strip".$x.".show(); <br>";
$x = 2;
echo "strip".$x.".show(); <br>";
$x = 1;
echo "delay(".$del."); <br>";
$countfrom14 = 14;
$positionof36 = $positionof36 + 1;
$positionof362 = $positionof362 + 1;
$beforenextlayer = $beforenextlayer + 1;
}






$beforenextlayer = 10;

$positionof363 = 1;

while (($beforenextlayer >= 10) AND ($beforenextlayer <=15)) {

while ($countfrom14 > 0) {
if ($positionof363 == 1) {
$arraynum = abs($countfrom14 - 14);
}
if ($positionof363 == 2) {
$arraynum = abs($countfrom14 - 28);
}
if ($positionof363 == 3) {
$arraynum = abs($countfrom14 - 42);
}
if ($positionof363 == 4) {
$arraynum = abs($countfrom14 - 56);
}
if ($positionof363 == 5) {
$arraynum = abs($countfrom14 - 70);
}

$lettertonumber = $layer3[$arraynum];
if ($lettertonumber == 'R') {
$r = 255;
}
if ($lettertonumber == 'N') {
$r = 0;
}
$x = 3;
echo "strip".$x.".setPixelColor($countfrom14, ".$r.", ".$g.", ".$b.");<br>";
$x = 2;

if ($positionof362 == 6) {
$arraynum = abs($countfrom14 - 84);
}
if ($positionof362 == 7) {
$arraynum = abs($countfrom14 - 98);
}
if ($positionof362 == 8) {
$arraynum = abs($countfrom14 - 112);
}
if ($positionof362 == 9) {
$arraynum = abs($countfrom14 - 126);
}
if ($positionof362 == 10) {
$arraynum = abs($countfrom14 - 140);
}

$lettertonumber = $layer2[$arraynum];
if ($lettertonumber == 'R') {
$r = 255;
}
if ($lettertonumber == 'N') {
$r = 0;
}
echo "strip".$x.".setPixelColor($countfrom14, ".$r.", ".$g.", ".$b.");<br>";
$x = 1;
if ($positionof36 == 11) {
$arraynum = abs($countfrom14 - 154);
}
if ($positionof36 == 12) {
$arraynum = abs($countfrom14 - 168);
}
if ($positionof36 == 13) {
$arraynum = abs($countfrom14 - 182);
}
if ($positionof36 == 14) {
$arraynum = abs($countfrom14 - 196);
}
if ($positionof36 == 15) {
$arraynum = abs($countfrom14 - 210);
}
$lettertonumber = $layer1[$arraynum];
if ($lettertonumber == 'R') {
$r = 255;
}
if ($lettertonumber == 'N') {
$r = 0;
}
echo "strip".$x.".setPixelColor($countfrom14, ".$r.", ".$g.", ".$b.");<br>";
$countfrom14 = $countfrom14 - 1;
} //end of countfrom14 loop
echo "strip".$x.".show(); <br>";
$x = 2;
echo "strip".$x.".show(); <br>";
$x = 3;
echo "strip".$x.".show(); <br>";
$x = 1;
echo "delay(".$del."); <br>";
$countfrom14 = 14;
$positionof36 = $positionof36 + 1;
$positionof362 = $positionof362 + 1;
$positionof363 = $positionof363 + 1;
$beforenextlayer = $beforenextlayer + 1;
}






$beforenextlayer = 15;

$positionof364 = 1;

while (($beforenextlayer >= 10) AND ($beforenextlayer <=15)) {

while ($countfrom14 > 0) {
if ($positionof364 == 1) {
$arraynum = abs($countfrom14 - 14);
}
if ($positionof364 == 2) {
$arraynum = abs($countfrom14 - 28);
}
if ($positionof364 == 3) {
$arraynum = abs($countfrom14 - 42);
}
if ($positionof364 == 4) {
$arraynum = abs($countfrom14 - 56);
}
if ($positionof364 == 5) {
$arraynum = abs($countfrom14 - 70);
}

$lettertonumber = $layer4[$arraynum];
if ($lettertonumber == 'R') {
$r = 255;
}
if ($lettertonumber == 'N') {
$r = 0;
}
$x = 4;
echo "strip".$x.".setPixelColor($countfrom14, ".$r.", ".$g.", ".$b.");<br>";
$x = 3;
if ($positionof363 == 1) {
$arraynum = abs($countfrom14 - 84);
}
if ($positionof363 == 2) {
$arraynum = abs($countfrom14 - 98);
}
if ($positionof363 == 3) {
$arraynum = abs($countfrom14 - 112);
}
if ($positionof363 == 4) {
$arraynum = abs($countfrom14 - 126);
}
if ($positionof363 == 5) {
$arraynum = abs($countfrom14 - 140);
}

$lettertonumber = $layer3[$arraynum];
if ($lettertonumber == 'R') {
$r = 255;
}
if ($lettertonumber == 'N') {
$r = 0;
}
$x = 3;
echo "strip".$x.".setPixelColor($countfrom14, ".$r.", ".$g.", ".$b.");<br>";
$x = 2;

if ($positionof362 == 6) {
$arraynum = abs($countfrom14 - 154);
}
if ($positionof362 == 7) {
$arraynum = abs($countfrom14 - 168);
}
if ($positionof362 == 8) {
$arraynum = abs($countfrom14 - 182);
}
if ($positionof362 == 9) {
$arraynum = abs($countfrom14 - 196);
}
if ($positionof362 == 10) {
$arraynum = abs($countfrom14 - 210);
}

$lettertonumber = $layer2[$arraynum];
if ($lettertonumber == 'R') {
$r = 255;
}
if ($lettertonumber == 'N') {
$r = 0;
}
echo "strip".$x.".setPixelColor($countfrom14, ".$r.", ".$g.", ".$b.");<br>";
$x = 1;
if ($positionof36 == 11) {
$arraynum = abs($countfrom14 - 224);
}
if ($positionof36 == 12) {
$arraynum = abs($countfrom14 - 238);
}
if ($positionof36 == 13) {
$arraynum = abs($countfrom14 - 252);
}
if ($positionof36 == 14) {
$arraynum = abs($countfrom14 - 266);
}
if ($positionof36 == 15) {
$arraynum = abs($countfrom14 - 280);
}
$lettertonumber = $layer1[$arraynum];
if ($lettertonumber == 'R') {
$r = 255;
}
if ($lettertonumber == 'N') {
$r = 0;
}
echo "strip".$x.".setPixelColor($countfrom14, ".$r.", ".$g.", ".$b.");<br>";
$countfrom14 = $countfrom14 - 1;
} //end of countfrom14 loop
echo "strip".$x.".show(); <br>";
$x = 2;
echo "strip".$x.".show(); <br>";
$x = 3;
echo "strip".$x.".show(); <br>";
$x = 4;
echo "strip".$x.".show(); <br>";
$x = 1;
echo "delay(".$del."); <br>";
$countfrom14 = 14;
$positionof36 = $positionof36 + 1;
$positionof362 = $positionof362 + 1;
$positionof363 = $positionof363 + 1;
$positionof364 = $positionof364 + 1;
$beforenextlayer = $beforenextlayer + 1;
}



?>


Inputs



On each page you get a view like this:



enter image description here



Each of these are check boxes with an individual ID that starts on the far left horizontal table and goes inward and then up to the next table and so on. There are 506 unique check boxes. When you hit Submit it takes those checked boxes and unchecked boxes and stores it in a string consisting of R for checked and N for not checked. In the end the string can be NNNRRRNNRNRNRNRRRRNN, etc. Now you do this for 10 different layers and ion a database you have columns layer1, layer2, layer3 etc. each with that string inside. Now in this code you see it breaks down the string for each layer and puts it in Arduino code.










share|improve this question
























  • Welcome to Code Review! Could you explain more specifically what this code accomplishes? What are the inputs? How do the inputs get translated to LED-controlling commands? We could do a better job of giving you advice if you actually explained your intentions rather than expecting us to deduce them by reverse-engineering your code.
    – 200_success
    Nov 7 at 18:20










  • My first thought is to use % modulus, but I didn't really pick though the code, anything that says I want to do something on the nth iteration, I say % modulus
    – ArtisticPhoenix
    Nov 8 at 19:31












  • Yeah % has nothing to do with anything here lol
    – Reese Houseknecht
    Nov 8 at 19:41















up vote
-1
down vote

favorite












For a website I'm writing, I am allowing users to check boxes which translate into LEDs to turn on for my 3D display.



The code shouldn't need much explaining but it's really killing me. You can see that after each 5 iterations of $beforenext it goes to a whole other loop which does a similar thing with a new input and some other number changes.



Perhaps I could devise a way to do just these 4 in a single loop; I would probably be able to extrapolate to 10.



<?php session_start();

include_once("connect.php");
$x = 1;
$uid = $_SESSION['uid'];
$sql = "SELECT * FROM code3d WHERE current_user_id = $uid";
$res = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($res);
$layer1 = $row['layer1'];
$layer2 = $row['layer2'];
$layer3 = $row['layer3'];
$layer4 = $row['layer4'];
$layer5 = $row['layer5'];
$layer6 = $row['layer6'];
$layer7 = $row['layer7'];
$layer8 = $row['layer8'];
$layer9 = $row['layer9'];
$layer10 = $row['layer10'];
$del = 1;
$g = 0;
$b = 0;
$x = 1;
$countfrom14 = 14;
$positionof36 = 1;
$beforenextlayer = 1;
while ($beforenextlayer <= 5) {
while ($countfrom14 > 0) {
// if ($beforenextlayer >= 5) {
//
// if ($positionof362 == 1) {
// $arraynum = abs($countfrom14 - 14);
// }
// if ($positionof362 == 2) {
// $arraynum = abs($countfrom14 - 28);
// }
// if ($positionof362 == 3) {
// $arraynum = abs($countfrom14 - 42);
// }
// if ($positionof362 == 4) {
// $arraynum = abs($countfrom14 - 56);
// }
// if ($positionof362 == 5) {
// $arraynum = abs($countfrom14 - 70);
// }
// $x = 2;
//}

if ($positionof36 == 1) {
$arraynum = abs($countfrom14 - 14);
}
if ($positionof36 == 2) {
$arraynum = abs($countfrom14 - 28);
}
if ($positionof36 == 3) {
$arraynum = abs($countfrom14 - 42);
}
if ($positionof36 == 4) {
$arraynum = abs($countfrom14 - 56);
}
if ($positionof36 == 5) {
$arraynum = abs($countfrom14 - 70);
}
$lettertonumber = $layer1[$arraynum];
if ($lettertonumber == 'R') {
$r = 255;
}
if ($lettertonumber == 'N') {
$r = 0;
}
echo "strip".$x.".setPixelColor($countfrom14, ".$r.", ".$g.", ".$b.");<br>";
$countfrom14 = $countfrom14 - 1;
} //end of countfrom14 loop

echo "strip".$x.".show(); <br>";
echo "delay(".$del."); <br>";
$countfrom14 = 14;
$positionof36 = $positionof36 + 1;
$beforenextlayer = $beforenextlayer + 1;
} // end of beforenextlayer loop




$beforenextlayer = 5;

$positionof362 = 1;

while (($beforenextlayer >= 5) AND ($beforenextlayer <=10)) {

while ($countfrom14 > 0) {
if ($positionof362 == 1) {
$arraynum = abs($countfrom14 - 14);
}
if ($positionof362 == 2) {
$arraynum = abs($countfrom14 - 28);
}
if ($positionof362 == 3) {
$arraynum = abs($countfrom14 - 42);
}
if ($positionof362 == 4) {
$arraynum = abs($countfrom14 - 56);
}
if ($positionof362 == 5) {
$arraynum = abs($countfrom14 - 70);
}
$x = 2;

$lettertonumber = $layer2[$arraynum];
if ($lettertonumber == 'R') {
$r = 255;
}
if ($lettertonumber == 'N') {
$r = 0;
}
echo "strip".$x.".setPixelColor($countfrom14, ".$r.", ".$g.", ".$b.");<br>";
$x = 1;
if ($positionof36 == 6) {
$arraynum = abs($countfrom14 - 84);
}
if ($positionof36 == 7) {
$arraynum = abs($countfrom14 - 98);
}
if ($positionof36 == 8) {
$arraynum = abs($countfrom14 - 112);
}
if ($positionof36 == 9) {
$arraynum = abs($countfrom14 - 126);
}
if ($positionof36 == 10) {
$arraynum = abs($countfrom14 - 140);
}
$lettertonumber = $layer1[$arraynum];
if ($lettertonumber == 'R') {
$r = 255;
}
if ($lettertonumber == 'N') {
$r = 0;
}
echo "strip".$x.".setPixelColor($countfrom14, ".$r.", ".$g.", ".$b.");<br>";
$countfrom14 = $countfrom14 - 1;
} //end of countfrom14 loop
echo "strip".$x.".show(); <br>";
$x = 2;
echo "strip".$x.".show(); <br>";
$x = 1;
echo "delay(".$del."); <br>";
$countfrom14 = 14;
$positionof36 = $positionof36 + 1;
$positionof362 = $positionof362 + 1;
$beforenextlayer = $beforenextlayer + 1;
}






$beforenextlayer = 10;

$positionof363 = 1;

while (($beforenextlayer >= 10) AND ($beforenextlayer <=15)) {

while ($countfrom14 > 0) {
if ($positionof363 == 1) {
$arraynum = abs($countfrom14 - 14);
}
if ($positionof363 == 2) {
$arraynum = abs($countfrom14 - 28);
}
if ($positionof363 == 3) {
$arraynum = abs($countfrom14 - 42);
}
if ($positionof363 == 4) {
$arraynum = abs($countfrom14 - 56);
}
if ($positionof363 == 5) {
$arraynum = abs($countfrom14 - 70);
}

$lettertonumber = $layer3[$arraynum];
if ($lettertonumber == 'R') {
$r = 255;
}
if ($lettertonumber == 'N') {
$r = 0;
}
$x = 3;
echo "strip".$x.".setPixelColor($countfrom14, ".$r.", ".$g.", ".$b.");<br>";
$x = 2;

if ($positionof362 == 6) {
$arraynum = abs($countfrom14 - 84);
}
if ($positionof362 == 7) {
$arraynum = abs($countfrom14 - 98);
}
if ($positionof362 == 8) {
$arraynum = abs($countfrom14 - 112);
}
if ($positionof362 == 9) {
$arraynum = abs($countfrom14 - 126);
}
if ($positionof362 == 10) {
$arraynum = abs($countfrom14 - 140);
}

$lettertonumber = $layer2[$arraynum];
if ($lettertonumber == 'R') {
$r = 255;
}
if ($lettertonumber == 'N') {
$r = 0;
}
echo "strip".$x.".setPixelColor($countfrom14, ".$r.", ".$g.", ".$b.");<br>";
$x = 1;
if ($positionof36 == 11) {
$arraynum = abs($countfrom14 - 154);
}
if ($positionof36 == 12) {
$arraynum = abs($countfrom14 - 168);
}
if ($positionof36 == 13) {
$arraynum = abs($countfrom14 - 182);
}
if ($positionof36 == 14) {
$arraynum = abs($countfrom14 - 196);
}
if ($positionof36 == 15) {
$arraynum = abs($countfrom14 - 210);
}
$lettertonumber = $layer1[$arraynum];
if ($lettertonumber == 'R') {
$r = 255;
}
if ($lettertonumber == 'N') {
$r = 0;
}
echo "strip".$x.".setPixelColor($countfrom14, ".$r.", ".$g.", ".$b.");<br>";
$countfrom14 = $countfrom14 - 1;
} //end of countfrom14 loop
echo "strip".$x.".show(); <br>";
$x = 2;
echo "strip".$x.".show(); <br>";
$x = 3;
echo "strip".$x.".show(); <br>";
$x = 1;
echo "delay(".$del."); <br>";
$countfrom14 = 14;
$positionof36 = $positionof36 + 1;
$positionof362 = $positionof362 + 1;
$positionof363 = $positionof363 + 1;
$beforenextlayer = $beforenextlayer + 1;
}






$beforenextlayer = 15;

$positionof364 = 1;

while (($beforenextlayer >= 10) AND ($beforenextlayer <=15)) {

while ($countfrom14 > 0) {
if ($positionof364 == 1) {
$arraynum = abs($countfrom14 - 14);
}
if ($positionof364 == 2) {
$arraynum = abs($countfrom14 - 28);
}
if ($positionof364 == 3) {
$arraynum = abs($countfrom14 - 42);
}
if ($positionof364 == 4) {
$arraynum = abs($countfrom14 - 56);
}
if ($positionof364 == 5) {
$arraynum = abs($countfrom14 - 70);
}

$lettertonumber = $layer4[$arraynum];
if ($lettertonumber == 'R') {
$r = 255;
}
if ($lettertonumber == 'N') {
$r = 0;
}
$x = 4;
echo "strip".$x.".setPixelColor($countfrom14, ".$r.", ".$g.", ".$b.");<br>";
$x = 3;
if ($positionof363 == 1) {
$arraynum = abs($countfrom14 - 84);
}
if ($positionof363 == 2) {
$arraynum = abs($countfrom14 - 98);
}
if ($positionof363 == 3) {
$arraynum = abs($countfrom14 - 112);
}
if ($positionof363 == 4) {
$arraynum = abs($countfrom14 - 126);
}
if ($positionof363 == 5) {
$arraynum = abs($countfrom14 - 140);
}

$lettertonumber = $layer3[$arraynum];
if ($lettertonumber == 'R') {
$r = 255;
}
if ($lettertonumber == 'N') {
$r = 0;
}
$x = 3;
echo "strip".$x.".setPixelColor($countfrom14, ".$r.", ".$g.", ".$b.");<br>";
$x = 2;

if ($positionof362 == 6) {
$arraynum = abs($countfrom14 - 154);
}
if ($positionof362 == 7) {
$arraynum = abs($countfrom14 - 168);
}
if ($positionof362 == 8) {
$arraynum = abs($countfrom14 - 182);
}
if ($positionof362 == 9) {
$arraynum = abs($countfrom14 - 196);
}
if ($positionof362 == 10) {
$arraynum = abs($countfrom14 - 210);
}

$lettertonumber = $layer2[$arraynum];
if ($lettertonumber == 'R') {
$r = 255;
}
if ($lettertonumber == 'N') {
$r = 0;
}
echo "strip".$x.".setPixelColor($countfrom14, ".$r.", ".$g.", ".$b.");<br>";
$x = 1;
if ($positionof36 == 11) {
$arraynum = abs($countfrom14 - 224);
}
if ($positionof36 == 12) {
$arraynum = abs($countfrom14 - 238);
}
if ($positionof36 == 13) {
$arraynum = abs($countfrom14 - 252);
}
if ($positionof36 == 14) {
$arraynum = abs($countfrom14 - 266);
}
if ($positionof36 == 15) {
$arraynum = abs($countfrom14 - 280);
}
$lettertonumber = $layer1[$arraynum];
if ($lettertonumber == 'R') {
$r = 255;
}
if ($lettertonumber == 'N') {
$r = 0;
}
echo "strip".$x.".setPixelColor($countfrom14, ".$r.", ".$g.", ".$b.");<br>";
$countfrom14 = $countfrom14 - 1;
} //end of countfrom14 loop
echo "strip".$x.".show(); <br>";
$x = 2;
echo "strip".$x.".show(); <br>";
$x = 3;
echo "strip".$x.".show(); <br>";
$x = 4;
echo "strip".$x.".show(); <br>";
$x = 1;
echo "delay(".$del."); <br>";
$countfrom14 = 14;
$positionof36 = $positionof36 + 1;
$positionof362 = $positionof362 + 1;
$positionof363 = $positionof363 + 1;
$positionof364 = $positionof364 + 1;
$beforenextlayer = $beforenextlayer + 1;
}



?>


Inputs



On each page you get a view like this:



enter image description here



Each of these are check boxes with an individual ID that starts on the far left horizontal table and goes inward and then up to the next table and so on. There are 506 unique check boxes. When you hit Submit it takes those checked boxes and unchecked boxes and stores it in a string consisting of R for checked and N for not checked. In the end the string can be NNNRRRNNRNRNRNRRRRNN, etc. Now you do this for 10 different layers and ion a database you have columns layer1, layer2, layer3 etc. each with that string inside. Now in this code you see it breaks down the string for each layer and puts it in Arduino code.










share|improve this question
























  • Welcome to Code Review! Could you explain more specifically what this code accomplishes? What are the inputs? How do the inputs get translated to LED-controlling commands? We could do a better job of giving you advice if you actually explained your intentions rather than expecting us to deduce them by reverse-engineering your code.
    – 200_success
    Nov 7 at 18:20










  • My first thought is to use % modulus, but I didn't really pick though the code, anything that says I want to do something on the nth iteration, I say % modulus
    – ArtisticPhoenix
    Nov 8 at 19:31












  • Yeah % has nothing to do with anything here lol
    – Reese Houseknecht
    Nov 8 at 19:41













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











For a website I'm writing, I am allowing users to check boxes which translate into LEDs to turn on for my 3D display.



The code shouldn't need much explaining but it's really killing me. You can see that after each 5 iterations of $beforenext it goes to a whole other loop which does a similar thing with a new input and some other number changes.



Perhaps I could devise a way to do just these 4 in a single loop; I would probably be able to extrapolate to 10.



<?php session_start();

include_once("connect.php");
$x = 1;
$uid = $_SESSION['uid'];
$sql = "SELECT * FROM code3d WHERE current_user_id = $uid";
$res = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($res);
$layer1 = $row['layer1'];
$layer2 = $row['layer2'];
$layer3 = $row['layer3'];
$layer4 = $row['layer4'];
$layer5 = $row['layer5'];
$layer6 = $row['layer6'];
$layer7 = $row['layer7'];
$layer8 = $row['layer8'];
$layer9 = $row['layer9'];
$layer10 = $row['layer10'];
$del = 1;
$g = 0;
$b = 0;
$x = 1;
$countfrom14 = 14;
$positionof36 = 1;
$beforenextlayer = 1;
while ($beforenextlayer <= 5) {
while ($countfrom14 > 0) {
// if ($beforenextlayer >= 5) {
//
// if ($positionof362 == 1) {
// $arraynum = abs($countfrom14 - 14);
// }
// if ($positionof362 == 2) {
// $arraynum = abs($countfrom14 - 28);
// }
// if ($positionof362 == 3) {
// $arraynum = abs($countfrom14 - 42);
// }
// if ($positionof362 == 4) {
// $arraynum = abs($countfrom14 - 56);
// }
// if ($positionof362 == 5) {
// $arraynum = abs($countfrom14 - 70);
// }
// $x = 2;
//}

if ($positionof36 == 1) {
$arraynum = abs($countfrom14 - 14);
}
if ($positionof36 == 2) {
$arraynum = abs($countfrom14 - 28);
}
if ($positionof36 == 3) {
$arraynum = abs($countfrom14 - 42);
}
if ($positionof36 == 4) {
$arraynum = abs($countfrom14 - 56);
}
if ($positionof36 == 5) {
$arraynum = abs($countfrom14 - 70);
}
$lettertonumber = $layer1[$arraynum];
if ($lettertonumber == 'R') {
$r = 255;
}
if ($lettertonumber == 'N') {
$r = 0;
}
echo "strip".$x.".setPixelColor($countfrom14, ".$r.", ".$g.", ".$b.");<br>";
$countfrom14 = $countfrom14 - 1;
} //end of countfrom14 loop

echo "strip".$x.".show(); <br>";
echo "delay(".$del."); <br>";
$countfrom14 = 14;
$positionof36 = $positionof36 + 1;
$beforenextlayer = $beforenextlayer + 1;
} // end of beforenextlayer loop




$beforenextlayer = 5;

$positionof362 = 1;

while (($beforenextlayer >= 5) AND ($beforenextlayer <=10)) {

while ($countfrom14 > 0) {
if ($positionof362 == 1) {
$arraynum = abs($countfrom14 - 14);
}
if ($positionof362 == 2) {
$arraynum = abs($countfrom14 - 28);
}
if ($positionof362 == 3) {
$arraynum = abs($countfrom14 - 42);
}
if ($positionof362 == 4) {
$arraynum = abs($countfrom14 - 56);
}
if ($positionof362 == 5) {
$arraynum = abs($countfrom14 - 70);
}
$x = 2;

$lettertonumber = $layer2[$arraynum];
if ($lettertonumber == 'R') {
$r = 255;
}
if ($lettertonumber == 'N') {
$r = 0;
}
echo "strip".$x.".setPixelColor($countfrom14, ".$r.", ".$g.", ".$b.");<br>";
$x = 1;
if ($positionof36 == 6) {
$arraynum = abs($countfrom14 - 84);
}
if ($positionof36 == 7) {
$arraynum = abs($countfrom14 - 98);
}
if ($positionof36 == 8) {
$arraynum = abs($countfrom14 - 112);
}
if ($positionof36 == 9) {
$arraynum = abs($countfrom14 - 126);
}
if ($positionof36 == 10) {
$arraynum = abs($countfrom14 - 140);
}
$lettertonumber = $layer1[$arraynum];
if ($lettertonumber == 'R') {
$r = 255;
}
if ($lettertonumber == 'N') {
$r = 0;
}
echo "strip".$x.".setPixelColor($countfrom14, ".$r.", ".$g.", ".$b.");<br>";
$countfrom14 = $countfrom14 - 1;
} //end of countfrom14 loop
echo "strip".$x.".show(); <br>";
$x = 2;
echo "strip".$x.".show(); <br>";
$x = 1;
echo "delay(".$del."); <br>";
$countfrom14 = 14;
$positionof36 = $positionof36 + 1;
$positionof362 = $positionof362 + 1;
$beforenextlayer = $beforenextlayer + 1;
}






$beforenextlayer = 10;

$positionof363 = 1;

while (($beforenextlayer >= 10) AND ($beforenextlayer <=15)) {

while ($countfrom14 > 0) {
if ($positionof363 == 1) {
$arraynum = abs($countfrom14 - 14);
}
if ($positionof363 == 2) {
$arraynum = abs($countfrom14 - 28);
}
if ($positionof363 == 3) {
$arraynum = abs($countfrom14 - 42);
}
if ($positionof363 == 4) {
$arraynum = abs($countfrom14 - 56);
}
if ($positionof363 == 5) {
$arraynum = abs($countfrom14 - 70);
}

$lettertonumber = $layer3[$arraynum];
if ($lettertonumber == 'R') {
$r = 255;
}
if ($lettertonumber == 'N') {
$r = 0;
}
$x = 3;
echo "strip".$x.".setPixelColor($countfrom14, ".$r.", ".$g.", ".$b.");<br>";
$x = 2;

if ($positionof362 == 6) {
$arraynum = abs($countfrom14 - 84);
}
if ($positionof362 == 7) {
$arraynum = abs($countfrom14 - 98);
}
if ($positionof362 == 8) {
$arraynum = abs($countfrom14 - 112);
}
if ($positionof362 == 9) {
$arraynum = abs($countfrom14 - 126);
}
if ($positionof362 == 10) {
$arraynum = abs($countfrom14 - 140);
}

$lettertonumber = $layer2[$arraynum];
if ($lettertonumber == 'R') {
$r = 255;
}
if ($lettertonumber == 'N') {
$r = 0;
}
echo "strip".$x.".setPixelColor($countfrom14, ".$r.", ".$g.", ".$b.");<br>";
$x = 1;
if ($positionof36 == 11) {
$arraynum = abs($countfrom14 - 154);
}
if ($positionof36 == 12) {
$arraynum = abs($countfrom14 - 168);
}
if ($positionof36 == 13) {
$arraynum = abs($countfrom14 - 182);
}
if ($positionof36 == 14) {
$arraynum = abs($countfrom14 - 196);
}
if ($positionof36 == 15) {
$arraynum = abs($countfrom14 - 210);
}
$lettertonumber = $layer1[$arraynum];
if ($lettertonumber == 'R') {
$r = 255;
}
if ($lettertonumber == 'N') {
$r = 0;
}
echo "strip".$x.".setPixelColor($countfrom14, ".$r.", ".$g.", ".$b.");<br>";
$countfrom14 = $countfrom14 - 1;
} //end of countfrom14 loop
echo "strip".$x.".show(); <br>";
$x = 2;
echo "strip".$x.".show(); <br>";
$x = 3;
echo "strip".$x.".show(); <br>";
$x = 1;
echo "delay(".$del."); <br>";
$countfrom14 = 14;
$positionof36 = $positionof36 + 1;
$positionof362 = $positionof362 + 1;
$positionof363 = $positionof363 + 1;
$beforenextlayer = $beforenextlayer + 1;
}






$beforenextlayer = 15;

$positionof364 = 1;

while (($beforenextlayer >= 10) AND ($beforenextlayer <=15)) {

while ($countfrom14 > 0) {
if ($positionof364 == 1) {
$arraynum = abs($countfrom14 - 14);
}
if ($positionof364 == 2) {
$arraynum = abs($countfrom14 - 28);
}
if ($positionof364 == 3) {
$arraynum = abs($countfrom14 - 42);
}
if ($positionof364 == 4) {
$arraynum = abs($countfrom14 - 56);
}
if ($positionof364 == 5) {
$arraynum = abs($countfrom14 - 70);
}

$lettertonumber = $layer4[$arraynum];
if ($lettertonumber == 'R') {
$r = 255;
}
if ($lettertonumber == 'N') {
$r = 0;
}
$x = 4;
echo "strip".$x.".setPixelColor($countfrom14, ".$r.", ".$g.", ".$b.");<br>";
$x = 3;
if ($positionof363 == 1) {
$arraynum = abs($countfrom14 - 84);
}
if ($positionof363 == 2) {
$arraynum = abs($countfrom14 - 98);
}
if ($positionof363 == 3) {
$arraynum = abs($countfrom14 - 112);
}
if ($positionof363 == 4) {
$arraynum = abs($countfrom14 - 126);
}
if ($positionof363 == 5) {
$arraynum = abs($countfrom14 - 140);
}

$lettertonumber = $layer3[$arraynum];
if ($lettertonumber == 'R') {
$r = 255;
}
if ($lettertonumber == 'N') {
$r = 0;
}
$x = 3;
echo "strip".$x.".setPixelColor($countfrom14, ".$r.", ".$g.", ".$b.");<br>";
$x = 2;

if ($positionof362 == 6) {
$arraynum = abs($countfrom14 - 154);
}
if ($positionof362 == 7) {
$arraynum = abs($countfrom14 - 168);
}
if ($positionof362 == 8) {
$arraynum = abs($countfrom14 - 182);
}
if ($positionof362 == 9) {
$arraynum = abs($countfrom14 - 196);
}
if ($positionof362 == 10) {
$arraynum = abs($countfrom14 - 210);
}

$lettertonumber = $layer2[$arraynum];
if ($lettertonumber == 'R') {
$r = 255;
}
if ($lettertonumber == 'N') {
$r = 0;
}
echo "strip".$x.".setPixelColor($countfrom14, ".$r.", ".$g.", ".$b.");<br>";
$x = 1;
if ($positionof36 == 11) {
$arraynum = abs($countfrom14 - 224);
}
if ($positionof36 == 12) {
$arraynum = abs($countfrom14 - 238);
}
if ($positionof36 == 13) {
$arraynum = abs($countfrom14 - 252);
}
if ($positionof36 == 14) {
$arraynum = abs($countfrom14 - 266);
}
if ($positionof36 == 15) {
$arraynum = abs($countfrom14 - 280);
}
$lettertonumber = $layer1[$arraynum];
if ($lettertonumber == 'R') {
$r = 255;
}
if ($lettertonumber == 'N') {
$r = 0;
}
echo "strip".$x.".setPixelColor($countfrom14, ".$r.", ".$g.", ".$b.");<br>";
$countfrom14 = $countfrom14 - 1;
} //end of countfrom14 loop
echo "strip".$x.".show(); <br>";
$x = 2;
echo "strip".$x.".show(); <br>";
$x = 3;
echo "strip".$x.".show(); <br>";
$x = 4;
echo "strip".$x.".show(); <br>";
$x = 1;
echo "delay(".$del."); <br>";
$countfrom14 = 14;
$positionof36 = $positionof36 + 1;
$positionof362 = $positionof362 + 1;
$positionof363 = $positionof363 + 1;
$positionof364 = $positionof364 + 1;
$beforenextlayer = $beforenextlayer + 1;
}



?>


Inputs



On each page you get a view like this:



enter image description here



Each of these are check boxes with an individual ID that starts on the far left horizontal table and goes inward and then up to the next table and so on. There are 506 unique check boxes. When you hit Submit it takes those checked boxes and unchecked boxes and stores it in a string consisting of R for checked and N for not checked. In the end the string can be NNNRRRNNRNRNRNRRRRNN, etc. Now you do this for 10 different layers and ion a database you have columns layer1, layer2, layer3 etc. each with that string inside. Now in this code you see it breaks down the string for each layer and puts it in Arduino code.










share|improve this question















For a website I'm writing, I am allowing users to check boxes which translate into LEDs to turn on for my 3D display.



The code shouldn't need much explaining but it's really killing me. You can see that after each 5 iterations of $beforenext it goes to a whole other loop which does a similar thing with a new input and some other number changes.



Perhaps I could devise a way to do just these 4 in a single loop; I would probably be able to extrapolate to 10.



<?php session_start();

include_once("connect.php");
$x = 1;
$uid = $_SESSION['uid'];
$sql = "SELECT * FROM code3d WHERE current_user_id = $uid";
$res = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($res);
$layer1 = $row['layer1'];
$layer2 = $row['layer2'];
$layer3 = $row['layer3'];
$layer4 = $row['layer4'];
$layer5 = $row['layer5'];
$layer6 = $row['layer6'];
$layer7 = $row['layer7'];
$layer8 = $row['layer8'];
$layer9 = $row['layer9'];
$layer10 = $row['layer10'];
$del = 1;
$g = 0;
$b = 0;
$x = 1;
$countfrom14 = 14;
$positionof36 = 1;
$beforenextlayer = 1;
while ($beforenextlayer <= 5) {
while ($countfrom14 > 0) {
// if ($beforenextlayer >= 5) {
//
// if ($positionof362 == 1) {
// $arraynum = abs($countfrom14 - 14);
// }
// if ($positionof362 == 2) {
// $arraynum = abs($countfrom14 - 28);
// }
// if ($positionof362 == 3) {
// $arraynum = abs($countfrom14 - 42);
// }
// if ($positionof362 == 4) {
// $arraynum = abs($countfrom14 - 56);
// }
// if ($positionof362 == 5) {
// $arraynum = abs($countfrom14 - 70);
// }
// $x = 2;
//}

if ($positionof36 == 1) {
$arraynum = abs($countfrom14 - 14);
}
if ($positionof36 == 2) {
$arraynum = abs($countfrom14 - 28);
}
if ($positionof36 == 3) {
$arraynum = abs($countfrom14 - 42);
}
if ($positionof36 == 4) {
$arraynum = abs($countfrom14 - 56);
}
if ($positionof36 == 5) {
$arraynum = abs($countfrom14 - 70);
}
$lettertonumber = $layer1[$arraynum];
if ($lettertonumber == 'R') {
$r = 255;
}
if ($lettertonumber == 'N') {
$r = 0;
}
echo "strip".$x.".setPixelColor($countfrom14, ".$r.", ".$g.", ".$b.");<br>";
$countfrom14 = $countfrom14 - 1;
} //end of countfrom14 loop

echo "strip".$x.".show(); <br>";
echo "delay(".$del."); <br>";
$countfrom14 = 14;
$positionof36 = $positionof36 + 1;
$beforenextlayer = $beforenextlayer + 1;
} // end of beforenextlayer loop




$beforenextlayer = 5;

$positionof362 = 1;

while (($beforenextlayer >= 5) AND ($beforenextlayer <=10)) {

while ($countfrom14 > 0) {
if ($positionof362 == 1) {
$arraynum = abs($countfrom14 - 14);
}
if ($positionof362 == 2) {
$arraynum = abs($countfrom14 - 28);
}
if ($positionof362 == 3) {
$arraynum = abs($countfrom14 - 42);
}
if ($positionof362 == 4) {
$arraynum = abs($countfrom14 - 56);
}
if ($positionof362 == 5) {
$arraynum = abs($countfrom14 - 70);
}
$x = 2;

$lettertonumber = $layer2[$arraynum];
if ($lettertonumber == 'R') {
$r = 255;
}
if ($lettertonumber == 'N') {
$r = 0;
}
echo "strip".$x.".setPixelColor($countfrom14, ".$r.", ".$g.", ".$b.");<br>";
$x = 1;
if ($positionof36 == 6) {
$arraynum = abs($countfrom14 - 84);
}
if ($positionof36 == 7) {
$arraynum = abs($countfrom14 - 98);
}
if ($positionof36 == 8) {
$arraynum = abs($countfrom14 - 112);
}
if ($positionof36 == 9) {
$arraynum = abs($countfrom14 - 126);
}
if ($positionof36 == 10) {
$arraynum = abs($countfrom14 - 140);
}
$lettertonumber = $layer1[$arraynum];
if ($lettertonumber == 'R') {
$r = 255;
}
if ($lettertonumber == 'N') {
$r = 0;
}
echo "strip".$x.".setPixelColor($countfrom14, ".$r.", ".$g.", ".$b.");<br>";
$countfrom14 = $countfrom14 - 1;
} //end of countfrom14 loop
echo "strip".$x.".show(); <br>";
$x = 2;
echo "strip".$x.".show(); <br>";
$x = 1;
echo "delay(".$del."); <br>";
$countfrom14 = 14;
$positionof36 = $positionof36 + 1;
$positionof362 = $positionof362 + 1;
$beforenextlayer = $beforenextlayer + 1;
}






$beforenextlayer = 10;

$positionof363 = 1;

while (($beforenextlayer >= 10) AND ($beforenextlayer <=15)) {

while ($countfrom14 > 0) {
if ($positionof363 == 1) {
$arraynum = abs($countfrom14 - 14);
}
if ($positionof363 == 2) {
$arraynum = abs($countfrom14 - 28);
}
if ($positionof363 == 3) {
$arraynum = abs($countfrom14 - 42);
}
if ($positionof363 == 4) {
$arraynum = abs($countfrom14 - 56);
}
if ($positionof363 == 5) {
$arraynum = abs($countfrom14 - 70);
}

$lettertonumber = $layer3[$arraynum];
if ($lettertonumber == 'R') {
$r = 255;
}
if ($lettertonumber == 'N') {
$r = 0;
}
$x = 3;
echo "strip".$x.".setPixelColor($countfrom14, ".$r.", ".$g.", ".$b.");<br>";
$x = 2;

if ($positionof362 == 6) {
$arraynum = abs($countfrom14 - 84);
}
if ($positionof362 == 7) {
$arraynum = abs($countfrom14 - 98);
}
if ($positionof362 == 8) {
$arraynum = abs($countfrom14 - 112);
}
if ($positionof362 == 9) {
$arraynum = abs($countfrom14 - 126);
}
if ($positionof362 == 10) {
$arraynum = abs($countfrom14 - 140);
}

$lettertonumber = $layer2[$arraynum];
if ($lettertonumber == 'R') {
$r = 255;
}
if ($lettertonumber == 'N') {
$r = 0;
}
echo "strip".$x.".setPixelColor($countfrom14, ".$r.", ".$g.", ".$b.");<br>";
$x = 1;
if ($positionof36 == 11) {
$arraynum = abs($countfrom14 - 154);
}
if ($positionof36 == 12) {
$arraynum = abs($countfrom14 - 168);
}
if ($positionof36 == 13) {
$arraynum = abs($countfrom14 - 182);
}
if ($positionof36 == 14) {
$arraynum = abs($countfrom14 - 196);
}
if ($positionof36 == 15) {
$arraynum = abs($countfrom14 - 210);
}
$lettertonumber = $layer1[$arraynum];
if ($lettertonumber == 'R') {
$r = 255;
}
if ($lettertonumber == 'N') {
$r = 0;
}
echo "strip".$x.".setPixelColor($countfrom14, ".$r.", ".$g.", ".$b.");<br>";
$countfrom14 = $countfrom14 - 1;
} //end of countfrom14 loop
echo "strip".$x.".show(); <br>";
$x = 2;
echo "strip".$x.".show(); <br>";
$x = 3;
echo "strip".$x.".show(); <br>";
$x = 1;
echo "delay(".$del."); <br>";
$countfrom14 = 14;
$positionof36 = $positionof36 + 1;
$positionof362 = $positionof362 + 1;
$positionof363 = $positionof363 + 1;
$beforenextlayer = $beforenextlayer + 1;
}






$beforenextlayer = 15;

$positionof364 = 1;

while (($beforenextlayer >= 10) AND ($beforenextlayer <=15)) {

while ($countfrom14 > 0) {
if ($positionof364 == 1) {
$arraynum = abs($countfrom14 - 14);
}
if ($positionof364 == 2) {
$arraynum = abs($countfrom14 - 28);
}
if ($positionof364 == 3) {
$arraynum = abs($countfrom14 - 42);
}
if ($positionof364 == 4) {
$arraynum = abs($countfrom14 - 56);
}
if ($positionof364 == 5) {
$arraynum = abs($countfrom14 - 70);
}

$lettertonumber = $layer4[$arraynum];
if ($lettertonumber == 'R') {
$r = 255;
}
if ($lettertonumber == 'N') {
$r = 0;
}
$x = 4;
echo "strip".$x.".setPixelColor($countfrom14, ".$r.", ".$g.", ".$b.");<br>";
$x = 3;
if ($positionof363 == 1) {
$arraynum = abs($countfrom14 - 84);
}
if ($positionof363 == 2) {
$arraynum = abs($countfrom14 - 98);
}
if ($positionof363 == 3) {
$arraynum = abs($countfrom14 - 112);
}
if ($positionof363 == 4) {
$arraynum = abs($countfrom14 - 126);
}
if ($positionof363 == 5) {
$arraynum = abs($countfrom14 - 140);
}

$lettertonumber = $layer3[$arraynum];
if ($lettertonumber == 'R') {
$r = 255;
}
if ($lettertonumber == 'N') {
$r = 0;
}
$x = 3;
echo "strip".$x.".setPixelColor($countfrom14, ".$r.", ".$g.", ".$b.");<br>";
$x = 2;

if ($positionof362 == 6) {
$arraynum = abs($countfrom14 - 154);
}
if ($positionof362 == 7) {
$arraynum = abs($countfrom14 - 168);
}
if ($positionof362 == 8) {
$arraynum = abs($countfrom14 - 182);
}
if ($positionof362 == 9) {
$arraynum = abs($countfrom14 - 196);
}
if ($positionof362 == 10) {
$arraynum = abs($countfrom14 - 210);
}

$lettertonumber = $layer2[$arraynum];
if ($lettertonumber == 'R') {
$r = 255;
}
if ($lettertonumber == 'N') {
$r = 0;
}
echo "strip".$x.".setPixelColor($countfrom14, ".$r.", ".$g.", ".$b.");<br>";
$x = 1;
if ($positionof36 == 11) {
$arraynum = abs($countfrom14 - 224);
}
if ($positionof36 == 12) {
$arraynum = abs($countfrom14 - 238);
}
if ($positionof36 == 13) {
$arraynum = abs($countfrom14 - 252);
}
if ($positionof36 == 14) {
$arraynum = abs($countfrom14 - 266);
}
if ($positionof36 == 15) {
$arraynum = abs($countfrom14 - 280);
}
$lettertonumber = $layer1[$arraynum];
if ($lettertonumber == 'R') {
$r = 255;
}
if ($lettertonumber == 'N') {
$r = 0;
}
echo "strip".$x.".setPixelColor($countfrom14, ".$r.", ".$g.", ".$b.");<br>";
$countfrom14 = $countfrom14 - 1;
} //end of countfrom14 loop
echo "strip".$x.".show(); <br>";
$x = 2;
echo "strip".$x.".show(); <br>";
$x = 3;
echo "strip".$x.".show(); <br>";
$x = 4;
echo "strip".$x.".show(); <br>";
$x = 1;
echo "delay(".$del."); <br>";
$countfrom14 = 14;
$positionof36 = $positionof36 + 1;
$positionof362 = $positionof362 + 1;
$positionof363 = $positionof363 + 1;
$positionof364 = $positionof364 + 1;
$beforenextlayer = $beforenextlayer + 1;
}



?>


Inputs



On each page you get a view like this:



enter image description here



Each of these are check boxes with an individual ID that starts on the far left horizontal table and goes inward and then up to the next table and so on. There are 506 unique check boxes. When you hit Submit it takes those checked boxes and unchecked boxes and stores it in a string consisting of R for checked and N for not checked. In the end the string can be NNNRRRNNRNRNRNRRRRNN, etc. Now you do this for 10 different layers and ion a database you have columns layer1, layer2, layer3 etc. each with that string inside. Now in this code you see it breaks down the string for each layer and puts it in Arduino code.







php arduino






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 26 mins ago









Jamal

30.2k11115226




30.2k11115226










asked Nov 7 at 18:12









Reese Houseknecht

12




12












  • Welcome to Code Review! Could you explain more specifically what this code accomplishes? What are the inputs? How do the inputs get translated to LED-controlling commands? We could do a better job of giving you advice if you actually explained your intentions rather than expecting us to deduce them by reverse-engineering your code.
    – 200_success
    Nov 7 at 18:20










  • My first thought is to use % modulus, but I didn't really pick though the code, anything that says I want to do something on the nth iteration, I say % modulus
    – ArtisticPhoenix
    Nov 8 at 19:31












  • Yeah % has nothing to do with anything here lol
    – Reese Houseknecht
    Nov 8 at 19:41


















  • Welcome to Code Review! Could you explain more specifically what this code accomplishes? What are the inputs? How do the inputs get translated to LED-controlling commands? We could do a better job of giving you advice if you actually explained your intentions rather than expecting us to deduce them by reverse-engineering your code.
    – 200_success
    Nov 7 at 18:20










  • My first thought is to use % modulus, but I didn't really pick though the code, anything that says I want to do something on the nth iteration, I say % modulus
    – ArtisticPhoenix
    Nov 8 at 19:31












  • Yeah % has nothing to do with anything here lol
    – Reese Houseknecht
    Nov 8 at 19:41
















Welcome to Code Review! Could you explain more specifically what this code accomplishes? What are the inputs? How do the inputs get translated to LED-controlling commands? We could do a better job of giving you advice if you actually explained your intentions rather than expecting us to deduce them by reverse-engineering your code.
– 200_success
Nov 7 at 18:20




Welcome to Code Review! Could you explain more specifically what this code accomplishes? What are the inputs? How do the inputs get translated to LED-controlling commands? We could do a better job of giving you advice if you actually explained your intentions rather than expecting us to deduce them by reverse-engineering your code.
– 200_success
Nov 7 at 18:20












My first thought is to use % modulus, but I didn't really pick though the code, anything that says I want to do something on the nth iteration, I say % modulus
– ArtisticPhoenix
Nov 8 at 19:31






My first thought is to use % modulus, but I didn't really pick though the code, anything that says I want to do something on the nth iteration, I say % modulus
– ArtisticPhoenix
Nov 8 at 19:31














Yeah % has nothing to do with anything here lol
– Reese Houseknecht
Nov 8 at 19:41




Yeah % has nothing to do with anything here lol
– Reese Houseknecht
Nov 8 at 19:41















active

oldest

votes











Your Answer





StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");

StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "196"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f207163%2fallowing-users-to-turn-on-leds-for-a-3d-display%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Code Review Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f207163%2fallowing-users-to-turn-on-leds-for-a-3d-display%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

TypeError: fit_transform() missing 1 required positional argument: 'X'