Bonjour C'est encore moi .
pour l'exemple no1 du message précèdent:
J'ai bien regardé la version avec statechangedetection mais je ne vois pas ou j'ai "oublié de changer lastboutonstate" désolé .
Avec simple bouton J'ai bien cru que tout était bon mais....
Quand je démarre le programme un item(0) est insérer automatiquement
Il y a aussi l'encoder incrémente à (0) mais ca ce n'est pas grave .
Donc quand la ligne avance J'ai automatiquement un item qui se balade avant que j'ai appuyé sur le bouton. sans ma modification simple bouton ca ne fessait pas ça .
je n'ai peut etre pas bien fait quelque chose mais je ne trouve pas ..
Vraiment désolé
excusez mon ignorance mais je veux comprendre ce que j'ai fait de travers.
merci
exemple avec Simple bouton
/*
Ce Programme est une simulation pour un convoyeur ayant quatres station situées
aux endroits 100, 200, 300 et 400.
A chaque fois qu'on veux mettre sur le convoyeur un 'Item' on pese sur le boutton 'Star'.
Dans cet exercice on suppose que sur le convoyeur on 4 Items au maximum.
Quatres LED simulent signalent le passage des items par chacune des quatres stations.
*/
#include <simpleBouton.h>
int Item_Conveyed=30;
bool start =0;
bool starts[30];
int counter[30];
int timer = 20;
const byte pinDepart = 3;
const byte pinTic = 2;
const int Station_Number1=4;
const int Station_Number2=12;
const int Station_Number3=15;
const int Station_Number4=22;
const int Station_Number5=30;
simpleBouton tic(pinTic);
simpleBouton boutonDepart(pinDepart);
//const int Station_Location[]={48, 127, 302, 645};
int ledPins[] = { 4, 5, 6, 7, 8 }; // We have four leds that Simulate the four stations are connected to the ports 2, 7, 4 and 6
int Station_Count = 5; // The number of Stations
int encoderState = 0;
void setup() {
// the ports 2, 7, 4 and have to be configured as outputs
for (int Station = 0; Station < Station_Count; Station++) {
pinMode(ledPins[Station], OUTPUT);
digitalWrite(ledPins[Station], HIGH);
}
pinMode(12, OUTPUT); // confirmation d'ajout d'ITEM
pinMode(9, OUTPUT); //this port simulate the pulses of the system
pinMode(3, INPUT_PULLUP); //This input port receive the start signal from the operator
pinMode(2, INPUT);// encoder
Serial.begin(9600);
// In the following for loop the Starts array as well as the counter Array are inilialised to zero
for (int j = 0; j < Item_Conveyed; j++) {
starts[j]=0;
counter[j]=0;
}
}
void loop() {
if (boutonDepart){ // here we chack if thge operator pressed on the Start Button
start=1;
delay(500);
}
if (start==1){
for (int i = 0; i < Item_Conveyed; i++) {
if(starts[i]==0){
starts[i]=1;
counter[i]=0;
digitalWrite(12, HIGH);
delay(150);
digitalWrite(12, LOW);
Serial.print("The Item Number is: ");
Serial.println(i);
start=0;
break;
}
}
}
if (tic) {
Serial.print("Position ");
Serial.println(counter[0]);
for (int k=0; k<Item_Conveyed; k++)
if (starts[k]==1){
if (tic == HIGH);
counter[k]++;
digitalWrite(9, HIGH);
delay(timer);
digitalWrite(9, LOW);
delay(timer);
switch (counter[k]) {
case Station_Number1:
Serial.print("Un Item No ");
Serial.print(k);
Serial.println(" est @ station 1");
digitalWrite(4, LOW);
delay(200);
digitalWrite(4, HIGH);
break;
case Station_Number2:
Serial.print("Un Item No ");
Serial.print(k);
Serial.println(" est @ station 2");
digitalWrite(5, LOW);
delay(200);
digitalWrite(5, HIGH);
break;
case Station_Number3:
Serial.print("Un Item No ");
Serial.print(k);
Serial.println(" est @ station 3");
digitalWrite(6, LOW);
delay(200);
digitalWrite(6, HIGH);
break;
case Station_Number4:
Serial.print("Un Item No ");
Serial.print(k);
Serial.println(" est @ station 4");
digitalWrite(7, LOW);
delay(200);
digitalWrite(7, HIGH);
break;
case Station_Number5:
Serial.print(" ByeBye!!! Item No ");
Serial.println(k);
Serial.println(" est @ station 5");
digitalWrite(8, LOW);
delay(200);
digitalWrite(8, HIGH);
starts[k]=0;
counter[k]=0;
break;
default:
// if nothing else matches, do the default
// default is optional
break;
}
}
delay(timer);
}
}
exemple précedent sans simple bouton sur le bouton ITEM
/*
*/
#include <simpleBouton.h>
int Item_Conveyed=30;
bool start =0;
bool starts[30];
int counter[30];
int timer = 20;
const byte pinTic = 2;
const int Station_Number1=4;
const int Station_Number2=12;
const int Station_Number3=15;
const int Station_Number4=22;
const int Station_Number5=30;
simpleBouton tic(pinTic);
//const int Station_Location[]={48, 127, 302, 645};
int ledPins[] = { 4, 5, 6, 7, 8 }; // We have four leds that Simulate the four stations are connected to the ports 2, 7, 4 and 6
int Station_Count = 5; // The number of Stations
int encoderState = 0;
void setup() {
// the ports 2, 7, 4 and have to be configured as outputs
for (int Station = 0; Station < Station_Count; Station++) {
pinMode(ledPins[Station], OUTPUT);
digitalWrite(ledPins[Station], HIGH);
}
pinMode(12, OUTPUT); // confirmation d'ajout d'ITEM
pinMode(9, OUTPUT); //this port simulate the pulses of the system
pinMode(3, INPUT_PULLUP); //This input port receive the start signal from the operator
pinMode(2, INPUT); //encoder
Serial.begin(9600);
// In the following for loop the Starts array as well as the counter Array are inilialised to zero
for (int j = 0; j < Item_Conveyed; j++) {
starts[j]=0;
counter[j]=0;
}
}
void loop() {
if (digitalRead(3)==1){ // here we chack if thge operator pressed on the Start Button
start=1;
delay(500);
}
if (start==1){
for (int i = 0; i < Item_Conveyed; i++) {
if(starts[i]==0){
starts[i]=1;
counter[i]=0;
digitalWrite(12, HIGH);
delay(150);
digitalWrite(12, LOW);
Serial.print("The Item Number is: ");
Serial.println(i);
start=0;
break;
}
}
}
if (tic) {
Serial.print("Position ");
Serial.println(counter[0]);
for (int k=0; k<Item_Conveyed; k++)
if (starts[k]==1){
if (tic == HIGH);
counter[k]++;
digitalWrite(9, HIGH);
delay(timer);
digitalWrite(9, LOW);
delay(timer);
switch (counter[k]) {
case Station_Number1:
Serial.print("Un Item No ");
Serial.print(k);
Serial.println(" est @ station 1");
digitalWrite(4, LOW);
delay(200);
digitalWrite(4, HIGH);
break;
case Station_Number2:
Serial.print("Un Item No ");
Serial.print(k);
Serial.println(" est @ station 2");
digitalWrite(5, LOW);
delay(200);
digitalWrite(5, HIGH);
break;
case Station_Number3:
Serial.print("Un Item No ");
Serial.print(k);
Serial.println(" est @ station 3");
digitalWrite(6, LOW);
delay(200);
digitalWrite(6, HIGH);
break;
case Station_Number4:
Serial.print("Un Item No ");
Serial.print(k);
Serial.println(" est @ station 4");
digitalWrite(7, LOW);
delay(200);
digitalWrite(7, HIGH);
break;
case Station_Number5:
Serial.print(" ByeBye!!! Item No ");
Serial.println(k);
Serial.println(" est @ station 5");
digitalWrite(8, LOW);
delay(200);
digitalWrite(8, HIGH);
starts[k]=0;
counter[k]=0;
break;
default:
// if nothing else matches, do the default
// default is optional
break;
}
}
delay(timer);
}
}
:-[