Exercise 11

Input Device

The board I designed in exercise 06 has two input sensors on it. The button and the light sensor. The light sensor's value is read by the Atiny85 and depending on the value an onboard led is lit or not. The threshhold values prevent the led from flickering. The button can invert the conditions when the led is lit. The pinheader is made to connect a RGB led stripe and the button would then serve as a switch to go through different modes.

int photoResistor = 0;
int onThreshold = 400;
int offThreshold = 350;
boolean button = false;

void setup() {
  pinMode(3, OUTPUT); //LED
  pinMode(0,  INPUT);
}

void loop() {
  photoResistor = analogRead(4);
  button = digitalRead(0);

  if(button){
    if (photoResistor > onThreshold){
        analogWrite(3, HIGH);
    }
    else {
      if(photoResistor <= offThreshold) {
          analogWrite(3, LOW);
      }
    }
  }else{
    if (photoResistor > onThreshold){
        analogWrite(3, LOW);
    }
    else {
      if(photoResistor <= offThreshold) {
          analogWrite(3, HIGH);
      }
    }
  }
}