Making Things Interactive

February 14, 2008

Assignment 6: (more motion)

Filed under: 6: More Motion, Assignments — mdgross @ 6:56 pm

Due Tuesday, February 19, 2008.

Complete (if necessary) and extend the previous (making motion) assignment. Make the motors, solenoids actually DO something. Make the motion more sophisticated, or make it more responsive to sensor inputs. Take the project further than a breadboard electronics exercise. See “cabaret mechanical theatre” or “flying pig” for some fun automata ideas (cams, levers, geneva wheels) that you can use to make a motor do something more than spin.

Course Notes – 12 Feb 08

Filed under: Class Notes, Course Materials — jet @ 10:49 am

Some examples from Tuesday. We’ll go over this more next week, but this is a good starting point.


// subroutine examples.

// To use subroutines you need two things:
// 1) a subroutine definition
// 2) a call to the subroutine.

// You make a subroutine definition using the following grammar:

// void NAME(ARGUMENTS)
// {
// BODY
// }

// NAME: the name of your subroutine.  Letters and numbers and
// underscores are ok

// ARGUMENTS: if your subroutine needs information to do something, you
// put it here in a comma seperated list:

// BODY: the statements you want the subroutine to do for you.

// Examples:

// a subroutine with no arguments that turns pin 13 on and off
// void Blink13()
// {
//     digitalWrite(13,HIGH);
//     delay(500);
//     digitalWrite(13,LOW);
//     delay(500)
// }
// and in the code, you'd use it like this:
// Blink13();

// a subroutine with one argument that turns a pin on and off.
// which pin is turned on and off is determined by the argument
// "int pin".
// void BlinkLed(int pin)
// {
//     digitalWrite(pin,HIGH);
//     delay(500);
//     digitalWrite(pin,LOW);
//     delay(500)
// }
// and in the code, you'd use it like this:
// BlinkLed(13); 

// a subroutine with two arguments that turns a pin on and off, which
// pin is turned on and off and how long the delay is are determined
// by the first two arguments:
// void BlinkLedDelay(int pin, int amount)
// {
//     digitalWrite(pin,HIGH);
//     delay(amount);
//     digitalWrite(pin,LOW);
//     delay(amount)
// }
// and in the code, you'd use it like this:
// BlinkLedDelay(13, 500); 

//  Note: "subroutine" and "function" are effectively interchangeable.
//  Which you use often has more to do with what language you learned
//  first than with anything else.
//  Personally, I use "subroutine" to mean something that does
//  something and "function" to be something that returns a value (more
//  on that next week).

// our output pins
int redLed = 10;
int blueLed = 12;
int greenLed = 13;

// our status pin
int statusLed = 13;

// we use this in more than one place, so set it as a variable
int startingDelay = 500;

// our default delay amount for the examples
int delayAmount = startingDelay;

// the delay amount for the status pin
int statusDelay = 200; 

void setup()
{
    pinMode(statusLed,OUTPUT);

    pinMode(redLed,OUTPUT);
    pinMode(blueLed,OUTPUT);
    pinMode(greenLed,OUTPUT);
}

void loop()
{
    // blink the status LED briefly using the LedBlinkDelay
    LedBlinkDelay(statusLed, statusDelay);
    // or we could have a dedicated status blink that takes
    // no arguments
    // BlinkStatusLed();

    delayAmount = delayAmount + 100;
    if (delayAmount > 2000) {
	delayAmount = startingDelay;
    }   

    LedBlinkDelay(redLed, delayAmount);
    LedBlinkDelay(blueLed, delayAmount);
    LedBlinkDelay(greenLed, delayAmount);

}

// this function
void LedBlinkDelay(int myPin, int myDelay)
{
    digitalWrite(myPin, HIGH);
    delay(myDelay);
    digitalWrite(myPin, LOW);
    delay(myDelay);
}

void BlinkStatusLed()
{
    digitalWrite(statusLed, HIGH);
    delay(statusDelay);
    digitalWrite(statusLed, LOW);
    delay(statusDelay);
}

Godzilla Puncher

Filed under: 5: Making Motion, Gaku Sato — ponkotsu @ 4:16 am

Circuitry & Controls:
The pot controls the servo position, on which Ultraman stands projecting his mighty energy beam. When he is aimed directly at the target, the photoresistor picks up the light. When that input exceeds a predefined threshold, a GO signal is sent to the transistor, which activates the solenoid to punch Godzilla right in the face.

img_7153b.jpgimg_7151b.jpg

Unfortunately, I couldn’t get the solenoid to work. So Godzilla is not punched in the face, and the people of Tokyo will not today be able to escape the always-happening disaster and the credits will not scroll. The solenoid works when it’s just straight 5V to ground, but won’t work when I plug it into a digital pin and output HIGH. The transistor circuit works with a resistor-LED combo in place of the solenoid. I’m not sure what’s going on here. So I’m posting this failure for reference only.

Servo Programming:
The servo control is similar to others’. It’s the only one I’ve come across online, and I’m assuming everyone got it there. The problem I found here was that the potentiometer input only seems to serve as speed control and not position control. I can get the servo to stop (v=0) at a specific pot position but that doesn’t correspond to servo position. I know servos with feedback loops can do position control, but can these not? I don’t know what the control signal is telling the servo to do, so I can’t even figure out the code. Am I doing something wrong here?

Lastly, I still can’t get the code to display below properly. I manually typed in the apostrophes but nothing. I just got another saved draft that crashes IE when I try to edit it. Fantastic. I’ll try to get something working soon…
I’ll be asking what the deal is in class tomorrow.

int PowerPin1 = 13; // power pin - potentiometer
int PowerPin2 = 2;  // power pin - photoresistor
int PotPin = 0;     // input pin - potentiometer
int PhotoPin = 5;   // input pin - photoresistor
int ServoPin = 9;   // output pin - servo
int SolePin = 4;    // output pin - solenoid

int minPulse = 500;
int maxPulse = 2500;
int pulse = minPulse;
long lastPulse = 0;
int refreshTime = 20;

int punch = 0;

void setup()
{
  Serial.begin(9600);
  pinMode(PowerPin1, OUTPUT);
  pinMode(PowerPin2, OUTPUT);
  pinMode(PotPin, INPUT);        // 0~1000
  pinMode(PhotoPin, INPUT);      // 800+
  pinMode(ServoPin, OUTPUT);
  pinMode(SolePin, OUTPUT);
  digitalWrite(PowerPin1, HIGH);
  digitalWrite(PowerPin2, HIGH);
  digitalWrite(ServoPin, LOW);
  digitalWrite(SolePin, LOW);
}

void loop()
{
  pulse = analogRead(PotPin) * 2 - 20 + minPulse;
  if(millis() - lastPulse >= refreshTime)
  {
    digitalWrite(ServoPin, HIGH);
    delayMicroseconds(pulse);
    digitalWrite(ServoPin, LOW);
    lastPulse = millis();
  }
  if(analogRead(PhotoPin)>800 && punch == 0)
  {
    punch = 1;
    digitalWrite(SolePin, HIGH);
    delay(500);
    digitalWrite(SolePin, LOW);
  }
  if(analogRead(PhotoPin<800)) {punch = 0;}
}

Blog at WordPress.com.