I have 2 separate sketches
The first sketch has a push button that allows me to toggle the Arudino LED light on and off
Second code allows for a stepper motor to spin
I've been trying to combine codes in order to allow the push button to be pushed, the stepper motor spins/runs through the program and then requires the push button to be pushed again for the process to repeat. I've tried different methods of combining the code with no luck so far. It may be very simple as I'm just not seeing it. Push button diagram attached.
Thank you in advance for any help.
The first sketch has a push button that allows me to toggle the Arudino LED light on and off
Code:
//Button test
int button = 3; //button pin, touch to ground as button
int press = 0;
boolean toggle = true;
void setup()
{
pinMode(13, OUTPUT); //LED on pin 13
pinMode(button, INPUT); //arduino monitor pin state
digitalWrite(5, HIGH); //enable pullups to make pin 5 high
}
void loop()
{
press = digitalRead(button);
if (press == LOW)
{
if(toggle)
{
digitalWrite(13, HIGH); // set the LED on
toggle = !toggle;
}
else
{
digitalWrite(13, LOW); // set the LED off
toggle = !toggle;
}
}
delay(300); //delay for debounce
}
Code:
/*
Stepper Motor Control - one revolution
This program drives a unipolar or bipolar stepper motor.
The motor is attached to digital pins 8 - 11 of the Arduino.
The motor should revolve one revolution in one direction, then
one revolution in the other direction.
Created 11 Mar. 2007
Modified 30 Nov. 2009
by Tom Igoe
*/
#include <Stepper.h>
int x = 0;
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
void setup() {
// set the speed at 60 rpm:
myStepper.setSpeed(63);
// initialize the serial port:
Serial.begin(9600);
}
void loop() {
if (x <= 10)
{ // step one revolution in one direction:
Serial.println("clockwise");
myStepper.step(stepsPerRevolution);
// delay(500);
x++;
}
// step one revolution in the other direction:
// Serial.println("counterclockwise");
// myStepper.step(-stepsPerRevolution);
// delay(500);
}
Thank you in advance for any help.
Attachments
-
31.3 KB Views: 4