- Code: Select all
if (buttonStateHome == HIGH)
// read the input pin
digitalWrite(buttonStateHome,HIGH );
And what is this part for? Is buttonStateHome an input or an output? As is, this statement enables the internal pullup resistor.
Moderators: adafruit_support_bill, adafruit
if (buttonStateHome == HIGH)
// read the input pin
digitalWrite(buttonStateHome,HIGH );
#include <buttons.h>
#include <Bounce.h>
#include <AccelStepper.h>
#include <AFMotor.h>
/*
Four switch stepper motor Program
Turns on and off digital pins connected to pin 9,10,11,13,2 as output when pressing pushbuttons
(Park,Rev,Ntrl, Dr and Home ) attached to digital pins 14,15,16,17and 18
The circuit:
* Using AfaFruit shield with motor output on M3 and M4
* pushbuttons are attached to digital pins 14,15,16,17,qnd switch 18 +5V supply for switches. // analog pins A0,A1,A2,A3, and A4 are used as digital pins 14 through 18:
* 10K resistors attached to digital pins 2 from ground
*/
// constants won't change. They're used here to
// set pin numbers:
const int buttonPinPark = 14; //Setting Park button to Pin 14
const int buttonPinRev = 15; //Setting Reverse button to Pin 15
const int buttonPinNtrl = 16; //Setting Neutral button to Pin 16
const int buttonPinDr = 17; //Setting Drive button to Pin 17
const int buttonPinHome = 18; //Used as input for the home position on pin 18
int buttonStatePark = 0; //Setting Park button state to off
int buttonStateRev = 0; //Setting Reverse button state to off
int buttonStateNtrl = 0; //Setting Neutral button state to off
int buttonStateDr = 0; //Setting Drive button state to off
int buttonStateHome = 0; //Setting Drive button state to off
const int Pin9 = 9; // PIN OUTPUT NUMBER
const int Pin10 = 10; // PIN OUTPUT NUMBER
const int Pin11 = 11; // PIN OUTPUT NUMBER
const int Pin13 = 13; // PIN OUTPUT NUMBER
const int Pin2 = 2; // PIN OUTPUT NUMBER
AF_Stepper motor(200, 2);
void setup() {
// open the serial port at 9600 bps:
Serial.begin(9600);
// initialize the pin as an output:
pinMode (Pin9,OUTPUT);
pinMode (Pin10,OUTPUT);
pinMode (Pin11,OUTPUT);
pinMode (Pin13,OUTPUT);
pinMode (Pin2,OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPinPark, INPUT);
pinMode(buttonPinRev, INPUT);
pinMode(buttonPinNtrl, INPUT);
pinMode(buttonPinDr, INPUT);
pinMode(buttonPinHome, INPUT);
motor.setSpeed(10); // 10 rpm
}
void loop()
{
// delay 10 milliseconds before the next reading:
delay(10);
// read the state of the Park pushbutton value:
buttonStatePark = digitalRead(buttonPinPark); //code for Park button
Serial.print("Park = ");
Serial.println(buttonStatePark, DEC); // print as an ASCII-encoded decimal:
// delay 10 milliseconds before the next reading:
delay(10);
// read the state of the Home pushbutton value:
buttonStateHome = digitalRead(buttonPinHome); //code for Park button
Serial.print("Home = ");
Serial.println(buttonStateHome, DEC); // print as an ASCII-encoded decimal:
// check if the Park pushbutton is pressed.
// if it is, the buttonStatePark is HIGH:
if (buttonStatePark == HIGH)
{
// Have output on pin 9 (5 volts:
digitalWrite (Pin9, HIGH);
while (buttonStateHome != HIGH)
// step until the home limit switch is detected
motor.step(20, FORWARD, SINGLE);
// read the input pin
digitalRead(buttonStateHome);
}
else
{
// Set Pin9 Off:
digitalWrite(Pin9, LOW);
}
{
// delay 10 milliseconds before the next reading:
delay(10);
// read the state of the Rev pushbutton value:
buttonStateRev = digitalRead(buttonPinRev); //code for Rev button
Serial.print("Rev = ");
Serial.println(buttonStateRev, DEC); // print as an ASCII-encoded decimal:
// check if the Rev pushbutton is pressed.
// if it is, the buttonStateRev is HIGH:
if (buttonStateRev == HIGH)
{
// Have output on pin 10 (5 volts:
digitalWrite (Pin10, HIGH);
motor.step(40, BACKWARD, SINGLE);
}
else
{
// Set Pin10 Off:
digitalWrite(Pin10, LOW);
}
{
// delay 10 milliseconds before the next reading:
delay(10);
// read the state of the Ntrl pushbutton value:
buttonStateNtrl = digitalRead(buttonPinNtrl); //code for Ntrl button
Serial.print("Ntrl = ");
Serial.println(buttonStateNtrl, DEC); // print as an ASCII-encoded decimal:
// check if the Ntrl pushbutton is pressed.
// if it is, the buttonStateNtrl is HIGH:
if (buttonStateNtrl == HIGH)
{
// Have output on pin 11 (5 volts:
digitalWrite (Pin11, HIGH);
motor.step(60, FORWARD, SINGLE);
}
else
{
// Set Pin11 Off:
digitalWrite(Pin11, LOW);
}
{
// delay 10 milliseconds before the next reading:
delay(10);
// read the state of the Rev pushbutton value:
buttonStateDr = digitalRead(buttonPinDr); //code for Dr button
Serial.print("Dr = ");
Serial.println(buttonStateDr, DEC); // print as an ASCII-encoded decimal:
// check if the Dr pushbutton is pressed.
// if it is, the buttonStateDr is HIGH:
if (buttonStateDr == HIGH)
{
// Have output on pin 13 (5 volts:
digitalWrite (Pin13, HIGH);
motor.step(80, FORWARD, SINGLE);
}
else
{
// Set Pin13 Off:
digitalWrite(Pin13, LOW);
}
}
}
}
}
#include <buttons.h>
#include <Bounce.h>
#include <AccelStepper.h>
#include <AFMotor.h>
/*
Four switch stepper motor Program
Turns on and off digital pins connected to pin 9,10,11,13,2 as output when pressing pushbuttons
(Park,Rev,Ntrl, Dr and Home ) attached to digital pins 14,15,16,17and 18
The circuit:
* Using AfaFruit shield with motor output on M3 and M4
* pushbuttons are attached to digital pins 14,15,16,17,qnd switch 18 +5V supply for switches. // analog pins A0,A1,A2,A3, and A4 are used as digital pins 14 through 18:
* 10K resistors attached to digital pins 2 from ground
*/
// constants won't change. They're used here to
// set pin numbers:
const int buttonPinPark = 14; //Setting Park button to Pin 14
const int buttonPinRev = 15; //Setting Reverse button to Pin 15
const int buttonPinNtrl = 16; //Setting Neutral button to Pin 16
const int buttonPinDr = 17; //Setting Drive button to Pin 17
const int buttonPinHome = 18; //Used as input for the home position on pin 18
int buttonStatePark = 0; //Setting Park button state to off
int buttonStateRev = 0; //Setting Reverse button state to off
int buttonStateNtrl = 0; //Setting Neutral button state to off
int buttonStateDr = 0; //Setting Drive button state to off
int buttonStateHome = 0; //Setting Drive button state to off
const int Pin9 = 9; // PIN OUTPUT NUMBER
const int Pin10 = 10; // PIN OUTPUT NUMBER
const int Pin11 = 11; // PIN OUTPUT NUMBER
const int Pin13 = 13; // PIN OUTPUT NUMBER
const int Pin2 = 2; // PIN OUTPUT NUMBER
AF_Stepper motor(200, 2);
void setup() {
// open the serial port at 9600 bps:
Serial.begin(9600);
// initialize the pin as an output:
pinMode (Pin9,OUTPUT);
pinMode (Pin10,OUTPUT);
pinMode (Pin11,OUTPUT);
pinMode (Pin13,OUTPUT);
pinMode (Pin2,OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPinPark, INPUT);
pinMode(buttonPinRev, INPUT);
pinMode(buttonPinNtrl, INPUT);
pinMode(buttonPinDr, INPUT);
pinMode(buttonPinHome, INPUT);
motor.setSpeed(10); // 10 rpm
}
void loop()
{
// delay 10 milliseconds before the next reading:
delay(10);
// read the state of the Park pushbutton value:
buttonStatePark = digitalRead(buttonPinPark); //code for Park button
Serial.print("Park = ");
Serial.println(buttonStatePark, DEC); // print as an ASCII-encoded decimal:
// delay 10 milliseconds before the next reading:
delay(10);
// read the state of the Home pushbutton value:
buttonStateHome = digitalRead(buttonPinHome); //code for Park button
Serial.print("Home = ");
Serial.println(buttonStateHome, DEC); // print as an ASCII-encoded decimal:
// check if the Park pushbutton is pressed.
// if it is, the buttonStatePark is HIGH:
if (buttonStatePark == HIGH)
{
// Have output on pin 9 (5 volts:
digitalWrite (Pin9, HIGH);
while (buttonStateHome != HIGH)
// step until the home limit switch is detected
motor.step(20, FORWARD, SINGLE);
// read the input pin
digitalRead(buttonStateHome);
}
else
{
// Set Pin9 Off:
digitalWrite(Pin9, LOW);
}
{
// delay 10 milliseconds before the next reading:
delay(10);
// read the state of the Rev pushbutton value:
buttonStateRev = digitalRead(buttonPinRev); //code for Rev button
Serial.print("Rev = ");
Serial.println(buttonStateRev, DEC); // print as an ASCII-encoded decimal:
// check if the Rev pushbutton is pressed.
// if it is, the buttonStateRev is HIGH:
if (buttonStateRev == HIGH)
{
// Have output on pin 10 (5 volts:
digitalWrite (Pin10, HIGH);
motor.step(40, BACKWARD, SINGLE);
}
else
{
// Set Pin10 Off:
digitalWrite(Pin10, LOW);
}
{
// delay 10 milliseconds before the next reading:
delay(10);
// read the state of the Ntrl pushbutton value:
buttonStateNtrl = digitalRead(buttonPinNtrl); //code for Ntrl button
Serial.print("Ntrl = ");
Serial.println(buttonStateNtrl, DEC); // print as an ASCII-encoded decimal:
// check if the Ntrl pushbutton is pressed.
// if it is, the buttonStateNtrl is HIGH:
if (buttonStateNtrl == HIGH)
{
// Have output on pin 11 (5 volts:
digitalWrite (Pin11, HIGH);
motor.step(60, FORWARD, SINGLE);
}
else
{
// Set Pin11 Off:
digitalWrite(Pin11, LOW);
}
{
// delay 10 milliseconds before the next reading:
delay(10);
// read the state of the Rev pushbutton value:
buttonStateDr = digitalRead(buttonPinDr); //code for Dr button
Serial.print("Dr = ");
Serial.println(buttonStateDr, DEC); // print as an ASCII-encoded decimal:
// check if the Dr pushbutton is pressed.
// if it is, the buttonStateDr is HIGH:
if (buttonStateDr == HIGH)
{
// Have output on pin 13 (5 volts:
digitalWrite (Pin13, HIGH);
motor.step(80, FORWARD, SINGLE);
}
else
{
// Set Pin13 Off:
digitalWrite(Pin13, LOW);
}
}
}
}
}
while (buttonStateHome != HIGH)
// step until the home limit switch is detected
motor.step(20, FORWARD, SINGLE);
// read the input pin
digitalRead(buttonStateHome);
while (buttonStateHome != HIGH)
{
// step until the home limit switch is detected
motor.step(20, FORWARD, SINGLE);
// read the input pin
digitalRead(buttonStateHome);
}
#include <buttons.h>
#include <Bounce.h>
#include <AccelStepper.h>
#include <AFMotor.h>
/*
Four switch stepper motor Program
Turns on and off digital pins connected to pin 9,10,11,13,2 as output when pressing pushbuttons
(Park,Rev,Ntrl, Dr and Home ) attached to digital pins 14,15,16,17and 18
The circuit:
* Using AfaFruit shield with motor output on M3 and M4
* pushbuttons are attached to digital pins 14,15,16,17,qnd switch 18 +5V supply for switches. // analog pins A0,A1,A2,A3, and A4 are used as digital pins 14 through 18:
* 10K resistors attached to digital pins 2 from ground
*/
// constants won't change. They're used here to
// set pin numbers:
const int buttonPinPark = 14; //Setting Park button to Pin 14
const int buttonPinRev = 15; //Setting Reverse button to Pin 15
const int buttonPinNtrl = 16; //Setting Neutral button to Pin 16
const int buttonPinDr = 17; //Setting Drive button to Pin 17
const int buttonPinHome = 18; //Used as input for the home position on pin 18
int buttonStatePark = 0; //Setting Park button state to off
int buttonStateRev = 0; //Setting Reverse button state to off
int buttonStateNtrl = 0; //Setting Neutral button state to off
int buttonStateDr = 0; //Setting Drive button state to off
int buttonStateHome = 0; //Setting Drive button state to off
const int Pin9 = 9; // PIN OUTPUT NUMBER
const int Pin10 = 10; // PIN OUTPUT NUMBER
const int Pin11 = 11; // PIN OUTPUT NUMBER
const int Pin13 = 13; // PIN OUTPUT NUMBER
const int Pin2 = 2; // PIN OUTPUT NUMBER
AF_Stepper motor(200, 2);
void setup() {
// open the serial port at 9600 bps:
Serial.begin(9600);
// initialize the pin as an output:
pinMode (Pin9,OUTPUT);
pinMode (Pin10,OUTPUT);
pinMode (Pin11,OUTPUT);
pinMode (Pin13,OUTPUT);
pinMode (Pin2,OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPinPark, INPUT);
pinMode(buttonPinRev, INPUT);
pinMode(buttonPinNtrl, INPUT);
pinMode(buttonPinDr, INPUT);
pinMode(buttonPinHome, INPUT);
motor.setSpeed(10); // 10 rpm
}
void loop()
{
// delay 10 milliseconds before the next reading:
delay(10);
// read the state of the Park pushbutton value:
buttonStatePark = digitalRead(buttonPinPark); //code for Park button
Serial.print("Park = ");
Serial.println(buttonStatePark, DEC); // print as an ASCII-encoded decimal:
// delay 10 milliseconds before the next reading:
delay(10);
// read the state of the Home pushbutton value:
buttonStateHome = digitalRead(buttonPinHome); //code for Park button
Serial.print("Home = ");
Serial.println(buttonStateHome, DEC); // print as an ASCII-encoded decimal:
// check if the Park pushbutton is pressed.
// if it is, the buttonStatePark is HIGH:
if (buttonStatePark == HIGH)
{
// Have output on pin 9 (5 volts:
digitalWrite (Pin9, HIGH);
while (buttonStateHome != HIGH)
// step until the home limit switch is detected
{
motor.step(20, FORWARD, SINGLE);
// read the input pin
digitalRead(buttonStateHome);
}
}
else
{
// Set Pin9 Off:
digitalWrite(Pin9, LOW);
}
{
// delay 10 milliseconds before the next reading:
delay(10);
// read the state of the Rev pushbutton value:
buttonStateRev = digitalRead(buttonPinRev); //code for Rev button
Serial.print("Rev = ");
Serial.println(buttonStateRev, DEC); // print as an ASCII-encoded decimal:
// check if the Rev pushbutton is pressed.
// if it is, the buttonStateRev is HIGH:
if (buttonStateRev == HIGH)
{
// Have output on pin 10 (5 volts:
digitalWrite (Pin10, HIGH);
motor.step(40, BACKWARD, SINGLE);
}
else
{
// Set Pin10 Off:
digitalWrite(Pin10, LOW);
}
{
// delay 10 milliseconds before the next reading:
delay(10);
// read the state of the Ntrl pushbutton value:
buttonStateNtrl = digitalRead(buttonPinNtrl); //code for Ntrl button
Serial.print("Ntrl = ");
Serial.println(buttonStateNtrl, DEC); // print as an ASCII-encoded decimal:
// check if the Ntrl pushbutton is pressed.
// if it is, the buttonStateNtrl is HIGH:
if (buttonStateNtrl == HIGH)
{
// Have output on pin 11 (5 volts:
digitalWrite (Pin11, HIGH);
motor.step(60, FORWARD, SINGLE);
}
else
{
// Set Pin11 Off:
digitalWrite(Pin11, LOW);
}
{
// delay 10 milliseconds before the next reading:
delay(10);
// read the state of the Rev pushbutton value:
buttonStateDr = digitalRead(buttonPinDr); //code for Dr button
Serial.print("Dr = ");
Serial.println(buttonStateDr, DEC); // print as an ASCII-encoded decimal:
// check if the Dr pushbutton is pressed.
// if it is, the buttonStateDr is HIGH:
if (buttonStateDr == HIGH)
{
// Have output on pin 13 (5 volts:
digitalWrite (Pin13, HIGH);
motor.step(80, FORWARD, SINGLE);
}
else
{
// Set Pin13 Off:
digitalWrite(Pin13, LOW);
}
}
}
}
}Users browsing this forum: No registered users and 2 guests