Dozing Off

Idea:

My idea for the assignment is a person who is studying, turned on his desk lamp (digital input and output) then doses off and as the pressure sensor senses the body, the light starts dimming (analog input and output).

Clearer video where desk lamp lights https://studio.youtube.com/video/I4NiezThfGQ/edit

const int ledPin = 2;
const int buttonPin = 3;
const int eyePin = 5; 
int pressureValue = A0; 

byte prevButtonState = LOW;
bool brightness = HIGH;

void setup() {
  // put your setup code here, to run once:
  pinMode(ledPin, OUTPUT);
  pinMode(buttonPin, INPUT);
  pinMode(eyePin, OUTPUT);
  pinMode(pressureValue, INPUT);
 
  Serial.begin(9600);
}

void loop() {
  // read the button pin
  // store that in a local variable
  byte buttonState  = digitalRead(buttonPin);
  int pressureValue = analogRead(A0);

 int mappedPressureValue = map(pressureValue, 0,400, 0, 255);
  Serial.print(pressureValue);
    
   int constrainedValue = constrain(mappedPressureValue, 0, 255);
    analogWrite(5, constrainedValue);//0-255
   
  // print out the state of the button stored in the variable
  // record the current button state for use next time through loop
  prevButtonState = buttonState;

 
  if (buttonState == HIGH && prevButtonState == LOW) {
   digitalWrite(ledPin, HIGH);
    }
  // otherwise turn the LED off
   else {
    digitalWrite(ledPin, LOW);
  }
}

 

Leave a Reply