Making Things Interactive

March 26, 2008

More State Machine Examples

Filed under: Class Notes,Course Materials — jet @ 2:16 pm

There are two examples in the PDF:

  1. using the switch/case statement to implement a state machine.  It’s not crucial that you understand this, but if it makes sense to you, it’s cleaner than using repeated if/else statements.  There are explanations in the comments, but also read the arduino docs.
  2. changing PulseLed so that it can read a button while making the LED grow brighter and darker.  This involves havnig PulseLed return a “boolean” value of “true” or “false” and changing the statemachine to use this value to change state.  See the comments for full details.

state machine examples #2

Advertisements

March 21, 2008

Course Notes – 18 Mar 08

Filed under: Class Notes,Course Materials — jet @ 1:23 pm

We spent a fair amount of time talking about state machines. It’s an abstract concept you probably haven’t used before, but after you get your head around it will seem quite obvious.

Since there were a couple of code examples, I put them all in a single PDF.

arduino state machine code examples

February 26, 2008

Course Notes – 26 Feb 08

Filed under: Class Notes,Course Materials — jet @ 6:47 pm

Resources:

Class Resource Page – has long lists of local and mailorder places to buy things. Remember to ask here and on the blog to coordinate group orders, you can pay for overnight and split the cost several ways.

Techniques:

Charliplexing – driving a lot of LEDs with only a few pins. You don’t have to understand why it works, but it’s easy to set up and there are plenty of examples using Arduino.

LED drivers – simple chips that can be used to turn on and off a number of switches

LED multiplexers – another way to turn lots of LEDs on and off. I find these the easiest to understand and work with.

February 20, 2008

Course Notes – 19 Feb 2008

Filed under: Class Notes,Course Materials — jet @ 3:09 pm

Notes from Tuesday, 19 Feb 2008. Lots of sample code to experiment with in the notes and a couple of simple state diagrams to think about.

Iteration and State 1

Two Simple State Diagrams

February 14, 2008

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);
}

February 8, 2008

Class Notes – 7 Feb 08

Filed under: Class Notes,Course Materials — jet @ 2:52 pm

Follows are the notes/diagrams/code from the second circuits lecture. If this is still confusing, take a look at the ITP tutorials. Keep in mind that they draw 9v power from the board instead of using an external battery pack, but other than that, we’re doing roughly the same sorts of things. Don’t get too freaked out by the complexity of what they do, it’s an entire graduate program and they spend a lot of time on physical computing as a result.

Circuits-2 notes and diagrams

February 1, 2008

Class Notes – Arduino Basics

Filed under: Class Notes,Course Materials — jet @ 3:13 pm

Notes from the first Arduino session: Arduino-1

January 23, 2008

Class Notes – 22 Jan 08 – Circuits and Sensors

Filed under: Class Notes,Course Materials — jet @ 6:29 pm

As promised, here are the notes. They’re in PDF, let me know if you have problems opening them.

Sensors-1

Circuits-1

Circuits-1 Example Circuits

January 17, 2008

Class Notes – 17 Jan 08

Filed under: Class Notes,Course Materials — jet @ 6:29 pm

Interactive Birthday Cake

Lee Byron’s (CMU) New Years Dance Party

Daniel Rozin’s Wooden Mirror

Johnny Chung Lee’s (CMU) Various Projects, including using the Wii remote with VR software.

Mobile phone aided museum guidance.

Lighttracer – interactive video/painting system.

Carnegie Mellon’s SenseChair.

Blog at WordPress.com.