Loading...
  Show Posts
Pages: 1 ... 9 10 [11]
151  Using Arduino / Storage / Re: how to store different values of a pot to be called up latter? on: March 19, 2012, 10:15:59 am
So then, if I understand correctly you need to create variables containing the values (i.e. servo positions) and than create an "if.. else if" structure corresponding to each switch that is being pressed. Each switch sends out a different value to the servo. Seems fairly easy. BTW you can check my progress on my code over here:http://arduino.cc/forum/index.php/topic,96056.0.html. This could maybe help you
152  Using Arduino / Motors, Mechanics, and Power / Re: record data from potentiometer & playback to servo on: March 19, 2012, 03:51:39 am
whoops, let me try again...
 smiley-red

Code:
// Controlling a servo position using a potentiometer (variable resistor)
// with the option of recording the movement, playing it in reverse and in original order.
// Adi Soffer 19.3.12

#include <Servo.h>
 
   Servo myservo;               // create servo object to control a servo
   char buffer [5];              //variable to hold keystrokes
   int potpin = 0;                // analog pin used to connect the potentiometer
   int val;                          // variable to read the value from the analog pin
   int servoPos[300];           //create array 300 values for servo position
   int incomingByte;            //declare variable to hold incoming letter

 
  void setup()
{
     Serial.begin(9600);
     Serial.flush();
     myservo.attach(3);           // attaches the servo on pin 3 to the servo object
 }


  void loop ()
{
   if (Serial.available( ) > 0)
 {
       incomingByte = Serial.read ( );
       if (incomingByte == 'F')
  {
          Serial.println ("Free mode");
          while (incomingByte == 'F')
    {
          val = analogRead (potpin);
          val = map(val, 0, 1023, 0, 179);
          myservo.write (val);
          delay (10);
          if (Serial.available ( ) > 0)
      {
            incomingByte = Serial.read ( );
            if (incomingByte == 'R')
         {
              Serial.println ("Record inside");                  // if so - prints record inside for checkup
              delay(15);
              for (int i=0;i<299;i++)                              //for loop to store 300 values of pot  
           {
              val = analogRead(potpin);                         // reads the value of the potentiometer (value between 0 and 1023)
              val = map(val, 0, 1023, 0, 179);                // scale it to use it with the servo (value between 0 and 180)
              myservo.write(val);                                 // sets the servo position according to the scaled value
              servoPos [i]=val;                                     // stores val in array "servoPos
              delay(15);                                              // waits for the servo to get there
              Serial.println(val);                                   // print values for checking
           }    
         }
           else if (incomingByte == 'H')
       {
            Serial.println ("Home inside");
            //delay(15);
            for (int i=299;i>0;i--)
         {
              myservo.write (servoPos[i]);           //reads values from array in reverse to servo
              delay(15);
              Serial.println (servoPos[i]);
         }
        }  
           else if (incomingByte = 'P')
        {
             Serial.println ("Playback inside");       // if so prints for checkup
             //delay(15);
             for (int i=0;i<299;i++)
          {
               myservo.write (servoPos[i]);          //reads values from array in original order to servo
               delay (15);
               Serial.println (servoPos[i]);
           }
         }    
       }  
     }
   }  
          else if (incomingByte == 'R')                // checks if input was capital R
        {                      
            Serial.println ("Record");                   // if so - prints record
            delay(15);
            for (int i=0;i<299;i++)                      //for loop to store 300 values of pot  
         {
              val = analogRead(potpin);               // reads the value of the potentiometer (value between 0 and 1023)
              val = map(val, 0, 1023, 0, 179);      // scale it to use it with the servo (value between 0 and 180)
              myservo.write(val);                       // sets the servo position according to the scaled value
              servoPos [i]=val;                           // stores val in array "servoPos
              delay(15);                                    // waits for the servo to get there
              Serial.println(val);                         // print values for checking
         }  
        }
 
          else if (incomingByte == 'H')
       {
            Serial.println ("Home");
            //delay(15);
            for (int i=299;i>0;i--)
         {
              myservo.write (servoPos[i]);           //reads values from array in reverse to servo
              delay(15);
              Serial.println (servoPos[i]);
         }
        }
      
          else if (incomingByte = 'P')
        {
             Serial.println ("Playback");
             //delay(15);
             for (int i=0;i<299;i++)
          {
               myservo.write (servoPos[i]);          //reads values from array in original order to servo
               delay (15);
               Serial.println (servoPos[i]);
           }
         }
 }
}
153  Using Arduino / Motors, Mechanics, and Power / Re: record data from potentiometer & playback to servo on: March 19, 2012, 02:44:16 am
Hey. I guess phase 1 is done. I'm able to control, record, play in reverse and play in original order.
Now it's controlled through serial monitor and my next phase is to control it with 4 switches.

I'm attaching the code and would appreciate remarks. Remember - I'm a complete noob, so please don't be too hard on me..
Edit - code attached as should be in my next post...
154  Using Arduino / Storage / Re: how to store different values of a pot to be called up latter? on: March 19, 2012, 12:31:23 am
ElChiguete I would be happy to assist. Since I'm new at this I can only hope to be able to help. Let's do this here so all can benefit.  smiley
155  Using Arduino / Motors, Mechanics, and Power / Re: record data from potentiometer & playback to servo on: March 17, 2012, 05:17:38 am
update:
1. Yes I can.
2&3 - would still appreciate a pointer or two.

 smiley
156  Using Arduino / Storage / Re: how to store different values of a pot to be called up latter? on: March 17, 2012, 05:15:48 am
update: figured it out!  smiley-grin I'm very pleased with myself... smiley-wink
Now I'm trying to figure out how to call the array in its different order using a switch.
157  Using Arduino / Storage / Re: how to store different values of a pot to be called up latter? on: March 17, 2012, 01:48:57 am
Hey guys, this thread seems relevant to me and I'm kind of getting lost here - I'm following all the links and reading the references... So I'd like to introduce my challenge and would appreciate a few pointers to help me sort the relevant things for me. I'm trying to "record" pot movement into an array, while using the data to move a servo. Then I wish to recall the data from the array (with a switch) and re create the same movement of the servo (i.e. move it again in the exact manner). What I can't wrap my around is how to create a process that stacks the continuous data from the servo into the array. I hope my "intrusion" into this thread is fine - It seems relevant here, right?  smiley-slim
thank you.
158  Using Arduino / Motors, Mechanics, and Power / Re: record data from potentiometer & playback to servo on: March 15, 2012, 02:27:17 pm
My project is slowly progressing (actually I should say I'M slowly progressing...) and my 3 questions are:
1. Is it possible to store the pot data into an array while at the same time send it over to the servo? This way I can both see what I'm doing and "record" the info for later retrieval.
2. In this project I'm expanding on the Knob sketch, adding the array in order to record. I want to be able to begin , stop and playback this recording using buttons. This means putting some "If" structures into the main loop of the sketch. Will this make my reading from the pot and writing to the servo slower (because the code will check to see if the button is pressed)? Should I use another structure? Is Interrupt better suited for this?
3. By other structure I mean maybe 2 loops that can be switched between by a button. Is that even possible?

Thanks  
159  Using Arduino / Motors, Mechanics, and Power / Re: record data from potentiometer & playback to servo on: March 11, 2012, 08:53:43 am
wildbill thanks a lot!
Will read, understand, try and reply!
 smiley-wink
160  Using Arduino / Motors, Mechanics, and Power / Re: record data from potentiometer & playback to servo on: March 11, 2012, 08:03:12 am
Hey wildbill, thanks for the reply.
Indeed I want the playback to be at the same speed as the real event...
This seems too complicated for my stage at this  smiley-red

As for the first part of your answer, is there a sample of a sketch that utilizes the technique you mentioned?
I'm a real noob at this...
161  Using Arduino / Motors, Mechanics, and Power / record data from potentiometer & playback to servo on: March 11, 2012, 01:39:36 am
Hello everyone. First of all, I'm new at this and this is an amazing technology and supporting community!  smiley
For the last month I've been reading stuff and working on my 1st project and the amount of info given here is great.

Now for my question (I've looked around but wasn't able to find answers):
Using the Knob sketch I'm building a Follow Focus for my camera.
what I'm trying to figure out is how be able to add a "Record" function to the code.
What I mean is to have the ability to to push a button telling to Arduino to record my potentiometer data
(as I move it, the servo of course moves and changes the focus on my camera),
than "stop" the recording and play it back causing the servo to repeat (once)
the movement and timing of my "focus pulling".

I would appreciate any advice, or if someone could point me to a relevant link.
Pages: 1 ... 9 10 [11]