loading

Welcome me matey to Davy Jones' miniature locker. To analyze yer wave and buoyancy mechanics while we plunder wenches, drink Rum and supplement with vitamin C, we rigged an Arduino Micro, (2) servos and potentiometer with if and for codes to generate various wave frequencies upon the sovereign seas (in a small acrylic case cast from a picture frame). Arrr--gh!

Selector Only Code

// Arduino Wave Tank
// TVMiller

#include <Servo.h>

Servo left;
Servo right;

int pos = 20;
int post = 160;
int back = 20;
int forward = 160;

int red = 6;
int green = 5;
int blue = 4;

int slow = 8;
int fast = 4;

void setup() {

  Serial.begin(9600);

  left.attach(2);
  right.attach(3);

  pinMode(red, OUTPUT);
  pinMode(green, OUTPUT);
  pinMode(blue, OUTPUT);

  left.write(back);
  right.write(back);

  digitalWrite(green, HIGH);
  delay(1000);
  digitalWrite(green, LOW);
  delay(1000);
  digitalWrite(red, HIGH);
  delay(1000);
  digitalWrite(red, LOW);
  delay(1000);

}

void loop() {

  int pent = analogRead(A0);
  Serial.println(pent);

  if (pent < 200) {
    digitalWrite(blue, HIGH);
    digitalWrite(red, LOW);
    digitalWrite(green, LOW);
    for (pos = back; pos <= forward; pos += 1) {
      left.write(pos);
      right.write(pos);
      delay(slow);
    }
    for (pos = forward; pos >= back; pos -= 1) {
      left.write(pos);
      right.write(pos);
      delay(slow);
    }
  }
  else if (pent > 200 && pent < 450) {
    digitalWrite(blue, LOW);
    digitalWrite(red, HIGH);
    digitalWrite(green, LOW);
    for (pos = back; pos <= forward; pos += 1) {
      left.write(pos);
      right.write(pos);
      delay(fast);
    }
    for (pos = forward; pos >= back; pos -= 1) {
      left.write(pos);
      right.write(pos);
      delay(fast);
    }
  }
  else if (pent > 450 && pent < 700) {
    digitalWrite(blue, LOW);
    digitalWrite(red, LOW);
    digitalWrite(green, HIGH);
    for (pos = back; pos <= forward; pos += 1) {
      post = map(pos, 20, 160, 160, 20);
      left.write(pos);
      right.write(post);
      delay(slow);
    }
    for (pos = forward; pos >= back; pos -= 1) {
      post = map(pos, 160, 20, 20, 160);
      left.write(pos);
      right.write(post);
      delay(slow);
    }
  }
  else if (pent > 700 && pent < 1023) {
    digitalWrite(blue, LOW);
    digitalWrite(red, HIGH);
    digitalWrite(green, LOW);
    for (pos = back; pos <= forward; pos += 1) {
      post = map(pos, 20, 160, 160, 20);
      left.write(pos);
      right.write(post);
      delay(fast);
    }
    for (pos = forward; pos >= back; pos -= 1) {
      post = map(pos, 160, 20, 20, 160);
      left.write(pos);
      right.write(post);
      delay(fast);
    }
  }

}

Speed Adjustable Code

// Arduino Wave Tank II
// TVMiller

#include 

Servo left;
Servo right;

int pos = 20;
int back = 20;
int forward = 160;
int spe = 15;

int red = 6;
int green = 5;
int blue = 4;

void setup() {

  Serial.begin(9600);

  left.attach(2);
  right.attach(3);

  pinMode(red, OUTPUT);
  pinMode(green, OUTPUT);
  pinMode(blue, OUTPUT);

  left.write(back);
  right.write(back);

  digitalWrite(green, HIGH);
  delay(1000);
  digitalWrite(green, LOW);
  delay(1000);
  digitalWrite(red, HIGH);
  delay(1000);
  digitalWrite(red, LOW);
  delay(1000);

}

void loop() {

  int pent = analogRead(A0);
  Serial.println(pent);
  spe = map(pent, 0, 1023, 15, 1);

  if (spe >= 10) {
    digitalWrite(green, HIGH);
    digitalWrite(blue, LOW);
    digitalWrite(red, LOW);
  }
  else if (spe < 10 && spe >= 5) {
    digitalWrite(green, LOW);
    digitalWrite(blue, HIGH);
    digitalWrite(red, LOW);
  }
  else if (spe < 5 && spe >= 1) {
    digitalWrite(green, LOW);
    digitalWrite(blue, LOW);
    digitalWrite(red, HIGH);
  }

  for (pos = back; pos <= forward; pos += 1) {
    left.write(pos);
    right.write(pos);
    delay(spe);
  }
  for (pos = forward; pos >= back; pos -= 1) {
    left.write(pos);
    right.write(pos);
    delay(spe);
  }
}

About This Instructable

240views

5favorites

License:

Bio: Privateer
More by TVMiller:Arduino Splash Resistant Toilet Foamer Arduino Motion Mute 1992 Isuzu Trooper Windshield Wiper Single Button Hack 
Add instructable to: