array of servo objects


hello,

          trying make array of servo objects. here sketch:
code: [select]
/*
              record , playback program
cappy jack 10/10/13

editing turn switch fred
program takes manuel manipulation of 4 potentiometers , moves 4 servo motors.
recording each of them individually while playing sd files other three.
record button saves selected pot values sd memory card, reads sd card other 3 , drives servos.
playback button reads values sd card , drives servos.
stop_ button halts record or playback function.
there 4 pots selected 2 switches in state diagram. 1 @ a  time
*/

#include <sd.h>
#include <servo.h>

const int pin6 = 6;      //attaches servos pins 6 & 8
const int pin7 = 7;
const int pin8 = 8;
const int pin9 = 9;

servo servo0;      // declare objects servos
servo servo1;
servo servo2;
servo servo3;
const int halt = 0;
const int rec = 2;
const int play = 3;
const int switch1 = 4;  // switches select pot record
const int switch2 = 5;
int pot;
int move_val;
file routine0;          // creates file object sd card
file routine1;
file routine2;
file routine3;

file routine[]= {
  routine0, routine1,routine2,routine3};
int pots[] = {
  0,1,2,3};
servo servo[]= {
servo0, servo1,servo2,servo3};

void setup() {
  serial.begin(9600);      // initialize serial communication
  serial.print("free ram: ");       // can debugging, running out of ram bad
  serial.println(freeram());
  servo0.attach(pin6);     // attach pins servos
  servo1.attach(pin7);
  servo2.attach(pin8);
  servo3.attach(pin9);
  pinmode(halt, input_pullup);   // halt button
  pinmode(rec, input_pullup);    // record button
  pinmode(play, input_pullup);   // playback button
  pinmode(switch1, input_pullup);  // selector pots 1-4
  pinmode(switch2, input_pullup);  // selector pots 1-4
  pinmode(10, output);           // sd card on
  sd.begin();                    //initializes sd library , card
}   // end of set up

int select_pot () {
  if ((digitalread(switch1) == 0) && (digitalread(switch2) == 1))
    pot = pots[0];
  if ((digitalread(switch1) == 1) && (digitalread(switch2) == 1))
    pot = pots[1];
  if ((digitalread(switch1) == 1) && (digitalread(switch2) == 0))
    pot =  pots[2];
  if ((digitalread(switch1) == 0) && (digitalread(switch2) == 0))
    pot = pots[3];
  return pot;
}

int readpot(int pot) {
  move_val = analogread(pot);  // reads value of potentiometer (value between 0 , 1023)
  move_val = map(move_val, 0, 1023, 0, 89);  // sets servo position according scaled value
  return move_val;
}

void move_servo(int pot,int move_val) {  // function move servo   
  servo[pot].write(move_val);
  delay(40);   // waits servo there


void halt_loop(int pot) {
  if (digitalread(halt)== 0){
    routine[pot].close();
//   break;
  }
}

void writesd(int pot){
  routine[pot] = sd.open(routine[pot],file_write);
  routine[pot].write(move_val);
  delay(40);
  }

  void record(int pot){      // function read pot, move servos , write sd card
    //  sd.remove("routine.txt");
    open routine[pot];
    readpot(pot);
    moveservo(pot);
    writesd(pot);
    halt_loop(pot);
  }

void playback(int pot){
  int value;
  open routine[pot];
  value = routine[pot].read();
  moveservo(pot);
  halt_loop(pot);
}

void switch_pot(){
  switch (pot){
  case 0:
    record(pot);
    playback(1);
    playback(2);
    playback(3);
  case 1:
    record(pot);
    playback(0);
    playback(2);
    playback(3);
  case 2:
    record(pot);
    playback(0);
    playback(1);
    playback(3);   
  case 3:
    record(pot);
    playback(0);
    playback(1);
    playback(2);
  case 4:
    playback(0);
    playback(1);
    playback(2);
    playback(3);
  }
}

void loop() {    // main loop

    if ((digitalread(rec)) == 0){
    select_pot();
    switch_pot();
    serial.print(digitalread(rec));
    serial.println("  rec   ");
  }

  if ((digitalread(playback)) == 0){
    pot = 4;
    switch_pot();
    serial.print(digitalread(playback));
    serial.println("  play   ");
  }
  serial.print("  looping ");
  delay(100);
}  // end void loop


and here compiler error log:
rec_1_play_3k.ino: in function 'void writesd(int)':
rec_1_play_3k:93: error: no matching function call 'sdclass::open(file&, int)'
c:\program files (x86)\arduino\libraries\sd/sd.h:74: note: candidates are: file sdclass::open(const char*, uint8_t)
rec_1_play_3k.ino: in function 'void record(int)':
rec_1_play_3k:100: error: 'open' not declared in scope
rec_1_play_3k:100: error: expected `;' before 'routine'
rec_1_play_3k:102: error: 'moveservo' not declared in scope
rec_1_play_3k.ino: in function 'void playback(int)':
rec_1_play_3k:109: error: 'open' not declared in scope
rec_1_play_3k:109: error: expected `;' before 'routine'
rec_1_play_3k:111: error: 'moveservo' not declared in scope
rec_1_play_3k.ino: in function 'void loop()':
rec_1_play_3k:154: error: invalid conversion 'void (*)(int)' 'uint8_t'
rec_1_play_3k:154: error: initializing argument 1 of 'int digitalread(uint8_t)'
rec_1_play_3k:157: error: invalid conversion 'void (*)(int)' 'uint8_t'
rec_1_play_3k:157: error: initializing argument 1 of 'int digitalread(uint8_t)'

could suggest fix?  thank you!

declaring array content unnecessary. this:
code: [select]

file routine0;          // creates file object sd card
file routine1;
file routine2;
file routine3;

file routine[]= {
  routine0, routine1,routine2,routine3};

should this:
code: [select]

file routine[4];

same servos.

as errors, solve them 1 @ time , recompile. first 1 complaining passed file structure when expecting string filename in it.


Arduino Forum > Using Arduino > Programming Questions > array of servo objects


arduino

Comments

Popular posts from this blog

VIDIOC_S_FMT error 16, Device or resource busy - Raspberry Pi Forums

using a laptop skeleton to build a pi laptop - Raspberry Pi Forums

Forum for Joomla? - Joomla! Forum - community, help and support