Programming RC Servo to do beats

Hi all,

I recently got into learning the Arduino and I came across this video and thought of re-creating it.

The only program is I have is that the video only displays the void loop part of the code but not the void setup so I really have no idea what the setup is supposed to be?

I wonder if some of you experienced folks could help me out with this! He doesn’t have the schematics up either so I don’t really quite know what to patch and where to patch.

I think I have all the parts required to do this project so I really hope to get this going! I have a RC motor and a potentiometer!

This is the code posted in the video that I copied :

*/
} 

void loop()
{ 
  //int BEATS = 10 
  // int theBeat[] = {-1, 1, 1,-1};

  //int theBEAT[] = { -2, -2, 2, -1, 1, -1, 1, -2, 4 };

  int i; 
  int sensorpin = 0; 
  int sensorValue = analogRead(sensorpin); 

  int extension = 45;
  //int maxSensorValue = 1023;  
  int Maxwait = 1025;
  Serial.printIn(sensorValue); 
  int millis = maxWait - sensorValue; 

  for (i=0; i<4; i++){
    sensorValue = analogRead (potpin); 
    millis = maxWait - sensorValue; 
    hit(millis*theBeat[i]);
  }
}

Please HELP!! Thanks fellas! :wink:

There is more than setup() missing. The hit() function is missing as well.

You will need to include the Servo library and create a Servo object. I would guess that the hit() function reads the the theBEAT array and moves the servo left and right depending on the value read. The delay (NOT delay()) between beats is set by the value read from the potentiometer.

May I know how one create the hit() function? I don’t quite understand that.

To create a servo object, I could just use something like this?

Servo myservo;  // create servo object to control a servo 
                // a maximum of eight servo objects can be created 
 
int pos = 0;    // variable to store the servo position 
 
void setup() 
{ 
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
}

Anyone else? Help?

May I know how one create the hit() function? I don't quite understand that.

What is the hit() function supposed to do? Looks to me like it just waves the servo from 90 to 0, from 0 to 180, and from 180 to 90 (though 0 and 180 may not be the proper limits; perhaps more like 45 and 135; you'd need to experiment with YOUR setup).