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 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;
}
}