Using buttons as commands for servo and motor controller, but no response.

I am using the Ethernet Pro microcontroller (similar to Arduino Uno). (http://www.sparkfun.com/products/10536)

I am using the RoboClaw 2x30A motor controller (http://www.basicmicro.com/RoboClaw-2x30A_p_46.html) and a simple servo.

I plan to use these buttons, which have built in resistors. (http://www.sparkfun.com/products/11160)
Since they have built in pullup resistors, I simply put connected the “VCC” on the joysticks to the 5V output on my microcontroller.

The testing code is as follows:

#include "BMSerial.h"
#include "RoboClaw.h"
#include "Servo.h"

#define address 0x80

Servo myservo;

RoboClaw roboclaw(12,13);

const int upA = 0;
const int downA = 1;
const int upB = 2;
const int downB = 3;
const int rightB = 4;

int pos = 90;

void setup() {
  roboclaw.begin(2400);
  
  myservo.attach(10);  // “Attaches” HSR1425CR servo on pin 11
  myservo.write(pos);
  
  pinMode(upA, INPUT);
  pinMode(downA, INPUT);
  pinMode(upB, INPUT);  
  pinMode(downB, INPUT);
  pinMode(rightB, INPUT);
  
}

void loop() {
  
  if (upA == LOW) {
    roboclaw.ForwardM1(address, 64);
  }
  else {
    roboclaw.ForwardM1(address, 0);
  }
  
  if (downA == LOW) {
    roboclaw.BackwardM1(address, 64);
  }
  else {
    roboclaw.BackwardM1(address, 0);
  }
  
  if (upB == LOW) {
    roboclaw.ForwardM1(address, 64);
  }
  else {
    roboclaw.ForwardM1(address, 0);
  }
  
  if (downB == LOW) {
    roboclaw.BackwardM2(address, 64);
  }
  
  if (rightB == LOW) {
   
      for(pos ; pos < 180; pos += 1) // Begin to rotate pressure washer to opposite rotation at full power
    {
      myservo.write(pos);
      delay(15);
    }
  }
  else {
    myservo.write(0);
  }
 
}

roboclaw.BackwardM1(address, 64); by the way means to put the motor at half speed.

Any flaws with my code?

Try this:

  if ( digitalRead(upA) == LOW ) { .......

Jim

Simple servo button test code.

//zoomkat servo button test 12-29-2011

#include <Servo.h>
int button1 = 4; //button pin, connect to ground to move servo
int press1 = 0;
int button2 = 5; //button pin, connect to ground to move servo
int press2 = 0;
Servo servo1;

void setup()
{
  pinMode(button1, INPUT);
  pinMode(button2, INPUT);
  servo1.attach(7);
  digitalWrite(4, HIGH); //enable pullups to make pin high
  digitalWrite(5, HIGH); //enable pullups to make pin high
}

void loop()
{
  press1 = digitalRead(button1);
  if (press1 == LOW)
  {
    servo1.write(170);
  }    
  
  press2 = digitalRead(button2);
  if (press2 == LOW)
  {
    servo1.write(10);
  }
  
  /*else {
    servo1.write(90);
  }*/
}