Programming Motor shield and 3 LEDs and a push button

Hello geeks,

Can you help me to program a motor shield with three LEDs and a push button, and limit sensor.

Actions:

  • after pressing the push button, start the engine (clockwise);
    (during this action an LED flashes).

-The motor stops when the end of travel sensor detects the end of position, the LED stops flashing.

-When a new press the motor works in the other direction (counter-clockwise), and the other limit switch does the same (stops the motor); The same LED flashes, and also stops when the sensor detects.

during this action an LED flashes

How many times do you think the LED will flash in the time it takes the pin to go HIGH?

and the other limit switch does the same

What other limit switch? You said you have ONE limit switch.

If the limit switches stop the motor without you having to do anything, you REALLY need to post a schematic showing how they are wired.

Hi thanks for ur reply, We have done a program with a push button n 2 LED, n motor shield, Can u help me fix it?

int pinBouton;
void setup()
{
Serial.begin(9600);
pinBouton=10;
pinMode(pinBouton,INPUT);
}
void loop()
{
boolean etatBouton=digitalRead(pinBouton);
Serial.println(etatBouton);
}

// LES DECLARATIONS
int bouton = 8; // pin 8 bouton poussoir
int valeur_bouton = 0; // variable pour enregistrer l'état du bouton
int valeur_precedante_bouton = 0; // variable pour enregistrer l'ancien état du bouton
int led_rouge = 13; // pin 13 led rouge
int led_verte = 12; // pin 12 led verte
int compteur = 0; // variable du compteur
int fin_de_course_1 = 42; // pin 42 contact fin de course

#include <Stepper.h>

//pour un moteur de 200 pas par tour et brancher sur les broches 2, 3, 4, 5
Stepper moteur(200, 5, 3, 4, 2);

boolean premiereFois = false;
boolean premiereFois2 = false;

void setup() {
pinMode(led_rouge, OUTPUT); // pin en sortie
pinMode(led_verte, OUTPUT); // pin en sortie
pinMode(bouton, INPUT); // pin en entrée
pinMode(fin_de_course_1, INPUT); // pin en entrée

moteur.setSpeed(16); // Vitesse 30 tours par minute
}

void loop() {

boolean etatfincourse_1 = digitalRead(fin_de_course_1); //lecture du contact fin de course

//UN APPUI SUR LE BOUTON ALLUME UN NOUVEL APPUI SUR LE BOUTON ETEINT
valeur_bouton = digitalRead(bouton); // interrogation du bouton poussoir, la valeur précédante est elle différente de la valeur l'actuelle?

if (valeur_precedante_bouton != valeur_bouton) {
if (valeur_bouton == HIGH) {
compteur++; // On incrémente le compteur (+1 à chaque appui)

}
}
valeur_precedante_bouton = valeur_bouton; // sauvegarder la valeur actuelle du bouton

if (etatfincourse_1 == HIGH) //si contact fermé

if (compteur % 2 == 0) // on incrémente la variable compteur à chaque boucle
// le signe %indique diviser voir tableau page 264, le résultat est soit pair (0) ou impair (1)
// traduction du code: SI(compteur pair (0) ecrire digitalWrite(led_rouge,HIGH)
{ // SINON il est donc de (1) et dans ce cas c'est l'instruction digitalWrite(led_rouge, LOW)
digitalWrite(led_rouge, HIGH);

if (!premiereFois) {
moteur.step(270); // angle de rotation
premiereFois = true; // stop le moteur après la première phase
premiereFois2 = false; // initialise pour la phase 2

}
}

else
digitalWrite(led_rouge, LOW);

if (compteur % 2 == 1) // le signe %indique diviser voir tableau page 264, le résultat est soit pair (0) ou impair (1)
// traduction du code: SI(compteur impair (1) ecrire digitalWrite(led_verte,HIGH)
// SINON il est donc de (0) et dans ce cas c'est l'instruction digitalWrite(led_verte, LOW)

{
digitalWrite(led_verte, HIGH);

if (!premiereFois2) {
moteur.step(-270); // angle de rotation
premiereFois2 = true; // stop le moteur après la deuxième phase
premiereFois = false; // initialise pour la phase 1

}
}

else
digitalWrite(led_verte, LOW);

}

Can u help me fix it?

Maybe. How is it broken?

In fact, we are novice, n we took this program on the web, n Can u help me for that?? I want just a example, Thanks