Show Posts
Pages: 1 ... 9 10 [11] 12
151  Using Arduino / Project Guidance / Re: how to create an array with both members and number of members undefined on: March 24, 2012, 05:56:45 am
Rob - thank you, I'll try and implement this.
Thank you very much!
 smiley
152  Using Arduino / Project Guidance / Re: how to create an array with both members and number of members undefined on: March 24, 2012, 03:40:31 am
Rob - I may have explained badly what I need - what you kindly wrote is already in my code. I'm attaching it here so you can see:

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
   const int valNumber = 500;                   //variable to contain number of array members
   int incomingByte;                                  //declare variable to hold incoming letter
   int servoPos[valNumber];                    //create array of values for servo position
   const int waitForServo = 15;               //delay time to let servo get to position
   int recordModeLed = 3;                              // defining pins for ui leds
   int homeModeLed = 4;
   int playModeLed = 5;
   int freeModeLed = 6;
   int freeSwitch = 7;                                 //defining pins for switches
   int recSwitch = 8;
   int homeSwitch = 9;
   int playSwitch = 10;
   

 
  void setup()
{
     Serial.begin(9600);
     Serial.flush();
     myservo.attach(2);                                                   // attaches the servo on pin 2 to the servo object
     pinMode (freeModeLed, OUTPUT);                         //defining LED pins as output
     pinMode (recordModeLed, OUTPUT);
     pinMode (homeModeLed, OUTPUT);
     pinMode (playModeLed, OUTPUT);
     pinMode (freeSwitch, INPUT);                              //defining switch pins as input
     pinMode (recSwitch, INPUT);
     pinMode (homeSwitch, INPUT);
     pinMode (playSwitch, INPUT);
     
 }


  void loop ()
{
   
  digitalWrite (freeModeLed, LOW);
  digitalWrite (recordModeLed, LOW);
  digitalWrite (homeModeLed, LOW);
  digitalWrite (playModeLed, LOW);
 
  if (Serial.available( ) > 0)
 {
       incomingByte = Serial.read ( );
       if (incomingByte == 'f')
  {
          Serial.println ("Free mode");
          while (incomingByte == 'f')
    {
          digitalWrite (freeModeLed, HIGH);
          val = analogRead (potpin);
          val = map(val, 0, 1023, 0, 179);
          myservo.write (val);
          delay (waitForServo);
          if (Serial.available ( ) > 0)
      {
            incomingByte = Serial.read ( );
            if (incomingByte == 'r')
         {
             recordFunction ( );   
         }
           else if (incomingByte == 'h')
       {
           reverseFunction ( );
        }   
           else if (incomingByte = 'p')
        {
             playBackFunction ( );
         }   
       } 
     }
   } 
          else if (incomingByte == 'r')                   // checks if input was r
        {                       
           recordFunction ( );
        }
           else if (incomingByte == 'h')
       {
           reverseFunction ( );
        }
                 else if (incomingByte = 'p')
        {
           playBackFunction ( );
           }
        }
      }

void playBackFunction ( )
       {
         digitalWrite (freeModeLed, LOW);
          digitalWrite (playModeLed, HIGH);
          Serial.println ("Playback Function");
            for (int i=0;i<(valNumber - 1);i++)
          {
             myservo.write (servoPos[i]);                    //reads values from array in original order to servo
             delay (waitForServo);
             Serial.println (servoPos[i]);
          }
           digitalWrite (playModeLed, LOW);   
       }

 void reverseFunction ( )
      {
            digitalWrite (freeModeLed, LOW);
            digitalWrite (homeModeLed, HIGH);
            Serial.println ("Home function");
            for (int i=(valNumber - 1);i>0;i--)
          {
             myservo.write (servoPos[i]);                   //reads values from array in reverse to servo
             delay(waitForServo);
             Serial.println (servoPos[i]);
          }
          digitalWrite (homeModeLed, LOW);
       }
     
void recordFunction ( )
{
           for (int c=6;c>3;c --)                                     // three sec countdown to recording
           {
             digitalWrite (recordModeLed, HIGH);
             digitalWrite (c, HIGH);
             delay (700);
             digitalWrite (recordModeLed, LOW);
             digitalWrite (c, LOW);
             delay(300);
           }
           digitalWrite (recordModeLed, HIGH);
           Serial.println ("Record function");            // if so - prints record
           for (int i=0;i<(valNumber - 1) ;i++)                //for loop to store declared 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(waitForServo);                                      // waits for the servo to get there
              Serial.println(val);                                       // print values for checking
         } 
         digitalWrite (recordModeLed, LOW);
}

In my code the "timing" of the recording function is predefined by the index number. What I'm trying to do is to be able to stop the recording when I decide externally - with a key stroke for example - and not just when the predefined 500 cycle ends. Than, if I stopped the cycle, I need the array to have an index number correct.

Did I manage to explain myself this time? I think most of you do this thing I'm trying to figure out off hand, which may explain why my question might seem redundant.   
153  Using Arduino / Project Guidance / Re: how to create an array with both members and number of members undefined on: March 24, 2012, 02:58:27 am
Hey Rob and nick, thank you for your replies.
I will check further.

Rob - I'll use the internal memory since the maximum members will not surpass 500 integers.
Since I'm new at this your explanation seems a bit abstract to me. Could you point to a specific sketch implementing this?

Nick - I'll search for the STL - hoping I'll understand how to implement it.
EDIT: just checked STL - seems way over my head right now... smiley-red

Thanks again
 smiley
154  Using Arduino / Project Guidance / how to create an array with both members and number of members undefined on: March 24, 2012, 01:42:51 am
Hi all.
The title may be misleading but I couldn't any better way to describe my question in a single line   smiley
I suspect this to be an easy one for most of you but I'm still a noob...
The thing is I'm building a system that enables me to control a servo, record my data and play it back in several ways
(you can see my ongoing progress here :http://arduino.cc/forum/index.php/topic,96056.0.html).

What I want to do (and couldn't find an answer) is not to limit my array to contain a certain amount of members, but to let my actions later on in the program decide that number for me.

for example: once I click "rec" an array is formed and ends when I click again. from now on, until I record again, this is the array and this is the number of its members.

hope I made my question clear and would appreciate some guidance! 
155  Using Arduino / Motors, Mechanics, and Power / Re: record data from potentiometer & playback to servo on: March 23, 2012, 11:30:34 am
Aha! Now I got your meaning. you're looking for an interfacing "something" to grab you data and spit it into the arduino... interesting.
156  Using Arduino / Motors, Mechanics, and Power / Re: record data from potentiometer & playback to servo on: March 23, 2012, 09:27:21 am
@ sbright33 - I'm afraid you misunderstood me... I'm simply a director building my own camera rigs for fun, not a motion control specialist... smiley-wink
What I can say is that from what I'm reading people are coding the arduino to smooth the arrays of data - thus smoothing the motion. HOp that helps  smiley-grin
157  Using Arduino / Motors, Mechanics, and Power / Re: record data from potentiometer & playback to servo on: March 23, 2012, 09:22:55 am
OK - things are looking good and I've even written code for using my LEDs as a countdown till record and so forth...  smiley-grin
Now here's a question I can't seem to find an answer to, probably since it's too simple, and I would very much appreciate an insight...

I'm rewriting the code so that instead of key strokes, switches will operate the different functions, and I'm constantly reading about the Debounce thing - BUT - if I simply with to use my switches not as toggles, just when I press one a function goes on, do I still need this debouncing trick? just to make it clear I'm attaching my updated code, still with keystrokes. Except for the "free mode" all other function are self terminating and for them I need to use the switch simply as a trigger.
Thank you.


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
   const int valNumber = 500;                   //variable to contain number of array members
   int incomingByte;                                  //declare variable to hold incoming letter
   int servoPos[valNumber];                    //create array of values for servo position
   const int waitForServo = 15;               //delay time to let servo get to position
   int recordModeLed = 3;                              // defining pins for ui leds
   int homeModeLed = 4;
   int playModeLed = 5;
   int freeModeLed = 6;
   int freeSwitch = 7;                                 //defining pins for switches
   int recSwitch = 8;
   int homeSwitch = 9;
   int playSwitch = 10;
   

 
  void setup()
{
     Serial.begin(9600);
     Serial.flush();
     myservo.attach(2);                                                   // attaches the servo on pin 2 to the servo object
     pinMode (freeModeLed, OUTPUT);                         //defining LED pins as output
     pinMode (recordModeLed, OUTPUT);
     pinMode (homeModeLed, OUTPUT);
     pinMode (playModeLed, OUTPUT);
     pinMode (freeSwitch, INPUT);                              //defining switch pins as input
     pinMode (recSwitch, INPUT);
     pinMode (homeSwitch, INPUT);
     pinMode (playSwitch, INPUT);
     
 }


  void loop ()
{
   
  digitalWrite (freeModeLed, LOW);
  digitalWrite (recordModeLed, LOW);
  digitalWrite (homeModeLed, LOW);
  digitalWrite (playModeLed, LOW);
 
  if (Serial.available( ) > 0)
 {
       incomingByte = Serial.read ( );
       if (incomingByte == 'f')
  {
          Serial.println ("Free mode");
          while (incomingByte == 'f')
    {
          digitalWrite (freeModeLed, HIGH);
          val = analogRead (potpin);
          val = map(val, 0, 1023, 0, 179);
          myservo.write (val);
          delay (waitForServo);
          if (Serial.available ( ) > 0)
      {
            incomingByte = Serial.read ( );
            if (incomingByte == 'r')
         {
             recordFunction ( );   
         }
           else if (incomingByte == 'h')
       {
           reverseFunction ( );
        }   
           else if (incomingByte = 'p')
        {
             playBackFunction ( );
         }   
       } 
     }
   } 
          else if (incomingByte == 'r')                   // checks if input was r
        {                       
           recordFunction ( );
        }
           else if (incomingByte == 'h')
       {
           reverseFunction ( );
        }
                 else if (incomingByte = 'p')
        {
           playBackFunction ( );
           }
        }
      }

void playBackFunction ( )
       {
         digitalWrite (freeModeLed, LOW);
          digitalWrite (playModeLed, HIGH);
          Serial.println ("Playback Function");
            for (int i=0;i<(valNumber - 1);i++)
          {
             myservo.write (servoPos[i]);                    //reads values from array in original order to servo
             delay (waitForServo);
             Serial.println (servoPos[i]);
          }
           digitalWrite (playModeLed, LOW);   
       }

 void reverseFunction ( )
      {
            digitalWrite (freeModeLed, LOW);
            digitalWrite (homeModeLed, HIGH);
            Serial.println ("Home function");
            for (int i=(valNumber - 1);i>0;i--)
          {
             myservo.write (servoPos[i]);                   //reads values from array in reverse to servo
             delay(waitForServo);
             Serial.println (servoPos[i]);
          }
          digitalWrite (homeModeLed, LOW);
       }
     
void recordFunction ( )
{
           for (int c=6;c>3;c --)                                     // three sec countdown to recording
           {
             digitalWrite (recordModeLed, HIGH);
             digitalWrite (c, HIGH);
             delay (700);
             digitalWrite (recordModeLed, LOW);
             digitalWrite (c, LOW);
             delay(300);
           }
           digitalWrite (recordModeLed, HIGH);
           Serial.println ("Record function");            // if so - prints record
           for (int i=0;i<(valNumber - 1) ;i++)                //for loop to store declared 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(waitForServo);                                      // waits for the servo to get there
              Serial.println(val);                                       // print values for checking
         } 
         digitalWrite (recordModeLed, LOW);
}


158  Using Arduino / Motors, Mechanics, and Power / Re: record data from potentiometer & playback to servo on: March 20, 2012, 02:47:14 am
And here again is the code, more organised, using functions...

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')
         {
             recordFunction ( );   
         }
           else if (incomingByte == 'H')
       {
           reverseFunction ( );
        }   
           else if (incomingByte = 'P')
        {
             playBackFunction ( );
         }   
       } 
     }
   } 
          else if (incomingByte == 'R')                   // checks if input was capital R
        {                       
           recordFunction ( );
        }
           else if (incomingByte == 'H')
       {
           reverseFunction ( );
        }
                 else if (incomingByte = 'P')
        {
           playBackFunction ( );
           }
        }
      }

void playBackFunction ( )
       {
          Serial.println ("Playback Function");
            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]);
          }   
       }

 void reverseFunction ( )
      {
          Serial.println ("Home function");
            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]);
          }
       }
     
void recordFunction ( )
{
   Serial.println ("Record function");                    // 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
         } 
}
159  Using Arduino / Motors, Mechanics, and Power / Re: record data from potentiometer & playback to servo on: March 19, 2012, 12:20:53 pm
sbright33, that sounds extremely interesting, and quite close to my field of interest  smiley
Are you using arrays to store the values from the software?
 
160  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
161  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]);
           }
         }
 }
}
162  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...
163  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
164  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
165  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.
Pages: 1 ... 9 10 [11] 12