So I made I made a program that only takes up 8KB of memory, after which it stopped working. Simply repeating the setup loop and not going into the main void loop. After looking online for a bit I found that the problem occurs when the program is larger than the space on the arduino. So I commented out several lines to lower the memory to about 5kb and it started working again. Pretty sure the issue is the memory but it should be able to be about 5x that value. This would mean that the bootloader is about 27 kb. Oh and Dmem is at 21% of total memory.
My code is as follows
//int XVal = A0;
int YVal = A1;
//int ZVal = A2;
//int sensor1 = 0;
int sensor2 = 0;
//int sensor3 = 0;
int midValue = 330;
int highValue = 330;
int lowValue = 330;
int error = 0;
int motor1 = 10;
int motor2 = 11;
//float prop = 1.0;
//float integ = 1.0;
//float deriv = 1.0;
void setup(){
Serial.begin(9600);
// pinMode(XVal, INPUT);
pinMode(YVal, INPUT);
// pinMode(ZVal, INPUT);
pinMode(motor1, OUTPUT);
pinMode(motor2, OUTPUT);
Serial.println("{TABLE:Base|SET|error|" + String(error) + "|baseline}");
Serial.println("{TABLE:Base|SET|proportional|" + String(error) + "|baseline}");
Serial.println("{TABLE:Base|SET|integral|" + String(error) + "|baseline}");
Serial.println("{TABLE:Base|SET|derivitive|" + String(error) + "|baseline}");
}
void loop(){
delay(300);
// sensor1 = analogRead(XVal);
sensor2 = analogRead(YVal);
// sensor3 = analogRead(ZVal);
if(sensor2 < lowValue){
lowValue = sensor2;
}
else
{
if(sensor2 > highValue){
highValue = sensor2;
}
}
midValue = (highValue+lowValue)/2+10;
error = midValue - sensor2;
//printf("X %I Y %I Z %I", sensor1, sensor2,sensor3);
//Serial.println(String(sensor1) + " " + String(sensor2) + " " + String(sensor3));
//Serial.println(String(lowValue) + "L " + String(midValue) + "M " + String(highValue) + "H ");
Serial.println(String(sensor2));
Serial.println("{TIMEPLOT|data|Pitch|T|" + String(sensor2) + "}");
Serial.println("{TABLE:Sensor|SET|Error|" + String(error) + "|amount off base}");
Serial.println("{TABLE:Sensor|SET|proportional|" + String(error) + "|proportional power}");
//Serial.println("#S|Proportion|[error]#");
if(sensor2 < 340){
analogWrite(motor1, 190 + error);
analogWrite(motor2, 190 - error);
}
else
{
if(sensor2 > 360){
analogWrite(motor1, 190 - error);
analogWrite(motor2, 190 + error);
}
else
{
analogWrite(motor1, 0);
analogWrite(motor2, 0);
}
}
}