SoftwareServo, Switch Case und Sweeps?

Hey everyone and a happy new year to all of you!

Concerning Arduino and programing it for my purposes ... I´m a noob and always stay one! Right now I try to figure how to use Switch cases, since my code will have to do "something all the time" and some other stuff based on bluetooth input.
Right now I´m just happy that I can use bluetooth :wink: but this code now makes the servo go wild ... I know I still have to figure how to get rid of the delay and all ... but for now I hope someone can tell my the my servo is going back and forth when switching the case?

edit: just a side note: I´m stuck with SoftwareServo, because the neat VarSpeedServo and Servo libs are cutting me of from using pins 9&10 ...

#include <SoftwareSerial.h>
#include <SoftwareServo.h>

char val;
SoftwareServo myServo;


int strobes = (5);
int warp = (6);
int mains = (9);
int posi = (10);
int flood = (11);
int pos = 0;

long previousMillis = 0;

int bluetoothTx = 2;  // TX-O pin of bluetooth mate, Arduino D2
int bluetoothRx = 7;  // RX-I pin of bluetooth mate, Arduino D3
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

void setup()  { 
    Serial.begin(115200);
    bluetooth.begin(115200);
    analogWrite(flood, 1);
    analogWrite(posi, 1);
    analogWrite(mains, 10);
    analogWrite(warp, 255);
    bluetooth.begin(115200);
    myServo.attach(3);  
    myServo.write(pos);
} 

void loop()  { 
    if( bluetooth.available() )       // if data is available to read
    {
    val = bluetooth.read();         // read it and store it in 'val'
    }
    switch(val){
      case 'a':
      for(pos=0;pos<100;pos+=5)
      {
      myServo.write(pos);
      SoftwareServo::refresh();
      delay(30);
      }
      break;
      case 'b':
      for(pos=100;pos>0;pos-=5)
      {
      myServo.write(pos);
      SoftwareServo::refresh();
      delay(30);
      }
      break;
    }
}

I'm not really clear what your issue is. Guessing though, it looks like once you have sent 'a' the servo moves continuously and you only want it to once. This is because once you read something into val, it stays there until another character is there to pick up so every time round loop, the 'a' case is executed. A simple solution would be to set val to 'x' (or whatever) at the start of loop.

int strobes = (5);
int warp = (6);
int mains = (9);
int posi = (10);
int flood = (11);

(What's) (with) (all) (the) (useless) (parentheses) (?)

int bluetoothTx = 2;  // TX-O pin of bluetooth mate, Arduino D2
int bluetoothRx = 7;  // RX-I pin of bluetooth mate, Arduino D3

Are the comments wrong, or is the code?

The SoftwareServo::refresh() function needs to be called at least once every 20 milliseconds. delay(30) means that doesn't happen.

The comments are left overs. Sorry for that.

Even if I set the delay to something like 15, the servo goes wild even faster. Switching the case only causes to direction to reverse.
What I´m after is to set the servo angle based on BT input and have the speed controlled.

The stuff in the setup are just settings for Leds that need to be set once.