00:00
62
More
See all Show me
6. Untitled
2 years ago
2. Drip Switch
3 years ago
beatBot is a drum playing robot that responds positively to human interaction and attention by playing music for its users. The target user of the beatBot is anyone who enjoys hearing rhythmic music and would want a quirky machine that they could watch play it. beatBot's users may choose to use beatBot for a variety of reasons - for musical entertainment, for playing other instruments with, for something to dance to at a party, or for viewing pleasure.

The beatBot plays three Roland PD-8 electronic drum pads, connected to the Roland drum synthesizer that they are made for. It uses six Hitec HS-322HD servos to drive six shortened drumsticks which play on the Roland pads. The music beatBot plays is written as code. By counting to some integer like 2750 (milliseconds) repeatedly, a function ‘beat’ which tells a particular servo to hit its drum once, can be run at the moment the arduino counts to certain percentages of that integer. This allows the tempo of the music to change depending on the ambient lighting in beatBot's environment, which it reads using a photocell during setup. A rangefinder mounted to the front of beatBot looks for people walking by to play music for. When it does not sense a human presence, beatBot plays a very simple rhythm on one drum to invite people in the area to come check it out, upon seeing them, beatBot begins to play more impressive music.

//set Roland drum brain to Drum Kit 9

#include //loads MegaServo library
#define FIRST_SERVO_PIN 2 //tells arduino on which pin servos start
#define MAX_SERVOS 5 //tells arduino how many adjacent pins are connect to servos
#define NUMREADINGS 10 //number of readings averaged by smoother

MegaServo Servos[MAX_SERVOS] ; //max servos is 32 for mega, 8 for other boards
int ServoDestDeg[MAX_SERVOS]; //degree to which servos move from zero position
int ServoCoolDown[MAX_SERVOS]; //number of milliseconds arduino lets servo move toward ServoDestDeg before bringing it back to zero position

int photoval = 0; //light dependant variable
int photoPin = 2; //pin that LDR is connected to

int tempo = 0; //variable for length of loop - dependant on ambient lighting
int loopMeasure = 0; //certain percentage of tempo

int readings[NUMREADINGS]; //the readings from the analog input
int index = 0; //the index of the current reading
int total = 0; //the running total
int average = 0; //the average
int rangePin = 1; //pin that range fider is connected to
int ledPin = 13; //pin that LED is connected to

void setup()
{
//Serial.begin(9600); //serial print

photoval = analogRead(photoPin); //photoval takes value of reading from photoPin
tempo = map(photoval, 300, 800, 2750, 3500); //maps tempo to photoval

pinMode(ledPin, OUTPUT); //sets ledPin as output

for( int i =0; i < MAX_SERVOS; i++){
Servos[i].attach( FIRST_SERVO_PIN +i,700,2000); //attaches each servo and assigns their pulse widths
ServoDestDeg[i] = 0;
ServoCoolDown[i] = 0;
}

for (int i = 0; i < NUMREADINGS; i++) //for smoothing range finder readings
readings[i] = 0;


}

void beat(int servoNum){ //hit drum once (reversed for servos facing left)
ServoDestDeg[servoNum] = 180; //destination angel of the servo
ServoCoolDown[servoNum] = 250; //number of cycles before returning
}

void revBeat(int servoNum){ //hit drum once (reversed for servos facing right)
ServoDestDeg[servoNum] = 0; //destination angel of the servo
ServoCoolDown[servoNum] = 250; //number of cycles before returning
}

void loop()
{
loopMeasure = millis() % tempo; //value of loopMeasure is a certain percentage of tempo

//Serial.println(photoval); //prints LDR readings


for(int i=0; i 0) //sends servos 0-2 back to 0 degrees after hitting drum
ServoCoolDown[i]--;

if(ServoCoolDown[i] == 0)
ServoDestDeg[i] = 22.5; //assigns 22.5 degrees as destination deree for servos 0-2 (hits drum at 22.5)
}

for( int i=3; i 0) //sends servos 3-5 back to 0 degrees after hitting drum
ServoCoolDown[i]--;


if(ServoCoolDown[i] == 0)
ServoDestDeg[i] = 157.5; //assigns 157.5 degrees as destination degree for servos 3-5 (hits drum at 157.5)
}


total -= readings[index]; // subtract the last reading
readings[index] = analogRead(rangePin); // read from the sensor
total += readings[index]; // add the reading to the total
index = (index + 1); // advance to the next index

if (index >= NUMREADINGS) // if we're at the end of the array...
index = 0; // ...wrap around to the beginning

average = total / NUMREADINGS; // calculate the average
//Serial.println(average); // send it to the computer (as ASCII digits)

if (average > 100) //if range finder senses a person standing in front of machine..
{
int beatTimeH = tempo / 4;
for(int i = tempo / 8; i < tempo; i += beatTimeH){
if(loopMeasure == i)
revBeat(0); //servo 0 hits high hat in 1/4 notes starting on the and of 1 (upbeat) of the measure
}
for(int i = tempo * .1875; i < tempo * .935; i += beatTimeH){
if(loopMeasure == i)
beat(3); //servo 3 his high hat in 1/4 notes starting one 1/16 note after the and of 1 of the measure (minus the last hit of each measure)
}
if(millis() % tempo == (int)(tempo * 0))
revBeat(1);
if(millis() % tempo == (int)(tempo * .1875))
revBeat(1);
if(millis() % tempo == (int)(tempo * .4375))
revBeat(1);
if(millis() % tempo == (int)(tempo * .625))
revBeat(1);
if(millis() % tempo == (int)(tempo * .8125))
revBeat(1);

if(millis() % tempo == (int)(tempo * .5625))
beat(4); // servos 1 and 4 hit bass drum in syncopated hip-hop rhythm

int beatTimeS = tempo / 2;
for(int i = tempo / 4; i < tempo; i += beatTimeS){
if(loopMeasure == i)
revBeat(2); //servo 2 hits snare drum in 1/2 notes starting on the 2 of the measure
}

digitalWrite(ledPin, HIGH); //LED turns on when range finder senses person
}

else //if range finder does not sense someone standing in front of machine...
{
if(millis() % tempo == (int)(tempo * 0))
revBeat(1);

if(millis() % tempo == (int)(tempo * .4375))
revBeat(1);

if(millis() % tempo == (int)(tempo * .625))
revBeat(1);

if(millis() % tempo == (int)(tempo * .8125))
revBeat(1); //servo 1 hits bass drum in syncopated hip-hop rhyhtm

digitalWrite(ledPin, LOW); //LED does not turn on when range finder does not sense person
}
}


//set Roland drum brain to Drum Kit 8

#include //loads MegaServo library
#define FIRST_SERVO_PIN 2 //tells arduino on which pin servos start
#define MAX_SERVOS 4 //tells arduino how many adjacent pins are connect to servos
#define NUMREADINGS 10 //number of readings averaged by smoother

MegaServo Servos[MAX_SERVOS] ; //max servos is 32 for mega, 8 for other boards
int ServoDestDeg[MAX_SERVOS]; //degree to which servos move from zero position
int ServoCoolDown[MAX_SERVOS]; //number of milliseconds arduino lets servo move toward ServoDestDeg before bringing it back to zero position

int photoval = 0; //light dependant variable
int photoPin = 2; //pin that LDR is connected to

int tempo = 0; //variable for length of loop - dependant on ambient lighting
int loopMeasure = 0; //certain percentage of tempo

int readings[NUMREADINGS]; //the readings from the analog input
int index = 0; //the index of the current reading
int total = 0; //the running total
int average = 0; //the average
int rangePin = 1; //pin that range fider is connected to
int ledPin = 13; //pin that LED is connected to

void setup()
{
//Serial.begin(9600); //serial print

pinMode(ledPin, OUTPUT); //sets ledPin as output

for( int i =0; i < MAX_SERVOS; i++){
Servos[i].attach( FIRST_SERVO_PIN +i,700,2000); //attaches each servo and assigns their pulse widths
ServoDestDeg[i] = 0;
ServoCoolDown[i] = 0;
}

for (int i = 0; i < NUMREADINGS; i++) //for smoothing range finder readings
readings[i] = 0;

photoval = analogRead(photoPin); //photoval takes value of reading from photoPin
tempo = map(photoval, 300, 800, 2500, 3000); //maps tempo to photoval
}

void beat(int servoNum){ //hit drum once (reversed for servos facing left)
ServoDestDeg[servoNum] = 180; //destination angel of the servo
ServoCoolDown[servoNum] = 250; //number of cycles before returning
}

void revBeat(int servoNum){ //hit drum once (reversed for servos facing right)
ServoDestDeg[servoNum] = 0; //destination angel of the servo
ServoCoolDown[servoNum] = 250; //number of cycles before returning
}

void loop()
{
loopMeasure = millis() % tempo; //value of loopMeasure is a certain percentage of tempo

//Serial.println(photoval); //prints LDR readings


for(int i=0; i 0) //sends servos 0-2 back to 0 degrees after hitting drum
ServoCoolDown[i]--;

if(ServoCoolDown[i] == 0)
ServoDestDeg[i] = 22.5; //assigns 22.5 degrees as destination deree for servos 0-2 (hits drum at 22.5)
}

for( int i=3; i 0) //sends servos 3-5 back to 0 degrees after hitting drum
ServoCoolDown[i]--;


if(ServoCoolDown[i] == 0)
ServoDestDeg[i] = 157.5; //assigns 157.5 degrees as destination degree for servos 3-5 (hits drum at 157.5)
}


total -= readings[index]; // subtract the last reading
readings[index] = analogRead(rangePin); // read from the sensor
total += readings[index]; // add the reading to the total
index = (index + 1); // advance to the next index

if (index >= NUMREADINGS) // if we're at the end of the array...
index = 0; // ...wrap around to the beginning

average = total / NUMREADINGS; // calculate the average
//Serial.println(average); // send it to the computer (as ASCII digits)

if (average > 70) //if range finder senses a person standing in front of machine..
{
int beatTimeK = tempo / 4;
for(int i = 0; i < tempo; i += beatTimeK){
if(loopMeasure == i)
revBeat(1); //servo 2 hits the bass drum in 1/4 notes starting on the 1 of the measure
}
int beatTimeS = tempo / 2;
for(int i = tempo * .1875; i < tempo; i += beatTimeS){
if(loopMeasure == i)
revBeat(2);
}
int beatTimeSS = tempo / 2;
for(int i = tempo * .375; i < tempo; i += beatTimeSS){
if(loopMeasure == i)
revBeat(2);
}
int beatTimeH = tempo / 4;
for(int i = tempo / 8; i < tempo; i += beatTimeH){
if(loopMeasure == i)
revBeat(0); //servo 0 hits the high hat in 1/4 notes starting on the and of 1 (first upbeat) of the measure
}
if(millis() % tempo == (int)(tempo * .5))
revBeat(0);
if(millis() % tempo == (int)(tempo * .5625))
beat(3);

digitalWrite(ledPin, HIGH); //LED turns on when range finder senses person
}

else //if range finder does not sense someone standing in front of machine...
{
int beatTimeS = tempo / 2;
for(int i = tempo * .1875; i < tempo; i += beatTimeS){
if(loopMeasure == i)
revBeat(2);
}
int beatTimeSS = tempo / 2;
for(int i = tempo * .375; i < tempo; i += beatTimeSS){
if(loopMeasure == i)
revBeat(2);
}

digitalWrite(ledPin, LOW); //LED does not turn on when range finder does not sense person
}
}


//set Roland drum brain to Drum Kit 10

#include //loads MegaServo library
#define FIRST_SERVO_PIN 2 //tells arduino on which pin servos start
#define MAX_SERVOS 4 //tells arduino how many adjacent pins are connect to servos
#define NUMREADINGS 10 //number of readings averaged by smoother

MegaServo Servos[MAX_SERVOS] ; //max servos is 32 for mega, 8 for other boards
int ServoDestDeg[MAX_SERVOS]; //degree to which servos move from zero position
int ServoCoolDown[MAX_SERVOS]; //number of milliseconds arduino lets servo move toward ServoDestDeg before bringing it back to zero position

int photoval = 0; //light dependant variable
int photoPin = 2; //pin that LDR is connected to

int tempo = 0; //variable for length of loop - dependant on ambient lighting
int loopMeasure = 0; //certain percentage of tempo

int readings[NUMREADINGS]; //the readings from the analog input
int index = 0; //the index of the current reading
int total = 0; //the running total
int average = 0; //the average
int rangePin = 1; //pin that range fider is connected to
int ledPin = 13; //pin that LED is connected to

void setup()
{
//Serial.begin(9600); //serial print

pinMode(ledPin, OUTPUT); //sets ledPin as output

for( int i =0; i < MAX_SERVOS; i++){
Servos[i].attach( FIRST_SERVO_PIN +i,700,2000); //attaches each servo and assigns their pulse widths
ServoDestDeg[i] = 0;
ServoCoolDown[i] = 0;
}

for (int i = 0; i < NUMREADINGS; i++) //for smoothing range finder readings
readings[i] = 0;

photoval = analogRead(photoPin); //photoval takes value of reading from photoPin
tempo = map(photoval, 300, 800, 1500, 2500); //maps tempo to photoval
}

void beat(int servoNum){ //hit drum once (reversed for servos facing left)
ServoDestDeg[servoNum] = 180; //destination angel of the servo
ServoCoolDown[servoNum] = 250; //number of cycles before returning
}

void revBeat(int servoNum){ //hit drum once (reversed for servos facing right)
ServoDestDeg[servoNum] = 0; //destination angel of the servo
ServoCoolDown[servoNum] = 250; //number of cycles before returning
}

void loop()
{
loopMeasure = millis() % tempo; //value of loopMeasure is a certain percentage of tempo

//Serial.println(photoval); //prints LDR readings


for(int i=0; i 0) //sends servos 0-2 back to 0 degrees after hitting drum
ServoCoolDown[i]--;

if(ServoCoolDown[i] == 0)
ServoDestDeg[i] = 22.5; //assigns 22.5 degrees as destination deree for servos 0-2 (hits drum at 22.5)
}

for( int i=3; i 0) //sends servos 3-5 back to 0 degrees after hitting drum
ServoCoolDown[i]--;


if(ServoCoolDown[i] == 0)
ServoDestDeg[i] = 157.5; //assigns 157.5 degrees as destination degree for servos 3-5 (hits drum at 157.5)
}


total -= readings[index]; // subtract the last reading
readings[index] = analogRead(rangePin); // read from the sensor
total += readings[index]; // add the reading to the total
index = (index + 1); // advance to the next index

if (index >= NUMREADINGS) // if we're at the end of the array...
index = 0; // ...wrap around to the beginning

average = total / NUMREADINGS; // calculate the average
//Serial.println(average); // send it to the computer (as ASCII digits)

if (average > 90) //if range finder senses a person standing in front of machine..
{
int beatTimeK = tempo / 4;
for(int i = 0; i < tempo; i += beatTimeK){
if(loopMeasure == i)
revBeat(1); //servo 2 hits the bass drum in 1/4 notes starting on the 1 of the measure
}
int beatTimeS = tempo / 2;
for(int i = tempo / 4; i < tempo; i += beatTimeS){
if(loopMeasure == i)
revBeat(2); //servo 1 hits the snare drum in 1/2 notes starting on the 2 of the measure
}
int beatTimeH = tempo / 4;
for(int i = tempo / 8; i < tempo; i += beatTimeH){
if(loopMeasure == i)
revBeat(0); //servo 0 hits the high hat in 1/4 notes starting on the and of 1 (first upbeat) of the measure
}
int beatTimeHH = tempo / 4;
for(int i = tempo / 5.333; i < tempo; i += beatTimeHH){
if(loopMeasure == i)
beat(3); //servo 3 hits the high hat in 1/4 notes starting on the 1/16 note after the and of 1 of the measure
}
digitalWrite(ledPin, HIGH); //LED turns on when range finder senses person
}

else //if range finder does not sense someone standing in front of machine...
{
int beatTimeK = tempo / 4;
for(int i = 0; i < tempo; i += beatTimeK){
if(loopMeasure == i)
revBeat(1); //servo 1 hits the bass drum in 1/4 notes starting on the 1 of the measure
}
digitalWrite(ledPin, LOW); //LED does not turn on when range finder does not sense person
}
}

Credits

This conversation is missing your voice. Take five seconds to join Vimeo or log in.

Advertisement

About this video

MP4
00:01:02
  • 480x368, 4.45MB
  • Uploaded Thu May 14, 2009
  • Please join or log in to download

Statistics

Date Plays Comments
Totals 277 0 0
Feb 23rd 0 0 0
Feb 22nd 0 0 0
Feb 21st 0 0 0
Feb 20th 0 0 0
Feb 19th 0 0 0
Feb 18th 0 0 0
Feb 17th 0 0 0