[Lab06] This one’s a kicker.

Description

For this lab, I wanted to try to extend the range of motion from the DC motor to a pinwheel, and then to try to move water with that. Thus, I made a dolphin that can splash with a high enough energy rotation from the potentiometer. Otherwise, it will just make a fitting high pitched squeal (due to the motor being restricted in its range of motion). I also created an accompanying sketch in Processing that does waves.

Materials

  • Dental Floss Cap
  • Deconstructed Pinwheel
  • Dolphin with Magnetic Bottom
  • Arduino, Breadboard, Jumper Cables
  • Potentiometer
  • Resistors, Transistors, Diodes

Code

 

/*
* one pot fades one motor
* modified version of AnalogInput
* by DojoDave <http://www.0j0.org>
* http://www.arduino.cc/en/Tutorial/AnalogInput
* Modified again by dave
*/

int potPin = 0; // select the input pin for the potentiometer
int motorPin = 9; // select the pin for the Motor
int val = 0; // variable to store the value coming from the sensor
void setup() {
Serial.begin(9600);
}
void loop() {
val = analogRead(potPin); // read the value from the sensor, between 0 - 1024
Serial.println(val);
analogWrite(motorPin, val/4); // analogWrite can be between 0-255
}



Processing (building off of SineWave example code)

String buf="";
int cr = 13;
int lf = 10;
int serialVal = 0;
int shift = 0;
int xspacing = 16; // How far apart should each horizontal location be spaced
int w; // Width of entire wave

float theta = 0.0; // Start angle at 0
float amplitude = 75.0; // Height of wave
float period = 500.0; // How many pixels before the wave repeats
float dx; // Value for incrementing X, a function of period and xspacing
float[] yvalues; // Using an array to store height values for the wave
float alpha=0;
boolean forward;

void setup() {
size(1500, 800);
w = width;
dx = (TWO_PI / period) * xspacing;
yvalues = new float[w/xspacing];

}

void draw() {
background(0, 125,200);
calcWave();
for (int i = 0; i < 360; i+=10) {
rotate(i%36);
renderWave(alpha);

}
}

void calcWave() {
// Increment theta (try different values for 'angular velocity' here
theta += 0.03;

alpha = ((alpha +1) %255);

// For every x value, calculate a y value with sine function
float x = theta;
for (int i = 0; i < yvalues.length; i++) {
yvalues[i] = sin(x)*amplitude;
x+=dx;
}
}

void renderWave(float alpha) {
stroke(50, alpha ,200);
noFill();
// A simple way to draw the wave with an ellipse at each location
for (int x = 0; x < yvalues.length; x++) {
ellipse(x*xspacing, height/2+yvalues[x], 3, 3);
}
}

waves

Leave a Reply