Annoyingly, the autoformat has shifted curly brackets onto separate lines again when I've used it after I tidied them earlier. I guess that's how they got like that in the first place now.
I haven't renamed those sensors yet btw... will do though.
If someone could advise what I'm doing wrong with this sodding error though I'd be grateful, thanks.
// Useful - http://arduino-info.wikispaces.com/LCD-Pushbuttons
// button presses are through A0 using "int read_LCD_buttons()"
#include <LiquidCrystal.h>
//LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7);
LiquidCrystal lcd( 8, 9, 4, 5, 6, 7 );
int buttonpin = A0; //Button presses from keypad
byte directionPin1 = 12; // rail
byte stepPin1 = 13if; // rail
int numberOfSteps1 = 3; // rail
int dir1 = 0; // direction flag for rail
int stepdelay1 = 0; // the delay between steps to control the speed
int stepdelaytime1b = 0;
int stepdelaytime1c = 1;
int delaytime1 = 1;
byte directionPin2 = 2; // pan
byte stepPin2 = 3; // pan
int numberOfSteps2 = 3; // pan
int dir2 = 0; // notional serial output flag for direction
int stepdelay2 = 0; // the delay between steps to control the speed
int stepdelaytime2b = 0;
int stepdelaytime2c = 1;
int delaytime2 = 1;
byte ledPin = 13;
//int uSbetweenSteps = 5; // microseconds
int sensorPin1 = A1; // input pin for rail pot
int sensorPin2 = A2; // panning pot
int sensorPin3 = A3; // exposure
int sensorPin4 = A4; // interval
int sensorValue1 = 0; // variable to store the value coming from the rail sensor
int sensorValue2 = 0; // variable to store the value coming from the pan sensor
int sensorValue3 = 0; // variable for the exposure
int sensorValue4 = 0; // variable for the interval
int sensorValue1b = 0; // new var to deduct 512 from rail input
int sensorValue2b = 0; // new var to deduct 512 from pan input
int interval = 3; // Delay between pictures (in seconds)
int exposure = 1; // default exposure time (ms)
int shutterPin =11; // Shutter pin (digital)
int shutterarray[20] = {
1, 2, 4, 8, 16, 33, 60, 125, 250, 500, 1000, 2000, 4000, 6000, 8000, 10000, 15000, 20000, 25000, 30000}; // create array of shutter millisecond speeds available
float newval= 0;
int roundval = 0;
void setup()
{
Serial.begin(9600); // start serial output
lcd.begin(16, 2); // start the lcd object
Serial.println("Starting");
lcd.setCursor(0,0);
lcd.print("Starting");
sensorValue1 = analogRead(sensorPin1); //rail
sensorValue2 = analogRead(sensorPin2); //pan
sensorValue3 = analogRead(sensorPin3); //expo
sensorValue4 = analogRead(sensorPin4); //intvl
Serial.println(sensorValue1); //rail
Serial.println(sensorValue2); //pan
Serial.println(sensorValue3); //expo
Serial.println(sensorValue4); //intvl
Serial.println("");
newval = (sensorValue3/51.2); // roughly range of 1-20 with loads of decimals
roundval = (int) newval; // round (actually truncate) it to a round number/integer
exposure = shutterarray[roundval]; // will pick up the appropriate shutter speed based on input val
Serial.println("newval =");
Serial.println(newval);
Serial.println("roundval =");
Serial.println(roundval);
Serial.println("Shutter MS =");
Serial.println(exposure);
Serial.println("Interval =");
Serial.println(interval);
digitalWrite(ledPin, LOW);
delay(2000);
pinMode(directionPin1, OUTPUT);
pinMode(stepPin1, OUTPUT);
pinMode(directionPin2, OUTPUT);
pinMode(stepPin2, OUTPUT);
pinMode(shutterPin, OUTPUT); // Set the shutter pin as an output
digitalWrite(shutterPin, LOW);
pinMode(ledPin, OUTPUT); // Set the LED pin as an output
// set up how many loops:
for (int count=0; count <= 100; count++)
{
// begin loop
//take pic:
Serial.println("Fire Shutter MS=");
lcd.setCursor(0,0);
lcd.print(" "); // Blank
lcd.setCursor(0,0);
lcd.print("Photostart");
lcd.setCursor(0,1);
lcd.print(" "); // Blank
lcd.setCursor(0, 1); //move to second line
lcd.print(exposure);
Serial.println(exposure);
//digitalWrite(ledPin, HIGH); // Turn on activity LED
digitalWrite(shutterPin, HIGH); // Turn on shutter relay
delay(exposure); // Hold the button for set time
//digitalWrite(ledPin, LOW); // Turn off activity LED
digitalWrite(shutterPin, LOW); // Turn off shutter relay
Serial.println("Photostop");
lcd.setCursor(0,0);
lcd.print(" "); // Blank
lcd.setCursor(0,0);
lcd.print("Photostop");
// get the 2 analog sensor values from the rail & pan pots:
lcd.setCursor(0,1);
lcd.print(" "); // Blank
lcd.setCursor(0,1);
lcd.print("Move..."); // Blank
Serial.println("Move rail = steps");
Serial.println(numberOfSteps1);
Serial.println("Move pan = steps");
Serial.println(numberOfSteps2);
sensorValue1 = analogRead(sensorPin1);
sensorValue1b = sensorValue1-512; // JD+
sensorValue2 = analogRead(sensorPin2);
sensorValue2b = sensorValue2-512;
// begin rail ******************************
if
(sensorValue1b < 0)
{
digitalWrite(directionPin1, HIGH); // Turn one way if the pot is turned low
{
dir1 = 1;
} // and set the direction flag
{
stepdelay1 = (sensorValue1b * -1);
} // convert the minus figure to + for the speed
}
else
{
digitalWrite(directionPin1, LOW); // Turn the other way if the pot is turned high
{
dir1 = 0;
} // and set the direction flag
{
stepdelay1 = sensorValue1b;
} //already have the speed
}
Serial.println("Rail Direction =");
Serial.println(dir1); //report the direction flag
//************************
//************************
stepdelaytime1b = sqrt(stepdelay1)/3; // of the knob output and reduce the range of delay
if
(stepdelaytime1b == 0) // a value of zero causes the code to stop so we weed this out for now with default 1
{stepdelaytime1c = 1;}
else
{stepdelaytime1c = stepdelaytime1b;}
delaytime1 = 22/stepdelaytime1b; // this is to invert the speed control about its centre point.
// 11 is the max value thus dividing into it gives the inverse and the speed control goes the right way now
for(int n = 0; n < numberOfSteps1; n++)
{
digitalWrite(stepPin1, HIGH);
Serial.println("Stepping Rail Now...");
delay(delaytime1);
digitalWrite(ledPin, !digitalRead(ledPin));
}
// end rail ******************************
// begin pan******************************
if
(sensorValue2b < 0)
{
digitalWrite(directionPin2, HIGH); // Turn one way if the pot is turned low
{
dir2 = 1;
} // and set the direction flag
{
stepdelay2 = (sensorValue2b * -1);
} // convert the minus figure to + for the speed
}
else
{
digitalWrite(directionPin2, LOW); // Turn the other way if the pot is turned high
{
dir2 = 0;
} // and set the direction flag
{
stepdelay2 = sensorValue2b;
} //already have the speed
}
Serial.println("Pan Direction =");
Serial.println(dir2); //report the direction flag
for(int n = 0; n < numberOfSteps2; n++)
{
digitalWrite(stepPin2, HIGH);
Serial.println("Stepping Pan Now...");
//delay(uSbetweenSteps);
delay(stepdelay2); // get the calculated figure to set the speed
digitalWrite(ledPin, !digitalRead(ledPin));
}
// end pan ******************************
Serial.println("Photo Count =");
Serial.println(count);
lcd.setCursor(0,0);
lcd.print("Wait b4 next shot");
delay(1000 * interval); // Wait interval time before next shot for stuff to move and time next frame.
Serial.println("Wait b4 next =");
Serial.println(interval);
lcd.setCursor(0,1);
lcd.print("Count = ");
lcd.setCursor(9,1);
lcd.print("count");
lcd.setCursor(0,1);
lcd.print(1000 * interval);
// end loop ********************
}
lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(0,0);
lcd.print("All finished");
}
void loop() // *****************************************************************
{
}