im at about 1000 lines of code but my static memory is already at 67%. Im wondering if i change all of my char arrays into global variables instead of sending them through the functions will save more memory. ill try to remove any code that isn't relevant.
#include <Stepper.h>
#include "rotateFace.h"
#include "rotateOutside.h"
// initialize the stepper library on pins 8 through 11:
//the 100 is the steps per revoltuion change it to get the best speed possible
Stepper whiteStepper(100, 8, 9, 10, 11);
void setup() {
Serial.begin(9600);
}
void loop() {
//Setting up the white face
Serial.println(F("With the white side towards you and the red end facing up enter the colors of each square by typing\nfor example 'wrbgwybog'."));
char white[10];
String temp = "";
while (Serial.available() == 0) {}
temp = Serial.readString();
temp.toCharArray(white, 10); //changes from a string to a char array
temp.remove(0, 10);
//Setting up the Blue face
Serial.println(F("With the Blue side towards you and the white end facing up enter the colors of each square by typing"));
while (Serial.available() == 0) {}
temp = Serial.readString();
char blue[10];
temp.toCharArray(blue, 10);
temp.remove(0, 10);
// this is repeated for orange[],green[], red[], and yellow[]
//for the rotate() function add the direction as cw or cc, color for ex 'white' then all the arrays in order
while (solved == false) {
if (white[1] != 'w' || red[1] != 'r') { // if the white red piece is not in the white red spot
if (white[3] == 'w' && blue[1] == 'r') { // if the white red piece is in the white 3 spot
rotate("cw", "blue", white, blue, orange, green, red, yellow);
rotate("cw", "blue", white, blue, orange, green, red, yellow);
rotate("cc", "yellow", white, blue, orange, green, red, yellow);
rotate("cw", "red", white, blue, orange, green, red, yellow);
rotate("cw", "red", white, blue, orange, green, red, yellow);
}
else if (white[5] == 'w' && green[1] == 'r') { // if white red piece is in the white 5 spot
rotate("cw", "green", white, blue, orange, green, red, yellow);
rotate("cw", "green", white, blue, orange, green, red, yellow);
rotate("cw", "yellow", white, blue, orange, green, red, yellow);
rotate("cw", "red", white, blue, orange, green, red, yellow);
rotate("cw", "red", white, blue, orange, green, red, yellow);
}
else if (white[7] == 'w' && orange[1] == 'r') { //if white red piece is in the white 7 spot
rotate("cw", "orange", white, blue, orange, green, red, yellow);
rotate("cw", "orange", white, blue, orange, green, red, yellow);
rotate("cw", "yellow", white, blue, orange, green, red, yellow);
rotate("cw", "yellow", white, blue, orange, green, red, yellow);
rotate("cw", "red", white, blue, orange, green, red, yellow);
rotate("cw", "red", white, blue, orange, green, red, yellow);
}
else if (white[1] == 'r' && red[1] == 'w') { // if white red piece is in red 1 spot
rotate("cw", "blue", white, blue, orange, green, red, yellow);
rotate("cw", "red", white, blue, orange, green, red, yellow);
rotate("cc", "blue", white, blue, orange, green, red, yellow);
rotate("cc", "yellow", white, blue, orange, green, red, yellow);
rotate("cw", "red", white, blue, orange, green, red, yellow);
rotate("cw", "red", white, blue, orange, green, red, yellow);
}
else if (green[5] == 'r' && red[3] == 'w') { // if white red piece is in red 3 spot
rotate("cw", "red", white, blue, orange, green, red, yellow);
rotate("cw", "blue", white, blue, orange, green, red, yellow);
rotate("cw", "red", white, blue, orange, green, red, yellow);
rotate("cc", "blue", white, blue, orange, green, red, yellow);
rotate("cc", "yellow", white, blue, orange, green, red, yellow);
rotate("cw", "red", white, blue, orange, green, red, yellow);
rotate("cw", "red", white, blue, orange, green, red, yellow);
}
else if (blue[3] == 'r' && red[5] == 'w') { // if white red piece is in red 5 spot
rotate("cc", "red", white, blue, orange, green, red, yellow);
rotate("cw", "blue", white, blue, orange, green, red, yellow);
rotate("cw", "red", white, blue, orange, green, red, yellow);
rotate("cc", "blue", white, blue, orange, green, red, yellow);
rotate("cc", "yellow", white, blue, orange, green, red, yellow);
rotate("cw", "red", white, blue, orange, green, red, yellow);
rotate("cw", "red", white, blue, orange, green, red, yellow);
}
else if (yellow[1] == 'r' && red[7] == 'w') { // if white red piece is in red 7 spot
rotate("cc", "red", white, blue, orange, green, red, yellow);
rotate("cc", "red", white, blue, orange, green, red, yellow);
rotate("cw", "blue", white, blue, orange, green, red, yellow);
rotate("cw", "red", white, blue, orange, green, red, yellow);
rotate("cc", "blue", white, blue, orange, green, red, yellow);
rotate("cc", "yellow", white, blue, orange, green, red, yellow);
rotate("cw", "red", white, blue, orange, green, red, yellow);
rotate("cw", "red", white, blue, orange, green, red, yellow);
}
else if (white[3] == 'r' && blue[1] == 'w') { //if the white red piece is in the blue 1 spot
rotate("cc", "blue", white, blue, orange, green, red, yellow);
rotate("cc", "red", white, blue, orange, green, red, yellow);
}
else if (red[5] == 'r' && blue[3] == 'w') { //if the white red piece is in the blue 3 spot
rotate("cc", "red", white, blue, orange, green, red, yellow);
}
else if (orange[3] == 'r' && blue[5] == 'w') { //if the white red piece is in the blue 5 spot
rotate("cc", "blue", white, blue, orange, green, red, yellow);
rotate("cc", "blue", white, blue, orange, green, red, yellow);
rotate("cc", "red", white, blue, orange, green, red, yellow);
rotate("cc", "blue", white, blue, orange, green, red, yellow);
rotate("cc", "blue", white, blue, orange, green, red, yellow);
}
else if (yellow[5] == 'r' && blue[7] == 'w') { //if the white red piece is in the blue 7 spot
rotate("cw", "blue", white, blue, orange, green, red, yellow);
rotate("cc", "red", white, blue, orange, green, red, yellow);
rotate("cc", "blue", white, blue, orange, green, red, yellow);
}
else if (white[7] == 'r' && orange[1] == 'w') { //if the white red piece is in the orange 1 spot
rotate("cw", "orange", white, blue, orange, green, red, yellow);
rotate("cw", "orange", white, blue, orange, green, red, yellow);
rotate("cc", "yellow", white, blue, orange, green, red, yellow);
rotate("cw", "blue", white, blue, orange, green, red, yellow);
rotate("cc", "red", white, blue, orange, green, red, yellow);
rotate("cc", "blue", white, blue, orange, green, red, yellow);
}
else if (blue[5] == 'r' && orange[3] == 'w') { //if the white red piece is in the orange 3 spot
rotate("cc", "orange", white, blue, orange, green, red, yellow);
rotate("cc", "yellow", white, blue, orange, green, red, yellow);
rotate("cw", "orange", white, blue, orange, green, red, yellow);
rotate("cw", "blue", white, blue, orange, green, red, yellow);
rotate("cc", "red", white, blue, orange, green, red, yellow);
rotate("cc", "blue", white, blue, orange, green, red, yellow);
}
else if (green[3] == 'r' && orange[5] == 'w') { //if the white red piece is in the orange 5 spot
rotate("cc", "green", white, blue, orange, green, red, yellow);
rotate("cw", "yellow", white, blue, orange, green, red, yellow);
rotate("cc", "red", white, blue, orange, green, red, yellow);
rotate("cc", "red", white, blue, orange, green, red, yellow);
rotate("cw", "green", white, blue, orange, green, red, yellow);
}
else if (yellow[7] == 'r' && orange[5] == 'w') { //if the white red piece is in the orange 7 spot
rotate("cw", "yellow", white, blue, orange, green, red, yellow);
rotate("cc", "green", white, blue, orange, green, red, yellow);
rotate("cw", "red", white, blue, orange, green, red, yellow);
rotate("cw", "green", white, blue, orange, green, red, yellow);
}
else if (white[5] == 'r' && green[1] == 'w') { //if the white red piece is in the green 1 spot
rotate("cw", "green", white, blue, orange, green, red, yellow);
rotate("cw", "red", white, blue, orange, green, red, yellow);
}
else if (orange[5] == 'r' && green[3] == 'w') { //if the white red piece is in the green 3 spot
rotate("cw", "green", white, blue, orange, green, red, yellow);
rotate("cw", "green", white, blue, orange, green, red, yellow);
rotate("cw", "red", white, blue, orange, green, red, yellow);
rotate("cw", "green", white, blue, orange, green, red, yellow);
rotate("cw", "green", white, blue, orange, green, red, yellow);
}
else if (red[3] == 'r' && green[5] == 'w') { //if the white red piece is in the green 5 spot
rotate("cw", "red", white, blue, orange, green, red, yellow);
}
else if (yellow[3] == 'r' && green[7] == 'w') { //if the white red piece is in the green 7 spot
rotate("cc", "green", white, blue, orange, green, red, yellow);
rotate("cw", "red", white, blue, orange, green, red, yellow);
rotate("cw", "green", white, blue, orange, green, red, yellow);
}
else if (red[7] == 'r' && yellow[1] == 'w') { //if the white red piece is in the yellow 1 spot
rotate("cw", "red", white, blue, orange, green, red, yellow);
rotate("cw", "red", white, blue, orange, green, red, yellow);
}
else if (green[7] == 'r' && yellow[3] == 'w') { //if the white red piece is in the yellow 3 spot
rotate("cw", "yellow", white, blue, orange, green, red, yellow);
rotate("cw", "red", white, blue, orange, green, red, yellow);
rotate("cw", "red", white, blue, orange, green, red, yellow);
}
else if (blue[7] == 'r' && yellow[3] == 'w') { //if the white red piece is in the yellow 5 spot
rotate("cc", "yellow", white, blue, orange, green, red, yellow);
rotate("cw", "red", white, blue, orange, green, red, yellow);
rotate("cw", "red", white, blue, orange, green, red, yellow);
}
else if (orange[7] == 'r' && yellow[3] == 'w') { //if the white red piece is in the yellow 7 spot
rotate("cw", "yellow", white, blue, orange, green, red, yellow);
rotate("cw", "yellow", white, blue, orange, green, red, yellow);
rotate("cw", "red", white, blue, orange, green, red, yellow);
rotate("cw", "red", white, blue, orange, green, red, yellow);
}
}// end red piece loop
}//ends solved loop though i haven't added a method for checking to see if the arrays are solved yet
}
here is the function i made that i use #include "rotateFace.h" to initalize
void rotate(char direct[3], String color, char white[10], char blue[10], char orange[10], char green[10], char red[10], char yellow[10]) {
char arr[16] = "";
String results = "";
if (color == "white") {
rotateFace(direct,white);
for (int i = 0; i < 3; i++) {
results = results + red[2 - i]; //red[2,1,0]
}
for (int i = 0; i < 3; i++) {
results = results + green[2 - i]; //green[2,1,0]
}
for (int i = 0; i < 3; i++) {
results = results + orange[2 - i]; //orange[2,1,0]
}
for (int i = 0; i < 3; i++) {
results = results + blue[2 - i]; //blue[2,1,0]
}
}
if (color == "blue") {
rotateFace(direct,blue);
for (int i = 0; i < 3; i++) {
results = results + white[i * 3]; //white[0,3,6]
}
for (int i = 0; i < 3; i++) {
results = results + orange[i * 3]; //orange[0,3,6]
}
for (int i = 0; i < 3; i++) {
results = results + yellow[8 - (i * 3)]; //yellow[8,5,2]
}
for (int i = 0; i < 3; i++) {
results = results + red[8 - (i * 3)]; //red[8,5,2]
}
}
if (color == "orange") {
rotateFace(direct,orange);
for (int i = 0; i < 3; i++) {
results = results + white[i + 6]; //white[6,7,8]
}
for (int i = 0; i < 3; i++) {
results = results + green[i * 3]; //green[0,3,6]
}
for (int i = 0; i < 3; i++) {
results = results + yellow[(i + 6)]; //yellow[6,7,8]
}
for (int i = 0; i < 3; i++) {
results = results + blue[8 - (i * 3)]; //blue[8,5,2]
}
}
if (color == "green") {
rotateFace(direct,green);
for (int i = 0; i < 3; i++) {
results = results + white[8 - (i * 3)]; //white[8,5,2]
}
for (int i = 0; i < 3; i++) {
results = results + red[i * 3]; //red[0,3,6]
}
for (int i = 0; i < 3; i++) {
results = results + yellow[i * 3]; //yellow[0,3,6]
}
for (int i = 0; i < 3; i++) {
results = results + orange[8 - (i * 3)]; //orange[8,5,2]
}
}
if (color == "red") {
rotateFace(direct,red);
for (int i = 0; i < 3; i++) {
results = results + white[2 - i]; //white[2,1,0]
}
for (int i = 0; i < 3; i++) {
results = results + blue[i * 3]; //blue[0,3,6]
}
for (int i = 0; i < 3; i++) {
results = results + yellow[(2 - i)]; //yellow[2,1,0]
}
for (int i = 0; i < 3; i++) {
results = results + green[8 - (i * 3)]; //green[8,5,2]
}
}
}//ends void function
that is a very shortened version of it but the function changes all arrays without me needing to return a value which is exactly what i want but im wondering how i would change this function to not need the char arrays to be put in as parameters assuming it would save space after calling this function 600+ times. also here is the 2nd and last function i made which is much simpler in case anyone wants context of what it does
void rotateFace(char direct[3], char face[10]) {
if (direct == "cw") {
char temp = face[0];
face[0] = face[6];
face[6] = face[8];
face[8] = face[2];
face[2] = temp;
temp = face[1];
face[1] = face[3];
face[3] = face[7];
face[7] = face[5];
face[5] = temp;
}
else if (direct == "cc") {
char temp = face[1];
face[1] = face[5];
face[5] = face[7];
face[7] = face[3];
face[3] = temp;
temp = face[0];
face[0] = face[2];
face[2] = face[8];
face[8] = face[6];
face[6] = temp;
}
}
let me know if there is anything i can clarify. like i said i just need to do this in order to clear up memory.