ChocoBit

Управление светодиодом от датчика движения и света

Oct 22nd, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.41 KB | None | 0 0
  1. int lightPin = A0;
  2. int ledPin = 5;
  3. int motionPin = 4;
  4.  
  5. void setup() {
  6.   // put your setup code here, to run once:
  7.   Serial.begin(9600);
  8.   pinMode(motionPin, INPUT);
  9.   pinMode(ledPin, OUTPUT);
  10. }
  11.  
  12. void loop() {
  13.   int light = analogRead(lightPin);
  14.   bool motion = digitalRead(motionPin);
  15.   if (light < 900 && motion == HIGH) {
  16.     digitalWrite(ledPin, HIGH);
  17.   } else {
  18.     digitalWrite(ledPin, LOW);
  19.   }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment