The Sea Anemome

For the stupid pet trick, I decided ‘hey why not build the stupid pet instead?’
 
so I made a sea anemone.  The light show varies in intensity with flexion of the flex sensors.  The flex sensors aren’t as impressive looking as one would hope, but I’d rather not break them.
 
 
The Arduino Code:
 
// Sea Anemone
// light show changes oscillation brightness with flex sensation
// declare and initialize variables
//input pin assignments
int flexPinA = 0; //Left Side flex sensor pin (0)
int flexPinB = 1; //right side flex sensor pin (1)
//initialization of input variables Flex value A and Flex B
int flexValueA = 0; //initial value for flex A
int flexValueB = 0; //initial value for flex B
//output Pin assignments
int greenPinA = 3; //PWM pin for Green LED A :: PWM digital 9
int greenPinB = 5;
int greenPinC = 6;
int bluePinA = 9;
int bluePinB = 10;
int yellowPinA = 11;
//random storage variables
int randA = 0;
int randB = 0;
int randC = 0;
int randD = 0;
int randE = 0;
//output storage variables (g/b)
int greenA = 0;
int greenB = 0;
int greenC = 0;
int blueA = 0;
int blueB = 0;
void setup ()
{
  Serial.begin(9600); //initialize serial comm @ 9600bps
  randomSeed(analogRead(5)); //initialize random number generator with random noise on unused analog pin (5)
}
void loop() // output stage
{
  flexValueA = analogRead(flexPinA); // read value A
  flexValueB = analogRead(flexPinB); // read value B
//debugger panel: raw input
  Serial.print(flexValueA); // print flexValueA to debugger
  Serial.print(",");
  Serial.println(flexValueB); // B to debugger
  flexValueA = map(flexValueA, 500, 250, 0, 10); // map flex sense value (0..1023) to output range for PWM output 0..255
  flexValueB = map(flexValueB, 500, 250, 0, 10);
/*
//debugger panel: scaled input
  Serial.print(flexValueA); // print flexValueA to debugger
  Serial.print(",");
  Serial.println(flexValueB); // B to debugger
*/
 
  randA = random(0,20); // random number between 0..128 (PWM half brightness)
  randB = random(0,20);
  randC = random(0,20);
  randD = random(0,20);
  randE = random(0,20);
 
  greenA = flexValueA * randA;
  greenA = constrain (greenA, 0, 255);
  greenB = flexValueB * randB;
  greenB = constrain (greenB, 0, 255);
  greenC = flexValueA * randC;
  greenC = constrain (greenC, 00, 255);
  blueA = flexValueA * randA;
  blueA = constrain (blueA, 0, 150);
  blueB = flexValueB * randB;
  blueB = constrain (blueB, 0, 150);
/*
  //debugger panel : output
  Serial.print(greenA); // print greenA to debugger
  Serial.print(",");
  Serial.print(greenB); // println Flex value B to debugger
  Serial.print(",");
  Serial.print(greenC); // println Flex value C to debugger
  Serial.print(","); 
  Serial.print(blueA);
  Serial.print(",");
  Serial.println(blueB);
*/
 
  analogWrite(greenPinA, greenA); // Green LED with random value + scaled flex value A  0..255 range one byte
  analogWrite(greenPinB, greenB);
  analogWrite(greenPinC, greenC);
  analogWrite(bluePinA, blueA);
  analogWrite(bluePinB, blueB);
  analogWrite(yellowPinA, greenB);
 
    delay(125); // delay
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s