Results 1 to 8 of 8

Thread: Vixen 3 Servos Back and forth how to .

  1. #1
    Join Date
    Sep 2013
    Posts
    3
    Post Thanks / Like

    Default Vixen 3 Servos Back and forth how to .

    So far I have my Arduino Uno communicating with Vixen 3 with no problems , using SET LEVEL I of course can make the servo turn one way but not the other way . I am usually pretty good at figuring stuff out , but this one has gotten me stumped as I cant seem to find anything to help out. Last year I built a 3 axis skull controlled by thumb sticks and had a head set so when you talked its jaw would move ( sound threw speakers of course ) . This year I would like to animate it to a few songs . I kinda understand the values val1, 0, 255 , I thought the intensity lower value would be left and higher value would be right . Anyways Here is the Arduino code I am using to start out with for the first time.

    #include <Servo.h>
    Servo Pumpkin1;
    Servo Pumpkin2;
    Servo Pumpkin3;
    int pos = 0;

    int Chan1 = 3; //PWM-Servo 1
    int Chan2 = 5; //PWM-Servo 2
    int Chan3 = 6; //PWM-Servo 3
    int Chan4 = 9; //PWM-Light 1
    int Chan5 = 10; //PWM-Light 2
    int Chan6 = 11; //PWM-Light 3
    int Chan7 = 12; //extra
    int Chan8 = 13; //extra



    int i = 0; // Loop counter
    int incomingByte[8]; // array to store the 25 values from the serial port
    int val1;
    int val2;
    int val3;

    //setup the pins/ inputs & outputs
    void setup()
    {
    Serial.begin(9600); // set up Serial at 9600 bps

    pinMode(Chan1, OUTPUT);
    Pumpkin1.attach(3);
    pinMode(Chan2, OUTPUT);
    Pumpkin2.attach(5);
    pinMode(Chan3, OUTPUT);
    Pumpkin3.attach(6);
    pinMode(Chan4, OUTPUT);
    pinMode(Chan5, OUTPUT);
    pinMode(Chan6, OUTPUT);
    pinMode(Chan7, OUTPUT);
    pinMode(Chan8, OUTPUT);
    }

    void loop()
    { // 8 channels are coming in to the Arduino
    if (Serial.available() >= 8) {
    // read the oldest byte in the serial buffer:
    for (int i=0; i<9; i++) {
    // read each byte
    incomingByte[i] = Serial.read();
    }
    //Pumpkin1
    val1 = incomingByte[0];
    val1 = map(val1, 0, 255, 0, 45); //Change the last number according to how far you want the pumpkin to open.
    Pumpkin1.write(val1);
    delay(15);
    //Pumpkin2
    val2 = incomingByte[1];
    val2 = map(val2, 0, 255, 0, 45); //Change the last number according to how far you want the pumpkin to open.
    Pumpkin2.write(val2);
    delay(15);
    //Pumpkin3
    val3 = incomingByte[2];
    val3 = map(val3, 0, 255, 0, 45); //Change the last number according to how far you want the pumpkin to open.
    Pumpkin3.write(val3);
    delay(15);

    analogWrite(Chan4, incomingByte[3]); //Light 1
    analogWrite(Chan5, incomingByte[4]); //Light 2
    analogWrite(Chan6, incomingByte[5]); //Light 3
    digitalWrite(Chan7, incomingByte[6]); //Extras
    digitalWrite(Chan8, incomingByte[7]); //Extras
    }
    }

    Add TipAsk QuestionCommentDownload

  2. #2
    Join Date
    Dec 2011
    Posts
    5,800
    Post Thanks / Like

    Default Re: Vixen 3 Servos Back and forth how to .

    Code:
    if map(val1, 0, 255, 0, 45) // turns right
    
    map(val1, 0, 255, 0, 180)  // What will this do  ?
    Last edited by angus40; 08-12-2019 at 03:16 AM.

  3. #3
    Join Date
    Sep 2013
    Posts
    3
    Post Thanks / Like

    Default Re: Vixen 3 Servos Back and forth how to .

    Wow , I knew it would be something simple . to many times trying to figure it out when i was tired . I was also not fully paying attention to how much my servo was turning , so i taped a straw to it . I also struggled a bit what the numbers actually did ( 180 ) and I have a better understanding now seeing it live threw vixen . Thank you Thank you Thank you.

  4. #4
    Join Date
    Sep 2013
    Posts
    3
    Post Thanks / Like

    Default Re: Vixen 3 Servos Back and forth how to .

    Any chance getting some help on servo position . When I start vixen the servos will go right to 0 position (val1, 0, 255, 0, 180) . If I start at 90 this still only limits me to only left and or right (val1, 0, 255, 0, 90) . If I have Set level to 50% it will be at 90 but as soon as the sequence ends it will default to 0 . Of course I don't want my skull to only look left at a 180 turn, even for Halloween that would be to creepy LOL.

  5. #5
    Join Date
    Dec 2011
    Posts
    5,800
    Post Thanks / Like

    Default Re: Vixen 3 Servos Back and forth how to .

    Unfortunately I have not tested any of this .

    What does this do in your code ... int pos = 0 ?
    Last edited by angus40; 08-18-2019 at 05:39 AM.

  6. #6
    Join Date
    Dec 2011
    Posts
    5,800
    Post Thanks / Like

    Default Re: Vixen 3 Servos Back and forth how to .

    Ignore my previous post .

    This is one way of setting and maintaining the servo center position and is the coding route I will be pursuing for my project
    without complicating things using map and serial .

    Code:
    for(int i=0; i<chCount; i++) {
        // attach channels to pins
        servoCh[i].attach(chPin[i], usMin, usMax);
        // initial value = middle
        chVal[i] = (usMin + usMax)/2;
        // update
        servoCh[i].writeMicroseconds( chVal[i] )

  7. #7
    Join Date
    Oct 2011
    Location
    Scotland, UK
    Posts
    37
    Post Thanks / Like

    Default Re: Vixen 3 Servos Back and forth how to .

    Quote Originally Posted by PuppyBoy View Post
    Any chance getting some help on servo position . When I start vixen the servos will go right to 0 position (val1, 0, 255, 0, 180) . If I start at 90 this still only limits me to only left and or right (val1, 0, 255, 0, 90) . If I have Set level to 50% it will be at 90 but as soon as the sequence ends it will default to 0 . Of course I don't want my skull to only look left at a 180 turn, even for Halloween that would be to creepy LOL.
    The only way I can think to do it would be to code something that is there's no change in the data for a set amount of time, then go to a default position at 90deg.

  8. #8
    Join Date
    Dec 2011
    Posts
    5,800
    Post Thanks / Like

    Default Re: Vixen 3 Servos Back and forth how to .

    I tested this and it works with the servo defaulting to center position .
    It may give you some ideas to alter your code .

    Code:
    void loop() {
      // servo1 test
    int val = digitalRead(D5);
    int val1 = digitalRead(D6);
     if (val == HIGH && val1 == HIGH )  // No illumination data from sequencer
       position = (90);
       servo1.write(position);
     if (val == LOW) //  Yes sequence Data
       position = (178);
       servo1.write(position);
     if (val1 == LOW && val == HIGH) //  Yes sequence Data
       position = (0);
       servo1.write(position);
    Last edited by angus40; 08-18-2019 at 06:24 PM.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •