Powered by an Arduino UNO and Arduino Motorshield running on 4AA batteries.
The motor is this one:
I am using (for now), this code:
I am using a linear pot to turn the motor speed up/down on A0, but it only gives me 3 stages; slow, moderate, fast. I don't have a fully at rest state, and I have no real speed control to find tune to my needs. My thought was that I would simply get the pot correctly running and it would sweep smoothly for speed control. Am I wrong that it should do that? I could use button controls to do what it does now (if I knew how to code them in).
Buttons are a lost cause for me, I can't figure them out, I've tried...talked to people about them....I simply do not understand the wiring that needs to be done for them or how to code them. I simply want 2 SPST NO buttons to control left/right control for now, and the pot for speed. After that is running I will work on the interface for timelapsing.
Can someone PLEASE help me out here? I can add you on facebook and repost here once I have it figured out so google can find it. I am simply lost on what I'm doing. I've done the tutorials on adafruit, but no luck on using them outside of the tutorials.
Buttons are a lost cause for me, I can't figure them out, I've tried...talked to people about them....I simply do not understand the wiring that needs to be done for them or how to code them. I simply want 2 SPST NO buttons to control left/right control
The easiest way to wire the switches (buttons are for shirts) is to connect one leg to ground and the other way to a digital pin. Then, turn on the pullup resistor on the pin that the switch is connected to. You can use:
Buttons are a lost cause for me, I can't figure them out, I've tried
Have you tried zips?
Velcro?
Seriously, there are plenty of examples, libraries even, to allow you to use simple switches.
Maybe I wasn't clear? I've done every button tutorial I can find. I simply don't understand this stuff, and would like to get my project moving forward. If I can get it working, I don't know if I will continue w/ Arduino or not...but I'd like to at least complete this.
A switch is a binary device; at any instant, it can be on or off.
Whether the "on" state returns a HIGH or a LOW to the processor depends on how it is wired.
If the switch is mechanical, it may exhibit a phenomenon called "bounce", where the natural springiness of its construction may cause it to return multiple different states over a short period of time, which may cause a very fast program loop to jitter as it reads every state until the switch fi ally comes to rest.
There are many techniques to debounce a switch, some hardware, some software
I'm not ofay with AccelStepper but a quick look at the library on the authors site an I cannot see an option for just 3 pin defininitions. Also you seem to be sharing one of the stepper pins with buttonPin. You setup but never read the buttonPin pin.
EDIT: A closer look and it seems the 2 is the number of pins so does not clash with buttonPin.
Also the command looks like it should be 'AccelStepper stepper(DRIVER ,3,12);' but someone else should confirm this.
#include <AccelStepper.h>
AccelStepper stepper(2,12,13);
const int pwmA = 3;
const int pwmB = 11;
const int brakeA = 8;
const int brakeB = 9;
const int buttonPin = 2;
boolean buttonWasPressed;
int buttonValue;
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup()
{
pinMode(pwmA, OUTPUT);
pinMode(pwmB, OUTPUT);
pinMode(brakeA, OUTPUT);
pinMode(brakeB, OUTPUT);
digitalWrite(pwmA, HIGH);
digitalWrite(pwmB, HIGH);
digitalWrite(brakeA, LOW);
digitalWrite(brakeB, LOW);
stepper.setMaxSpeed(800);
stepper.setSpeed(1);
pinMode(buttonPin, INPUT);
buttonWasPressed = false;
}
void loop()
{
stepper.runSpeed();
int sensorReading = analogRead(A0);
// map it to a range from 0 to 100:
int motorSpeed = map(sensorReading, 0, 1023, 1, 1600); //1600 is the max speed of my motor
stepper.setSpeed(motorSpeed);
Serial.println(sensorReading);
}
AWOL:
Maybe if we could see your code, we might be able to help.
Oh well.
I posted my code in my first post. I figured that was easier than posting it here, but it's posted below now but another user. I've been staring at this for nearly a month, with little to no progress. I'm simply just trying to finish at this point.
I've been staring at this for nearly a month, with little to no progress.
How ARE your switches wired? What behavior do you actually see when a SMALL sketch reads the switch state(s) and prints them to the Serial Monitor application?
Last I tried a switch, when pressed it turned my whole board off. I don't know why or how. I stopped messing with it when I couldn't get a better outcome, so I came here.
This is what I've come up with, though I also got it working with a while statement. It works...but something is still off. Debounce may beI needed, I don't know. I rress the button and it moves, but it delays the release a lot of times.
#include <AccelStepper.h>
AccelStepper stepper(2,12,13);
const int pwmA = 3;
const int pwmB = 11;
const int brakeA = 8;
const int brakeB = 9;
const int buttonPin = 2;
int buttonState = 0; // variable for reading the pushbutton status
void setup()
{
pinMode(pwmA, OUTPUT);
pinMode(pwmB, OUTPUT);
pinMode(brakeA, OUTPUT);
pinMode(brakeB, OUTPUT);
digitalWrite(pwmA, HIGH);
digitalWrite(pwmB, HIGH);
digitalWrite(brakeA, LOW);
digitalWrite(brakeB, LOW);
stepper.setMaxSpeed(800);
stepper.setSpeed(800);
pinMode(buttonPin, INPUT_PULLUP);
}
void loop()
{
buttonState = digitalRead(buttonPin); // read state of buttonPin
if (buttonState == HIGH)
{
digitalWrite(buttonPin, HIGH);
}
else
{
digitalWrite(buttonPin, LOW);
stepper.runSpeed(); //stepper code goes here
}
}