directional stepper motor driver

Hey! I’m fairly new to Arduino, and have been trying to make a simple controller to drive a stepper motor back and forth. To simplify things, I bought an easy stepper driver from sparkfun, which requires only a direction pin and a step pin that alternates low and high for each step. What I am trying to create is simply two SPST switches that are normally open, connected to two pins that are pulled low, as left, right direction controls. For some reason, the code I created seems to default to both direction states (upstate, downstate) always being high, resulting in alternating left, right (up, down in the code) movement. The code is based off of the example debounce code as well as spark fun’s easy stepper driver code. I’ve debugged the bread board by tying pins 4 & 5 straight to ground to make sure my resistors were messed up and floating the pins or something else wierd was happening… Any idea what I am doing wrong here? Thanks!!

const int dirPin = 2;
const int stepperPin = 3;
const int upPin = 4;
const int downPin = 5;
int lastup = LOW;
int lastdown = LOW;
int upstate;
int downstate;
long lastdebouncetime = 0;
long dlastdebouncetime = 0;
long debouncedelay = 50;
void setup() {
pinMode (dirPin, OUTPUT);
pinMode (stepperPin, OUTPUT);
pinMode (upPin, INPUT);
pinMode (downPin, INPUT);

void step (boolean dir, int steps) {
digitalWrite (dirPin, dir);
delay (50);
for (int i = 0; i < steps; i++)
digitalWrite (stepperPin, HIGH);
delayMicroseconds (100 );
digitalWrite (stepperPin, LOW);
delayMicroseconds (100); }

void loop () {
int reading = digitalRead(upPin);
if (reading != lastup) {
lastdebouncetime = millis();

if ((millis() - lastdebouncetime) > debouncedelay) {
upstate = reading;
lastup = reading;

int dreading = digitalRead(downPin);
if (dreading != lastdown) {
dlastdebouncetime = millis();

if ((millis() - dlastdebouncetime) > debouncedelay) {
downstate = dreading;
lastdown = dreading;
if (upstate = HIGH) {
step (true, 1000);
delay (100);

if (downstate = HIGH) {
step (false, 1000);
delay (100);

if (upstate = HIGH) {

Pay attention to when to use = vs. ==.

Also your step function is pulsing steps at 5kHz - this may be too fast for some steppers. Start with something like 10 pulses per second.