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.

Sunday, April 17, 2016

Peter + Kylen = ~*~Arduino Logic Experiment~*~

We placed three LED lights onto our board, and made them correspond to the changing resistance. By changing the output of the sensor, the green, yellow, and red lights illuminate at different times. Green at the lowest voltage, yellow at the middle, and red at the most.




Our Code:

int led = 9;// the PWM pin the LED is attached to
int knob = 0;
int brightness = 0;// how bright the LED is
//int fadeAmount = 5;    // how many points to fade the LED by

void setup() {
  Serial.begin(9600);
  pinMode(led, OUTPUT);
  pinMode(A0, INPUT);
}

void loop() {
  analogWrite(led, 0);
  knob = analogRead(A0);

  if(knob < 400) {
    led = 11; //green
    Serial.print("green light ");
  }

  else if (knob > 400 && knob < 700) {
    led = 10; // yellow
    Serial.print("yellow light ");
  }

  else { //brightest
    led = 9; //red
    Serial.print("red light ");
  }

  Serial.print("knob is ");
  Serial.println(knob);
 
  brightness = map(knob,0,845,0,255);
  Serial.print("brightness is ");
  Serial.println(brightness);
  //brightness = brightness + fadeAmount;

  //if (brightness == 0 || brightness == 255) {
    //fadeAmount = -fadeAmount ;
  //}
  analogWrite(led,brightness);
  delay(200);
}

No comments:

Post a Comment