Assignment 3: Nina Prakash

Laughing Boy: An Animated Emoji

For this assignment I animated a laughing emoji face. The story goes that the boy is always happy and laughing but really needs his personal space, so as someone gets closer to him, he laughs more slowly. The further away people are from him, the harder he laughs.

Initially I had buttons as inputs so you “tickle” the face to make it laugh, but I changed it to an IR distance sensor just for fun. I had a bit of trouble with wiring it, but they were pretty simple mistakes so it worked pretty smoothly once I fixed them. Also the output readings from the IR sensor were different every time I uploaded it, but I fixed this by playing around with how I calculated the delay and soldering a pin to the end of the wire on the IR sensor. After that it worked pretty smoothly.

Video: https://youtu.be/b4o6-_xikzI

Everything else is included in this Drive file including fritzing sketch and reflection: https://drive.google.com/open?id=0Bw2BkLX-TTddTXVobmxxczVneDQ

Assignment 3: Motorized Emotions

Motorized Emotions:  Make a kinetic interaction that expresses an emotion.

Due:  Wed, 27 Sep, 23:59hrs.

Find an emotion you can display with motion.  A couple of examples I used in class:

  • Light makes plants happy:  Use a photoresistor to detect light and create more motion when there is more light, less motion when it is dark.
  • Cats like to be petted:  Use buttons or other inputs to “pet” your cat, use a servo for a wagging tail and tactors to simulate purring.

Document your project with a Fritzing sketch of your circuit, an Arduino sketch, and video.  I’d like everyone to demonstrate these in class on the following Thursday.

08 – class notes, 21 Sep 2017 — Intro to Power and Motors

Timing

Two short sketches showing how we can use the timing commands to blink and LED on and off without using delay() statements.

This is the version suggested in class:

// -*-c++-*-
/*
The MIT License (MIT)

Copyright (c) 2017 J. Eric Townsend

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/


/*
* This is a simple example that turns the LED on and off based on a single time.
*/


int debugLed = 13;
int blinkTime = 500;

bool ledState = LOW;
int now = 0;
int previous = 0;

void setup() {
// put your setup code here, to run once:
pinMode(debugLed, OUTPUT);
Serial.begin(115200);
}

void loop() {
now = millis();

if ((now - previous) > blinkTime) {
ledState = !ledState;
digitalWrite(debugLed, ledState);
previous = now;
}

}

You could also use if/else

// -*-c++-*-
/*
The MIT License (MIT)

Copyright (c) 2017 J. Eric Townsend

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/


/*
* This is a simple state machine that tracks the state of the LED and
* allows it to be on and off for different lengths of time.
*/


int debugLed = 13;
int blinkTimeOn = 1000;
int blinkTimeOff = 1000;

int ledOn = 1;
int ledOff = 2;

bool ledState = LOW;
int now = 0;
int lastOn = 0;
int lastOff = 0;

void setup() {
// put your setup code here, to run once:
pinMode(debugLed, OUTPUT);
Serial.begin(115200);
}

void loop() {
now = millis();

if (!ledState && ((now - lastOff) > blinkTimeOff)) {
ledState = HIGH;
lastOn = now;
} else if (ledState && ((now - lastOn) > blinkTimeOn)) {
ledState = LOW;
lastOff = now;
}

digitalWrite(debugLed, ledState);
}

Driving Actuators

Motors, solenoids, and servos require different methods of control and often require external sources of power.

Here’s a solenoid-example with a Fritzing doc showing the schematic.  There’s a similar method for using a motor that we will go over on Tuesday.

The basics of using a servo that we looked at in class.

Project 2 State Machines, Switch/Case, and For () Loops

For this project I utilized my previous configuration and implemented for () loops, switch/case, and a state machine to meet the requirements of this project. My previous code was all about 5 inputs that would turn on a light if pressed in the right order as well as an analog reading from the photo resistor. I proceeded to remove one of the 5 buttons as well as the photo resistor and work from the left over 4 inputs A-D. Since I am new to Arduino coding I did a very simple configuration in which each of the 4 buttons would make the LED behave differently. InputA would make the LED flash rapidly, InputB would make the LED pulse slower, InputC would make the LED fade from off to on, and InputC would make the LED fade to off. I practiced by trying to figure out the statement to fade on and once figured out reversed that to have it fade off and then copy pasted that into my for()loop. The rest of the commands were pretty simple.

Link to video- https://youtu.be/lUm5E2ytEoQ

Project2-20170920T170753Z-001

07 – class notes, 19 Sep 2017 — Crits and Assignments

07 – class notes, 19 Sep 2017 — Crits and Assignments

Assignment Submissions

In your Arduino sketch be sure to put your name, the assignment, and the date in comments in the start of the sketch.

If you cut-and-pasted something from another person’s sketch, give them credit!

Critiques

Starting with the next assignment we’ll try and have an informal crit of a few projects and do a more practiced version of tonight’s demo.

A guide for professional graphic designers and students that I think applies to our class.

This is from a class taught by Bruce Sterling:

Assignment 2: State Machines, switch/case, for() loops

The second assignment is about state machines, switch/case and for() statements.

As before, go through the process of coming up with an idea, planning it, implementing it, then documenting your project. If you are going to post your project to google docs, please make sure the link is sharable with other people.

This assignment can be done using your Arduino circuit for Assignment 1. The requirements are to implement a state machine with at least four states and transition paths between those states. The transition path can be a switch, a photoresistor, a pot, or some other form of input you’ve learned outside of class.  You’re free to use other outputs or make your own switches, there’s also the collection of components in A10.

Your state machine should use switch/case to change state and for() loops to create output.

Document your entire process, from your first idea, the circuits that didn’t work, the changes you made, and what was the final result. In your documentation, ask yourself what you learned, what went wrong, what you’d do differently if you did it a second time.

To submit your project, post a reply with the documentation. Attach a zip file to that post containing your Arduino sketch, a photo of your finished breadboard circuit, and anything else you think is relevant. I’m working on how we can post video to the blog, but for now you could post it to your AFS account and link to that from your submission.

Due 23:59, Monday, 18 September. Let me know ASAP if you have a conflict and will be submitting late, if you talked to me after class please send me email as a reminder.

06 – class notes, 14 Sep 2017 — State Machines II

06 – class notes, 14 Sep 2017 — State Machines II

Switch/Case Statements

Switch/Case statements are useful for implementing state machines. There are two good exercises on the arduino site, Tutorial1 lays out a simple example and Tutorial2 shows how to use the “default:” case as “turn everything off”.

Here’s class responses for a “make a state machine” assignment I taught in the first Making Things Interactive, there are good examples of switch/case statements in these submissions.

for() Loops

for() loops are a way to iterate through a range of values and take an action on each iteration.  In my example (below) I use for() loops to pulse a light on and off.  In the arduino tutorial they use it for a “Knight Rider” effect of cycling through LEDs.

// -*-c++-*-
/*
  The MIT License (MIT)

  Copyright (c) 2017 J. Eric Townsend

  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to deal
  in the Software without restriction, including without limitation the rights
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  THE SOFTWARE.
*/



const int onOffPin = 2;
const int switch1Pin = 7;
const int switch2Pin = 8;

const int yellowLEDPin = 3;
const int redLEDPin = 5;
const int blueLEDPin = 6;

const int redOn = 1;
const int redOff = 0;
int redStatus = redOff;

const int blueOn = 1;
const int blueOff = 0;
int blueStatus = blueOff;

const int yellowOn = 1;
const int yellowOff = 0;
int yellowStatus = yellowOff;

const int noLED = 0;
const int redLED = 1;
const int blueLED = 2;
const int yellowLED = 3;

int activeLED = noLED;
int activeLEDPin = 0;

const int maxPWM = 255;
const int lowPWM = 0;

int pushCount = 0;

int currentPWM = 0;

void setup() {

  Serial.begin(115200);
  pinMode (onOffPin, INPUT);
  pinMode (switch1Pin, INPUT);
  pinMode (switch2Pin, INPUT);

  pinMode(yellowLEDPin, OUTPUT);
  pinMode(redLEDPin, OUTPUT);
  pinMode(blueLEDPin, OUTPUT);
}

void loop() {

  if (digitalRead(switch1Pin) == HIGH) {
    activeLED++;
    if (activeLED > yellowLED) {
      activeLED = noLED;
    }
  }
  if (digitalRead(onOffPin) == HIGH) {
    //    if (redStatus || blueStatus || yellowStatus) {
    if (activeLED != noLED)  {
      switch (activeLED) {
        case redLED:
          activeLEDPin = redLEDPin;
          break;
        case blueLED:
          activeLEDPin = blueLEDPin;
          break;
        case yellowLED:
          activeLEDPin = yellowLEDPin;
          break;
        default:
          Serial.println("WARNING");
          // if nothing else matches, do the default
          // default is optional
          break;
      }
      analogWrite(yellowLEDPin, lowPWM);
      analogWrite(blueLEDPin, lowPWM);
      analogWrite(redLEDPin, lowPWM);

      for (int v = lowPWM; v < maxPWM; v++) {
        delay(10);
        analogWrite(activeLEDPin, v);
        //          analogWrite(yellowLEDPin, v);
        //          analogWrite(blueLEDPin, v);
        //          analogWrite(redLEDPin, v);
      }

    }
  }
  else   {
    //
    //    for (int v = maxPWM; v > lowPWM; v--) {
    //      delay(10);
    //      analogWrite(yellowLEDPin, v);
    //      analogWrite(blueLEDPin, v);
    //      analogWrite(redLEDPin, v);
    //    }
    activeLED == noLED;
    analogWrite(yellowLEDPin, lowPWM);
    analogWrite(blueLEDPin, lowPWM);
    analogWrite(redLEDPin, lowPWM);
  }

}
// -*-c++-*-
/*
  The MIT License (MIT)

  Copyright (c) 2017 J. Eric Townsend

  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to deal
  in the Software without restriction, including without limitation the rights
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  THE SOFTWARE.
*/



const int onOffPin = 2;
const int switch1Pin = 7;
const int switch2Pin = 8;

const int yellowLEDPin = 3;
const int redLEDPin = 5;
const int blueLEDPin = 6;

const int redOn = 1;
const int redOff = 0;
int redStatus = redOff;

const int blueOn = 1;
const int blueOff = 0;
int blueStatus = blueOff;

const int yellowOn = 1;
const int yellowOff = 0;
int yellowStatus = yellowOff;

const int noLED = 0;
const int redLED = 1;
const int blueLED = 2;
const int yellowLED = 3;

int activeLED = noLED;
int activeLEDPin = 0;

const int maxPWM = 255;
const int lowPWM = 0;

int pushCount = 0;

int currentPWM = 0;

void setup() {

  Serial.begin(115200);
  pinMode (onOffPin, INPUT);
  pinMode (switch1Pin, INPUT);
  pinMode (switch2Pin, INPUT);

  pinMode(yellowLEDPin, OUTPUT);
  pinMode(redLEDPin, OUTPUT);
  pinMode(blueLEDPin, OUTPUT);
}

void loop() {

  if (digitalRead(switch1Pin) == HIGH) {
    activeLED++;
    if (activeLED > yellowLED) {
      activeLED = noLED;
    }
  }
  if (digitalRead(onOffPin) == HIGH) {
    //    if (redStatus || blueStatus || yellowStatus) {
    if (activeLED != noLED)  {

      if (activeLED == redLED) {
        activeLEDPin = redLEDPin;
      }
      else if (activeLED == blueLED) {
        activeLEDPin = blueLEDPin;
      }
      else if (activeLED == yellowLED) {
        activeLEDPin = yellowLEDPin;
      }
      else {
        Serial.println("WARNING");
      }
    }
    for (int v = lowPWM; v < maxPWM; v++) {
      delay(10);
      analogWrite(activeLEDPin, v);
      //          analogWrite(yellowLEDPin, v);
      //          analogWrite(blueLEDPin, v);
      //          analogWrite(redLEDPin, v);
    }

  }
}
else   {
  //
  //    for (int v = maxPWM; v > lowPWM; v--) {
  //      delay(10);
  //      analogWrite(yellowLEDPin, v);
  //      analogWrite(blueLEDPin, v);
  //      analogWrite(redLEDPin, v);
  //    }
  activeLED == noLED;
  analogWrite(yellowLEDPin, lowPWM);
  analogWrite(blueLEDPin, lowPWM);
  analogWrite(redLEDPin, lowPWM);
}

}