Sequential switching, no compiling errors, but it still doesn't work!

Hi all,

Sorry to be the bearer of questions but I just can't see what's wrong!

I have modified some code in a tutorial I have done so that I could open three pneumatic actuators sequentially with a timed delay between each using the 'Delay' command, it's for a basic pick and place robot I've been working on. so I have the code and even a serial out so that I can watch it using the monitor but there's just nothing! it compiles fine, the programmer lights up etc (I'm using a TinyISP and an UNO) but then nothing, I've been through it and I can't see whats wrong so any advice would be great, I've debounced the switch as you'll see in the code below and there are currently three LED's at the pins where the actuators will finally go for testing purposes, and I'm using an SPST tac switch connected to pin2 with a 10k pulldown resistor to ground. and the code is as follows:

/*
 *  Pick & place
 */
int SPICLOCK = 8;//sck
int switchPin = 2;              // switch is connected to pin 2
int A1Pin = 12;        //Actuator 1 is up and down cylinder
int A2Pin = 11;        //Actuator 2 is vacuum to picker
int A3Pin = 10;      //Actuator 3 is to in and out cylinder or sliding table
int A4Pin = 9;    //spare
//int A5Pin = 8;      //spare

int val;                        // variable for reading the pin status
int val2;                       // variable for reading the delayed/debounced status
int buttonState;                // variable to hold the button state

int PPMode = 0;              // Is the unit homed?

void setup() {
  pinMode(switchPin, INPUT);    // Set the switch pin as input

  pinMode(A1Pin, OUTPUT);
  pinMode(A2Pin, OUTPUT);
  pinMode(A3Pin, OUTPUT);
  pinMode(A4Pin, OUTPUT);
  //pinMode(A5Pin, OUTPUT);
  
  Serial.begin(9600);                // Set up serial communication at 9600bps
  buttonState = digitalRead(switchPin);   // read the initial state
}

void loop(){
  val = digitalRead(switchPin);      // read input value and store it in val
  delay(10);                         // 10 milliseconds debounce delay
  val2 = digitalRead(switchPin);     // read the input again to check for bounces
  if (val == val2) {                 // make sure we got 2 consistant readings!
    if (val != buttonState) {          // the button state has changed!
      if (val == LOW) {                // check if the button is pressed
        if (PPMode == 0) {          // is the pick & place back home?
          PPMode = 1;               // start the pick and place routine
          digitalWrite(A1Pin, HIGH); //actuator 1 on to send cylinder down
          delay (1000);
          digitalWrite(A2Pin, HIGH); //vac on
          delay (1000);
          digitalWrite(A1Pin, LOW); //actuator 1 off to send cylinder up
          delay (200);
          digitalWrite(A3Pin, HIGH); //actuator 3 on to send cylinder across
          delay (1000);
           digitalWrite(A1Pin, HIGH); //actuator 1 on to send cylinder down
          delay (1000);
          digitalWrite(A2Pin, LOW); //vac off
          delay (1000);
          digitalWrite(A1Pin, LOW); //actuator 1 off to send cylinder up
          delay (200);
          digitalWrite(A3Pin, LOW); // sends head back to start position

        } else {
          PPMode = 0;               // homed position!
          digitalWrite(A1Pin, LOW);
          digitalWrite(A2Pin, LOW);
          digitalWrite(A3Pin, LOW);
          digitalWrite(A4Pin, LOW);
         // digitalWrite(A5Pin, LOW);
        }
      }
    }
    buttonState = val;                 // save the new state
  }
}

Thanks for all replies in advance! :)

Why are you using a programmer with an Uno? It has its own programmer.

When I have problems like these, I go back to the original Blink sketch and try to load that. look for errors returned from AVRDUDE.

Hi MorganS my previous laptop used to give errors when programming my UNO so I just always used a programmer, it's the same thing in essence! the original blink sketch works fine! annoyingly :)

Set the internal pullup on the input pin so that it isn't floating.

  pinMode(switchPin, INPUT_PULLUP);

This will make your pulldown resistor redundant.

Try adding serial debugging statements. E.g. add

Serial.println("Changed");

immediately after

    if (val != buttonState) {

so that you can tell whether the button's change of state is being detected.

Pete

Thanks, i'll give that a try!