Archive for November, 2009

Button Fun

November 3rd, 2009

This was my example. When you clicked the button, the face appeared and a sound file of a scream played.
I also suggested, to help students understand the interaction, that they could start with a picture of an animal, like a pig. If you clicked the tail, the image should change and a squeal should play.

iPhone Project with buttons and sound

  1. Create a background image

  2. Create a foreground image

  3. Create an icon image 57 x 57px

  4. Find a sound. Open the sound in Audacity and save as 32-bit sound.

  5. Open XCode

  6. Create a ViewBased Project

  7. Add the images and the sound

  8. Update the plist file

  9. Add a framework by CTRL+clicking on Frameworks. Select Existing Frameworks and add AudioToolbox.framework

  10. Open the header file

  11. Create a statement that imports the AudioToolbox/AudioToolbox.h

  12. Add 3 IBOutlets. One to hold a UILabel and the other two to hold pointers of type UIImageView

  13. Create a pointer of type NSTimer and name it resetTimer

  14. Create a a variable named sound of type SystemSoundID

  15. Create 3 @property declarations for the label and the UIImageViews

  16. Create a buttonPressed IBAction that takes sender of type id as its parameter.

  17. Open the implementation file

  18. @synthesize the properties

  19. Define the buttonPressed method:
    1. Set the text of your label to your message

    2. Create a pointer named foregroundImg of type UIImage and set it to the UIImage method imageNamed with the name of your foreground image as your parameter

    3. Set the image of the UIImageView that will pop up, to be the variable you just created (foregroundImg)

    4. Set the hidden property of that UIImageView to NO

    5. Test if sound and

      if the condition is met, then call:

    6. Test if resetTimer does NOT equal nil

      If the condition is met, then call:
      [resetTimer invalidate];

    7. Now set resetTimer to
      resetTimer = [NSTimer scheduledTimerWithTimeInterval:1.1 target:self selector:@selector(resetImages:) userInfo:nil repeats:NO];

  20. Now you have to define the method you just called (resetImages)

    - (void)resetImages:(NSTimer *)sender{


  21. Inside the method:
    1. Set the hidden property of the UIImageView that pops up to YES

    2. Empty the label.

    3. Set resetTimer to nil

  22. Navigate to and uncomment viewDidLoad

  23. After the call to super, include these lines (remember to update the name of your audio file):

    CFBundleRef mainBundle = CFBundleGetMainBundle();
    CFURLRef soundUrlRef = CFBundleCopyResourceURL(mainBundle, CFSTR ("aaaah2"), CFSTR ("wav"), NULL);

    // Create a system sound object representing the sound file
    AudioServicesCreateSystemSoundID (soundUrlRef, &sound);

  24. Open the nib file and add a UIImageView

  25. Using the inspector set it to hold your background image
  26. Add a label

  27. Add a button

  28. Add another UIImageView and align it with the bottom

  29. Connect The File Owner to label and select label

  30. Connect the button to the File Owner and select buttonPressed

  31. Connect the File Owner to the UIImageView aligned to the bottom and select the name holding the UIImageView that pops up

This project was inspired by Rory Lewis’s tutorials

Some early projects

November 2nd, 2009

Physical Computing

Here are a few of the recently completed projects:P1120064
FSR and LEDs

MovieA soft circuit button and LEDs

Potentiometer controlled LEDs with 2 modes controlled by a button

FSR controlled spooky eyes

A few other interesting projects are in the works. Two involve the capacitive sensor. The first uses a hacked disposable digital camera that flashes when the sensor is triggered. The second project was created as a Halloween installation. I hope there were pictures!