Michael Importico – HALLOWUINO!

 
#include  

// Create a servo "object", called servo1. Each servo object
// controls one servo (you can have a maximum of 12):

Servo servo1;
const int flexpin = 0; 
const int motorPin = 5;

void setup() 
{   
  Serial.begin(9600);
  servo1.attach(9);
  pinMode(motorPin, OUTPUT);
} 

void loop() 
{ 
  int motospeed;
  int flexposition;    // Input value from the analog pin.
  int servoposition;   // Output value to the servo.

  // Read the position of the flex sensor (0 to 1023):

  flexposition = analogRead(flexpin);

  servoposition = map(flexposition, 760, 938, 0, 180);
  servoposition = constrain(servoposition, 0, 180);
  motospeed = map(flexposition,760,930,0,255);
  servo1.write(servoposition);
  analogWrite(motorPin, motospeed);

  //serial sensor info
  Serial.print("sensor: ");
  Serial.print(flexposition);
  Serial.print("  servo: ");
  Serial.println(servoposition);
  delay(20);  // wait 20ms between servo updates
}
The guts of my Mummy
This was an exciting project.  I used one flex sensor, one motor and a servo.  The action is activated by "hurting the mummy" - this means bending him in places he does not want to bend.  This upsets the Mummy and as you hurt him, he begins to writhe in pain - flailing his arms as his head spins.

Post a comment