ccarman602

Project-2

Nov 25th, 2021
663
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //light Induction Desk Lamp
  2. int soundPin = A2; // Analog sound sensor is to be attached to analog
  3. int lightPin = A6; //Analog light sensor is to be attached to analog
  4. int ledPin = 4; // Digital LED is to be attached to digital
  5.  
  6. void setup() {
  7.   pinMode(ledPin, OUTPUT);
  8.   pinMode(lightPin, INPUT);
  9.   pinMode(soundPin, INPUT);
  10. }
  11.  
  12. void loop(){
  13.   int soundState = analogRead(soundPin); // Read sound sensor’s value
  14.   int lightState = analogRead(lightPin); // Read light sensor’s value
  15.   // if the sound sensor's value is greater than 500 or the sound sensor's is less than 200, the light will be on.
  16.   //Otherwise, the light will be turned off
  17. if (soundState > 500 || lightState < 200) {
  18.   digitalWrite(ledPin, HIGH);
  19.   delay(500); //You can add the "//" to remove the delay
  20. }else{
  21.   digitalWrite(ledPin, LOW);
  22. }
  23. }
  24.  
RAW Paste Data