Hey guys, I need help, I’m working on a project with a deadline and I need to combine two codes. The first is a simple button that lights up a LED, push on for on, it stays on, then push again, and it turns off (or vice versa). I have the script below. The tricky bit for me is the next code (also see below), so when I push that button, I want the next code to also initiate in sequence. Basically, I push a button, thew LED lights up, it runs a motor that pushes a shelf, and then returns to its original position for the next shelf. PLEASE help me guys, I am not a programmer and really need some brains to help me
//Button toggle, when the button is pressed and afterwards released
//the LED stays on until the button is pressed once again
int led = 13;
int button = 12;
int ledState = HIGH;
int buttonCurrent;
int buttonPrevious = LOW;
void setup ()
{
pinMode(button, INPUT);
pinMode(led, OUTPUT);
}
void loop()
{
buttonCurrent = digitalRead(button);
if (buttonCurrent == HIGH && buttonPrevious == LOW)
{
if (ledState == HIGH)
{
ledState = LOW;
}
else
{
ledState = HIGH;
}
}
digitalWrite(led, ledState);
buttonPrevious = buttonCurrent;
}
Next Code for motor pushing shelf and returning……………..
// defines pins numbers
const int stepPin = 5;
const int dirPin = 2;
const int enPin = 8;
void setup() {
// Sets the two pins as Outputs
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
pinMode(enPin,OUTPUT);
digitalWrite(enPin,LOW);
}
void loop() {
digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
// Makes 200 pulses for making one full cycle rotation
for(long int x = 0; x < 244500; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(70);
digitalWrite(stepPin,LOW);
delayMicroseconds(70);
}
delay(1000000); // One second delay
}