program not responding

Hey, I have a working program that is wroking just the way I want.
However, i made a slightly changed version that doesnt work. I just replaced one condition for a case in a switch. My question is why? The robot doesnt respond to any signals sent to arduino from bt module in the second version of program. It just doesnt do anything. Any help would be appreciated.

This is just a small part of the whole program

Version that is working:

if (Serial.available() > 0) {         // zápis prijatých dát z BT do premennej prijateData
    prijateData = Serial.read();
  }

  if (pocetCyklov >= 200) {             // prepnutie do manuálneho ak počet cyklov programu pri stratenej čiare >= 100
    manualnyRezim();
    Serial.println(5);
    pocetCyklov = 0;
  }

  if (prijateData == '8') {                  // po prijatí signálu sa čas aktualizuje
    cas = millis();
    prijateData = 0;
  }

  if ( millis() > (cas + oneskorenie)) {      // ak je aktuálny čas > čas zaznamenaný po prijatí signálu + oneskorenie, robot sa vypne
     manualnyRezim();
  }

  switch (prijateData) {

    case '1':
      manualnyRezim();
      break;

    case '2':
      sledovanieCiary();
      break;

    case '3':
      hladanieTrasy();
      break;

    case '4':
      rychlost80();
      break;

    case '5':
      rychlost100();
      break;

    case '6':
      rychlost120();
      break;

    case '7':
      rychlost200();
      break;
  }

Version that doesnt work:

if (Serial.available() > 0) {         // zápis prijatých dát z BT do premennej prijateData
    prijateData = Serial.read();
  }

  if (pocetCyklov >= 200) {             // prepnutie do manuálneho režimu ak počet cyklov programu pri stratenej čiare >= 200
    manualnyRezim();
    Serial.println(5);
    pocetCyklov = 0;
  }

  if ( millis() > (cas + oneskorenie)) {      // ak je aktuálny čas > čas zaznamenaný po prijatí signálu + oneskorenie, robot sa vypne
    manualnyRezim();
  }

  switch (prijateData) {

    case '1':
      manualnyRezim();
      break;

    case '2':
      sledovanieCiary();
      break;

    case '3':
      hladanieTrasy();
      break;

    case '4':
      rychlost80();
      break;

    case '5':
      rychlost100();
      break;

    case '6':
      rychlost120();
      break;

    case '7':
      rychlost200();
      break;

    case '8':                         // aktualizácia času
      cas = millis();
      break;
  }

In the working program you give the value of millis() to cas near the top.

In the non-working program it is only given in a certain situation - perhaps that situation never arises.

You really need to post complete programs so we can see how variables are defined and whether they get initial values. And what the other functions do.

...R

Here is the full program of both versions. The working one is the 1.2
im pretty sure that situation should happen every 500 ms like in the first version

robot_gen1.2_kompletDC.ino (15.3 KB)

robot_gen1.3.ino (15.2 KB)

You did forget to reset this in your Case '8'.

 prijateData = 0;

And does this modify prijateData before it gets checked if it's '8'?

if ( millis() > (cas + oneskorenie)) {      // ak je aktuálny čas > čas zaznamenaný po prijatí signálu + oneskorenie, robot sa vypne
     manualnyRezim();
  }

Also, this got changed from version 1.2 to 1.3. (Line 743)

(vzdialenostP > vzdialenostL)

mafokken:
You did forget to reset this in your Case '8'.

 prijateData = 0;

And does this modify prijateData before it gets checked if it's '8'?

if ( millis() > (cas + oneskorenie)) {      // ak je aktuálny čas > čas zaznamenaný po prijatí signálu + oneskorenie, robot sa vypne

manualnyRezim();
  }






Also, this got changed from version 1.2 to 1.3. (Line 743)


(vzdialenostP > vzdialenostL)

Yes, I first tried it with resetting it and now without it, either doesnt work.

Yes it sets them to 0. But that condition should not be met if bt is connected. as it is not in the first version.

Yeah I changed that but that doesnt concern my problem in any way. im positive it doesnt affect the problem

i think i see why you made the change, to make processing more consistent, that all inputs are handled within the switch statement. this makes sense

in the 1.2 version, when prijateData is 8 and cas reset, the condition that millis() > cas + is not likely to be true and manualnyRezim() is no invoked. in the 1.3 version, this might be true the next iteration, which again make sense.

i wonder if ver 1.2 was really working correctly. the conditional execution of manualnyRezim() after a second, when pocetCyklov > 200 and when prijateData == 1 doesn't seem right. could it actually be called 3 times in one iteration.

and i think millis() should only be called once per iteration (i.e. unsigned long msec = millis()) and use msec whereever you need time.

but it's not clear what is not working. can you explain what must not be being invoked that causes "It just doesnt do anything"

gcjr:
i think i see why you made the change, to make processing more consistent, that all inputs are handled within the switch statement. this makes sense

in the 1.2 version, when prijateData is 8 and cas reset, the condition that millis() > cas + is not likely to be true and manualnyRezim() is no invoked. in the 1.3 version, this might be true the next iteration, which again make sense.

i wonder if ver 1.2 was really working correctly. the conditional execution of manualnyRezim() after a second, when pocetCyklov > 200 and when prijateData == 1 doesn't seem right. could it actually be called 3 times in one iteration.

and i think millis() should only be called once per iteration (i.e. unsigned long msec = millis()) and use msec whereever you need time.

but it's not clear what is not working. can you explain what must not be being invoked that causes "It just doesnt do anything"

manualnyRezim(); cant happen at once with for both conditions for pocetCyklov>=200 and prijate data == 1
since those are happening in 2 different switch cases.

Sure, after a second manualnyRezim can happen twice, with both of the above cases, but It doesnt to seem to interrupt the program at all in the version 1.2

It is working correctly, the robot does respond to control from bt(prijateData cases) but in second version it doesnt respond at all. It is not responding to the prijateData from bt