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.
Showing posts with label LED. Show all posts
Showing posts with label LED. Show all posts

Friday, June 13, 2014

Code and Diagram

Controlling a servo with a tact switch, and LED blinking tied to moisture sensor.






// Latest code June 4th
‪#‎include‬ <Servo.h>
Servo servoMain; // Define our Servo
const int buttonPin = 2; // the number of the pushbutton pin
// variables will change:
int buttonState = 0;
int pos = 0; // variable to store the servo position
int sensorPin = A0; // select the input pin for the potentiometer
int sensorValue = 0; // variable to store the value coming from the sensor
const int led = 13; // turn on
const int led2 = 3; // blinking
int ledState = LOW; // ledState used to set the LED
long previousMillis = 0; // will store last time LED was updated
long interval = 1000;
void setup() {
// declare the ledPin as an OUTPUT:
Serial.begin(9600);
pinMode(led, OUTPUT);
pinMode(led2, OUTPUT);
servoMain.attach(10); // servo on digital pin 10
pinMode(buttonPin, INPUT);
servoMain.write(90);
}
void loop() {
sensorValue = analogRead(sensorPin);
delay(1000);
Serial.print("sensor = " );
Serial.println(sensorValue);
if (sensorValue <= 200) { //350-390 range => blinking
digitalWrite(led, LOW);
// Only allowed button to be pressed if no water
// read the state of the pushbutton value:
//buttonState = ;
if (digitalRead(buttonPin) == 1) { // Ground
Serial.println(buttonState);
Serial.println(buttonPin);
servoMain.write(0);
delay(5000);
servoMain.write(90);
delay(500);
} else {
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
if (ledState == LOW) {
ledState = HIGH;
} else {
ledState = LOW;
}
digitalWrite(led2, ledState);
}
}
} else if (sensorValue >= 350) {
digitalWrite(led2, LOW); // turn off the other LED first
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
} else {
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
digitalWrite(led2, LOW); // turn the LED off by making the voltage LOW
}
}

Friday, April 25, 2014

Arduino Sensor Experiment | Anjelica Harlow + Albert Lui

Hi there. This is Albert and Angelica, we are now officially a group. I'm leaving for Toronto soon and wont be in class on next week so I figured I would get this out of the way as soon as possible. Pretty simple, I'm using a momentary push button as my 'sensor.'
Whenever the button is pressed down, the red LED lights up. I actually had to build my circuit with a resistor. Our textbook never really tells us why this is necessary and how the circuit actually works. I understand the code completely, but I don't quite understand the electronics. I have a few questions I'm hoping to ask Dominic in person.

Pressing the momentary button down to light up the red LED.

/*
Turns on an LED when the momentary switch is held down.
 */

int led = 13;
int button = 7;
int val = 0;

void setup() {              
  // initialize then digital pins as input/output for the LED an switch
  pinMode(led, OUTPUT);
  pinMode(button, INPUT);
}


void loop() {
  val = digitalRead(button);
  if (val == HIGH) { //switch is pressed
    digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  } else {
    digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  }
}

Thursday, April 24, 2014

Arduino Fibonacci Sequence LED | Albert Lui + Anjelica Harlow

Hi. This is Albert and Angelica. Here is the code for making an LED blink the Fibonacci Sequence. No fancy code or mathematical equations for this one. It basically treats the first Fibonacci number as if it were the beginning of a fencepost problem and solves it as a single unique case. It's true that performing the if/else check every single time the void loop is run seems to be redundant, but in reality, a single conditional statement test should have a negligible effect on the time complexity of the entire program. Variables are used to remember what values are in the n-1 and n-2 spots of the sequence and updated after blinking the LED.

/*
  A simple program that blinks an LED a number of times in accordance with the Fibonacci Sequence (1, 1, 2, 3, 5, 8, 13, 21 . . .)
  There are 3 second delays between each Fibonacci number.
 */

int led = 13;
int nMinus1 = 0; // keeps track of the previous number
int nMinus2 = 0; // keeps track of the number before the previous
int blinks = 0; // number of times to blink the LED


void setup() {              
  pinMode(led, OUTPUT);  
}

void loop() {
  // Takes care of the first case like a classic fencepost problem
  if (nMinus1 == 0) {
    digitalWrite(led, HIGH);
    delay(200);            
    digitalWrite(led, LOW);
    delay(200);
    nMinus1 = 1;
  } else {  
    blinks = nMinus1 + nMinus2;
    for (int x = 0; x < blinks; x++) {
      digitalWrite(led, HIGH);
      delay(300);            
      digitalWrite(led, LOW);  
      delay(300);            
    }
  nMinus2 = nMinus1;
  nMinus1 = blinks;
  }
  delay(3000);
}