i have a rotating table which listens to an "S" from serial. this "S" comes from a scannersoftware. when the table gets an "S" it moves 12 times. during this, the rotating table sends some characters to the scannersoftware to trigger some of its functions. when it made full 360 degrees it stops. and waits for another "S" of the scannersoftware.
the program of the turntable works. if i send an "S" with serial monitor, the table behaves as it should.
my problem with my code is that if the table gets another "S", while he is working, it will never stop again. unluckyly the scannersoftware does send additional "S" during its scanning process and i have no influence to change this.
so i am sure there is a simple way of for example let arduino listen to serial only on certain times or flush the lasersoftware "S" out of the communication but i am not clever enough to find it.
i am asking you nice people out there to help me. have a nice day.
void loop(){
if (Serial.available() >0){ // prüft ob Kommunikation möglich
Ser = Serial.read(); // com Port auslesen
}
if (Ser == 'S'){
delay(5000); // ersten Scan abwarten
Serial.println('3'); // auf Texturmenü springen
delay(1500); // warten
Serial.println('G'); // Textur aufnehmen
delay(1000); // warten
Serial.println('4'); // auf SL Menü springen
delay(1500); // warten
Serial.println('A'); // Scan zur Liste hinzufügen
for(int i=0;i<pos;i++){
step(true,stepstogo,500); // Schrittmotor zur nächsten Position bewegen
Serial.println('S'); // nächsten Scan beginnen
delay(5000); // Scan abwarten
Serial.println('3'); // für Textur vorbereiten
delay(1500); // warten
Serial.println('G'); // Textur aufnehmen
delay(1000); // warten
Serial.println('4'); // auf SL Menü springen
delay(1500); // warten
Serial.println('A'); // Scan zur Liste hinzufügen
}
}
}
thats what i also thought. i tried setting a variable Scan = 1 when the "S" was received. then i did put the whole turntable motion into an if Scan == 1 loop but it did not work.
is there another way to set a flag and work with it?
As an aside, having spent many years programming in Pascal, I do think it is done better there, using = for comparisons, and having a separate assignment operator.
Algol did it with a different assignment ( ":=" )operator long before Pascal, and, if you squint a little, looks a little like a mathematical assignment " <- "
Why K&R chose to ape Basic of all things with the "=" assignment, heaven knows.
got help in another forum but have to share here for other poor souls
the problem was using arduino 1.0 where some changes were made using serial communication. after this users tip i tried the code with arduino 23 and now serial.flush() works as expected.
keep in mind that arduino 1.0 reacts differently to arduino 0.23 when it comes to serial!
It is worth pointing out that at no point in this thread did you
A) mention which version you were using
B) mention that you were using a Serial.flush
C) post full code.