Go Down

Topic: starting the Windows media player from the UNO? (Read 3 times) previous topic - next topic

lydfanger

Hej Mikael

Jeg udnytter at jeg har "fanget" dig, til lige at spørge om en sidste ting. Håber du vil hjælpe mig...igen.

Når jeg sender Serial.println til dit program, får gobetwino koden mange gange, så efter "timeout" gentager programmet visningen af den bestemte fil. Jeg kan se det samme i "Serial overvågningen" så det er helt sikkert mine evner indenfor kode skrivning der halter.
Vil du kigge på Sketch'en, og  give et bud på hvor jeg kan sætte en bremse, så Serial.println... kun bliver sendt en gang?.
På forhånd tak.

int kon1 = 7;//kontakt1
int kon2 = 8;//kontakt2
int val1 = 0;
int val2 = 0;


void setup()
{
pinMode(kon1, INPUT);
pinMode(kon2, INPUT);
Serial.begin(9600);

}

void loop()

{
val1 = digitalRead(kon1);
val2 = digitalRead(kon2);

  val1 =!val1;
  val2 =!val2;
if (val1 == HIGH)
{
   Serial.println("#S|MUSIK1|[]#");
   delay(val1);
}
if (val2 == HIGH)
{
   Serial.println("#S|BILLED1|[]#");
   delay(val2);

}}

dxw00d

Guys, this is an English language forum, so please provide translations, so others can help, or be helped.

lydfanger

Sorry, you are right. So here is translation of the pre posting.

When i am sending Serial.println(XXXXXX) to my PC the "Code" is send many times, I just want the arduino to send it once.
I need something in the sketch to control the how many times Serial.println is send.
The sketch looks like this....

int kon1 = 7;//button1
int kon2 = 8;//button2
int val1 = 0;
int val2 = 0;

void setup()
{
pinMode(kon1, INPUT);
pinMode(kon2, INPUT);
Serial.begin(9600);
}
void loop()
{
val1 = digitalRead(kon1);
val2 = digitalRead(kon2);

  val1 =!val1;
  val2 =!val2;
if (val1 == HIGH)
{
   Serial.println("#S|MUSIK1|[]#");
   delay(val1);
}
if (val2 == HIGH)
{
   Serial.println("#S|BILLED1|[]#");
   delay(val2);
}


PaulS

Quote
When i am sending Serial.println(XXXXXX) to my PC the "Code" is send many times, I just want the arduino to send it once.


Then, you need to send only when a transition occurs, not whenever the state is HIGH or LOW.

Detecting a transition is simply a matter of comparing the current state of the switch with the previous state, If they are not the same, a transition occurred. At the end of loop(). set the previous state to the current state, ready for next time.

lydfanger

Hi PaulS

That make sense....thank you so far...

But, i am total NewBie...so is it possible that you could "challenge" me with some hints, of what to write in the sketch???  XD

Regards
LYDFANGER

Go Up