6. Motor Chaos Mobile

Posted by Erich

Erich's picture

Chaotic Motor Pendulum 

A pot controls a motor, to which an LED is attached. As the motor speeds up, it whips a cable around faster. A speaker is then outputting a random note that speeds up as the motor speeds up. The motor is being powered by the 5 volts from the arduino.

Video: http://www.youtube.com/watch?v=naNsSJ3qnnY

 

/*
 * Erich
 */
 
byte names[] = {'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C'};  
int tones[] = {1915, 1700, 1519, 1432, 1275, 1136, 1014, 956};
int potPin = 0;   // select the input pin for the potentiometer
int motorPin = 9; // select the pin for the Motor
int speakerPin = 11;
int pot = 0;      // variable to store the value coming from the sensor
int note = 0;
int tempo = 0;
 
void setup() {
  pinMode(speakerPin, OUTPUT); 
  pinMode(potPin, INPUT);
  pinMode(motorPin, OUTPUT);
  Serial.begin(9600);
}
void loop() {
  pot = analogRead(potPin);    // read the value from the sensor
  tempo=map(pot,0,1024,250,25);
  analogWrite(motorPin, pot/7); //
  Serial.print("Tempo=");
  Serial.print(tempo);
  note = random(8);
  Serial.print("    Note=");
  Serial.println(names[note]);
  
//  for( int i=0; i<tempo; i++ ) {  // play it for tempo cycles
  for( int i=0; i<tempo; i++ ) {  // play it for tempo cycles
    digitalWrite(speakerPin, LOW);
    delayMicroseconds(tones[note]);
    digitalWrite(speakerPin, HIGH);
    delayMicroseconds(tones[note]);
  }  
}
setup.jpg
lightshow.jpg
circuit.jpg
0
Your rating: None
Tags: