Need Help Using a V2 Module To Control A Servo

Hello everyone, I’m very new to Arduino (just got the board last Tuesday). I’m trying to use a V2 Voice module to control a servo and move that servo to different positions. So far just building up to this moment I made a simple code that let’s me control a servo to 3 positions using 3 input switches. I also learned how to program the V2 module and control some leds. Now I want to control that servo with the outputs from the V2 module. If anyone can take a look at my code I’d greatly appreciate it. I’ve been stuck for a few hours.

Problem Code below: (I’ll attach my two codes separately that I’m trying to merge together)

int button7= 9;
int button6= 10;
int button5= 11;

int redPin = 9;
int greenPin = 10;

int bluePin = 11; byte

com = 0; //reply from voice recognition

#include <Servo.h>

Servo myservo;
int pos=0;

void setup() { Serial.begin(9600);

pinMode(redPin, INPUT);

pinMode(greenPin, INPUT);

pinMode(bluePin, INPUT);

myservo.attach(5);

delay(2000);

Serial.write(0xAA);

Serial.write(0x37);

delay(1000);

Serial.write(0xAA);

Serial.write(0x21);

}

void loop()

{

while(Serial.available())

{

com = Serial.read();

switch(com)

{

case 0x11:

digitalWrite(redPin, HIGH);

button7=digitalRead(redPin);
button6=digitalRead(greenPin);
button5=digitalRead(bluePin);

if(button7==1 && button6==1 && button5==1)
myservo.write(0);

if(button7==1 && button6==0 && button5==1)
myservo.write(90);

if(button7==0 && button6==1 && button5==1)
myservo.write(145);

if(button7==1 && button6==1 && button5==0)
myservo.write(180);

break;

case 0x12:

digitalWrite(greenPin, HIGH);

button7=digitalRead(redPin);
button6=digitalRead(greenPin);
button5=digitalRead(bluePin);

if(button7==1 && button6==1 && button5==1)
myservo.write(0);

if(button7==1 && button6==0 && button5==1)
myservo.write(90);

if(button7==0 && button6==1 && button5==1)
myservo.write(145);

if(button7==1 && button6==1 && button5==0)
myservo.write(180);

break;

case 0x13:

digitalWrite(bluePin, HIGH);

button7=digitalRead(redPin);
button6=digitalRead(greenPin);
button5=digitalRead(bluePin);

if(button7==1 && button6==1 && button5==1)
myservo.write(0);

if(button7==1 && button6==0 && button5==1)
myservo.write(90);

if(button7==0 && button6==1 && button5==1)
myservo.write(145);

if(button7==1 && button6==1 && button5==0)
myservo.write(180);

break;

case 0x14:

digitalWrite(redPin, HIGH);

button7=digitalRead(redPin);
button6=digitalRead(greenPin);
button5=digitalRead(bluePin);

if(button7==1 && button6==1 && button5==1)
myservo.write(0);

if(button7==1 && button6==0 && button5==1)
myservo.write(90);

if(button7==0 && button6==1 && button5==1)
myservo.write(145);

if(button7==1 && button6==1 && button5==0)
myservo.write(180);

digitalWrite(greenPin, HIGH);

button7=digitalRead(redPin);
button6=digitalRead(greenPin);
button5=digitalRead(bluePin);

if(button7==1 && button6==1 && button5==1)
myservo.write(0);

if(button7==1 && button6==0 && button5==1)
myservo.write(90);

if(button7==0 && button6==1 && button5==1)
myservo.write(145);

if(button7==1 && button6==1 && button5==0)
myservo.write(180);

digitalWrite(bluePin, HIGH);

button7=digitalRead(redPin);
button6=digitalRead(greenPin);
button5=digitalRead(bluePin);

if(button7==1 && button6==1 && button5==1)
myservo.write(0);

if(button7==1 && button6==0 && button5==1)
myservo.write(90);

if(button7==0 && button6==1 && button5==1)
myservo.write(145);

if(button7==1 && button6==1 && button5==0)
myservo.write(180);

break;

case 0x15:

digitalWrite(redPin, LOW);

button7=digitalRead(redPin);
button6=digitalRead(greenPin);
button5=digitalRead(bluePin);

if(button7==1 && button6==1 && button5==1)
myservo.write(0);

if(button7==1 && button6==0 && button5==1)
myservo.write(90);

if(button7==0 && button6==1 && button5==1)
myservo.write(145);

if(button7==1 && button6==1 && button5==0)
myservo.write(180);

digitalWrite(greenPin, LOW);

button7=digitalRead(redPin);
button6=digitalRead(greenPin);
button5=digitalRead(bluePin);

if(button7==1 && button6==1 && button5==1)
myservo.write(0);

if(button7==1 && button6==0 && button5==1)
myservo.write(90);

if(button7==0 && button6==1 && button5==1)
myservo.write(145);

if(button7==1 && button6==1 && button5==0)
myservo.write(180);

digitalWrite(bluePin, LOW);

button7=digitalRead(redPin);
button6=digitalRead(greenPin);
button5=digitalRead(bluePin);

if(button7==1 && button6==1 && button5==1)
myservo.write(0);

if(button7==1 && button6==0 && button5==1)
myservo.write(90);

if(button7==0 && button6==1 && button5==1)
myservo.write(145);

if(button7==1 && button6==1 && button5==0)
myservo.write(180);

break;

}

}

}

Sorry here’s my two codes that work, that I’m trying to merge together.

Working Codes.doc (30 KB)

Why did you start a new thread?

PaulS: Why did you start a new thread?

In fact.... closing here...