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:
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
add a comment |
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:
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
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
add a comment |
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:
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
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:
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
php arduino
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
add a comment |
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
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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