Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * final prototype
- * 9/26/2017
- */
- #include <LiquidCrystal.h>
- #include <Servo.h>
- LiquidCrystal lcd (11, 12, 13, 16, 17, 15);
- const int photoPin = A3;
- int photoVal;
- Servo miServito ;
- const int PotPin= A0;
- int PotVal = 0;
- int angle = 0;
- const int pinButton= 2;
- const int SER =8;
- const int LATCH =9;
- const int CLK =10;
- int lights[15] ={1, 2, 4, 8, 16, 32, 16, 8, 4, 2, 1};
- int bar[15] = {1, 3, 7, 15, 31, 63, 127, 63, 31, 15, 7, 3, 1};
- int readVal= 0;
- int ledPin = 8; // choose the pin for the LED
- int inputPin = 4; // choose the input pin (for PIR sensor)
- int pirState = LOW; // we start, assuming no motion detected
- int val = 0;
- void setup()
- {
- pinMode(pinButton, INPUT);
- lcd.begin (16, 2);
- lcd.print( "hello");
- miServito.attach(5);
- pinMode ( PotPin, INPUT);
- Serial.begin (9600);
- Serial.println (analogRead(PotPin));
- pinMode(ledPin, OUTPUT); // declare LED as output
- pinMode(inputPin, INPUT); // declare sensor as input
- pinMode(SER, OUTPUT);
- pinMode(LATCH, OUTPUT);
- pinMode(CLK, OUTPUT);
- pinMode(pinButton, INPUT);
- digitalWrite(LATCH, LOW);
- shiftOut(SER, CLK, MSBFIRST, B111111);
- digitalWrite(LATCH, HIGH);
- }
- void loop()
- {
- PotVal= analogRead(PotPin);
- angle = map( PotVal, 0, 1023, 0, 179);
- angle= constrain(angle, 0, 179);
- miServito.write( angle);
- {
- for (int i = 0; i < 12; i++)
- {
- digitalWrite(LATCH, LOW);
- shiftOut (SER, CLK, MSBFIRST, bar[i]);
- digitalWrite(LATCH, HIGH);
- delay(100);
- }
- //{
- // if( pirState== HIGH)
- //
- //}
- }
- {
- val = digitalRead(inputPin); // read input value
- if (val == HIGH) { // check if the input is HIGH
- digitalWrite(ledPin, HIGH); // turn LED ON
- if (pirState == LOW) {
- // we have just turned on
- Serial.println("Motion detected!");
- // We only want to print on the output change, not state
- pirState = HIGH;
- }
- } else {
- digitalWrite(ledPin, LOW); // turn LED OFF
- if (pirState == HIGH){
- // we have just turned of
- Serial.println("Motion ended!");
- // We only want to print on the output change, not state
- pirState = LOW;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement