User login

Powered by Drupal, an open source content management system

Theory and Practice of Tangible User Interfaces

Halloween Ghostie

Submitted by criley on Wed, 10/15/2008 - 20:00

Assignment: DC Motor: Actuation Assignment 1

Collaborators:

This ghostie greets visitors who 'stand on the welcome mat' with a happy little dance, but touch the ghostie and he gets rather angry!

When the force sensor is triggered by a visitor, the motor, with offset weight, creates a gentle swing, but when one of the force sensors is occluded, the vibration becomes strong. The next feature I want to add is sound: when happy, the ghost sings, but when angry, makes a warning scream!

Code:

int photoPin1 = 0;   // select the input pin for the first photocell
int photoPin2 = 1;   // select the input pin for the second photocell
int forcePin = 2 ;
int ledPin2 = 11;
int ledPin1 = 10;
int motorPin = 9; // select the pin for the Motor
int forceVal = 0;      // variable to store the value coming from the sensor
int photoVal1 = 0;
int photoVal2 = 0;
void setup() {
  Serial.begin(9600);
}
void loop() {
  forceVal = analogRead(forcePin);
  photoVal1 = analogRead(photoPin1);
  photoVal2 = analogRead(photoPin2);
  Serial.println(forcePin);
  Serial.println(photoVal2);
  Serial.println(photoVal1);
  if(forceVal > 0 ){
    //do something happy
    analogWrite(motorPin, 25); //spin gently
  }else if(photoVal1 < 100 || photoVal2 < 100){
    //do something angry
    analogWrite(motorPin, 200); //vibrate wildly!
  }
}