As computing becomes more ubiquitous in our objects, designers need to be more aware of how to design meaningful interactions into electronically enhanced objects. At the University of Washington, a class of junior Interaction Design majors is exploring this question. These pages chronicle their efforts.

Tuesday, May 1, 2012

Erin and Charissa: Catduino

For this week's experiment, we made a cat! Nothing groundbreaking or particularly new here, just trying to make something fun with the few sensors/actuators we have. Turn the dial to make the cat turn, and pet  the photo resistor on its head to make it glow brighter!



The code is after the break....





Turning Cat Code:
// Based on
// File > Examples > Servo > Knob
// Controlling a servo position using a 
// potentiometer (variable resistor)
// by Michal Rinott //
//also based on Fade, Analog Input (David Cuartielles, modified by Tom Igoe), and AnalogInOutSerial (Tom Igoe)
//April 30, 2012


#include <Servo.h>


Servo myservo;  // create servo object to
                // control a servo
                
int sensorPin = 0;  // analog pin used to 
                // connect the
                // potentiometer
int val;     // variable to read the 
             //value from the analog pin

int lightPin = A2;    // select the input pin for the potentiometer
int ledPin = 11;      // select the pin for the LED
int sensorValue = 0;  // variable to store the value coming from the sensor
int outputValue = 0;  //value output to the PWM (analog out)

             
void setup()
{
   // declare the ledPin as an OUTPUT:
  pinMode(ledPin, OUTPUT);  
  Serial.begin(9600);
  myservo.attach(9);// attaches the servo
    // servo on pin 9 to the servo object
    pinMode(0, INPUT); //analog pin 0 is an input
  
}

    
void loop()
{

  val = analogRead(sensorPin);// reads the value
               // of the potentiometer
               //(value between 0 and 900)
  Serial.println(outputValue);
  val = map(val, 0, 1023, 0, 179);
      // scale it to use it with the servo
      // (value between 0 and 180)
  myservo.write(val); // sets the servo
                      // according to the 
                      // scaled value
                      
  delay(15);          //waits for the servo
                      // to get there

 // read the value from the sensor:
  int sensorValue = analogRead(lightPin);  
outputValue = map(sensorValue, 60, 700, 0, 255);  
  // turn the ledPin on
  analogWrite(ledPin, outputValue);  
  // stop the program for <sensorValue> milliseconds:
  delay(10);          
          
}


No comments:

Post a Comment