Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: Homing stepper with a swtich on: November 28, 2012, 05:47:55 am
Here is the code.  I've gotten it so far that it needs a press of the button to start activate the program. But i cant figure out how to make it move backwards until the button in pressed.

Code:
#include <AccelStepper.h>

// Define a stepper and the pins it will use
AccelStepper stepper(1, 49, 47);

int switchPin = 33;
int ledPin = 13;
boolean lastButton = LOW;
boolean currentButton = LOW;
boolean ledOn = false;

void setup()
{
  pinMode(switchPin, INPUT);
  pinMode(ledPin, OUTPUT);
  stepper.setMaxSpeed(200.0);
    stepper.setAcceleration(100.0);
}

boolean debounce(boolean last)
{
  boolean current = digitalRead(switchPin);
  if (last != current)
  {
    delay(5);
    current = digitalRead(switchPin);
  }
  return current;
}

void loop()
{
  currentButton = debounce(lastButton);
  if (lastButton == LOW && currentButton == HIGH)
  {
    ledOn = !ledOn;
    stepper.runToNewPosition(0);
    stepper.runToNewPosition(500);
    stepper.runToNewPosition(100);
    stepper.runToNewPosition(120);
  }
  lastButton = currentButton;
  }

 
2  Using Arduino / Programming Questions / Re: Homing stepper with a swtich on: November 27, 2012, 01:45:11 pm
I haven't got the rail atm, but it seems like it should work anyways, like if the button is not active the motor moves backwards. But when the button gets pressed the code from the menu starts.

I've just tried to modify the AccelStepper's example "blocker" with a funktion that reads the buttonstate. But i don't really know how i should proceed, or if I'm doing it right from the start?
3  Using Arduino / Programming Questions / Re: Homing stepper with a swtich on: November 27, 2012, 01:11:52 pm
I can't work it out..  smiley-confuse
I'm pretty new to programing.
4  Using Arduino / Programming Questions / Re: Homing stepper with a swtich on: November 27, 2012, 12:25:19 pm
Oh many answers!  smiley
But how am I going to prgoram it? Is there a tutorial on those RepRap machines?
5  Using Arduino / Programming Questions / Homing stepper with a swtich on: November 27, 2012, 12:07:56 pm
Hey!
I'm worink on a project where I'm gonna build a box that is sliding on a linear rail (very much like a CNC) using a stepper motor. I'm using an meny to determine the actions of the stepper motor, but i wont the stepper to "home" itself before it move to its first stop.

So my question is: Is it posible to make the stepper move until it triggers a switch before starting its actions?

Sorry if the question is bad formulated. It is to prevent the motor to start from a wrong point incase of the power shuts down in the middle of a previous action.

I'm using the library "accelstepper" to control the stepper. 
6  Using Arduino / Sensors / Re: Using a photoresistor to block menu with arduino! on: November 17, 2012, 04:06:39 am
Thank you very much! It helped alot, and now it's working  smiley
7  Using Arduino / Sensors / Re: Using a photoresistor to block menu with arduino! on: November 16, 2012, 10:18:01 am
Thanks for the help, but it's not really what im looking for.
When i press the a button on the menu, i want it to either "block" the menu and write "make it darker", but if its dark enough it will proceede to submenu.
I'm sorry if im pretty slow  smiley-confuse
8  Using Arduino / Sensors / Re: Using a photoresistor to block menu with arduino! on: November 16, 2012, 10:03:05 am
I am pretty new to programing, but I've figured out how to read the pin. The part I'm not sure is where to place de "decisions" depending on the value. And if i should be using "if" statement.
9  Using Arduino / Sensors / Using a photoresistor to block menu with arduino! on: November 16, 2012, 09:40:03 am
Hey guys!
Im doing a project in school where im using a menu on an LCD display and four buttons to navigate. The microcontroler im using is Arduino. I got the program for the LCD from http://www.coagula.org/content/pages/tutorial-manage-menu-and-lcd-display-arduino, and it is working perfectly! But i want to combine it with a photoresistor, so when i press a button and the value is to high, the screen will say "Make the room darker" or something like that. And if the value is low enough it will proceede to submenus.

Thanks!  smiley
Pages: [1]