Advertisement
kogerr19

Prototype for Final

Jun 27th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. /*
  2. * final prototype
  3. * 9/26/2017
  4. */
  5.  
  6. #include <LiquidCrystal.h>
  7. #include <Servo.h>
  8.  
  9. LiquidCrystal lcd (11, 12, 13, 16, 17, 15);
  10. const int photoPin = A3;
  11. int photoVal;
  12. Servo miServito ;
  13. const int PotPin= A0;
  14. int PotVal = 0;
  15. int angle = 0;
  16. const int pinButton= 2;
  17. const int SER =8;
  18. const int LATCH =9;
  19. const int CLK =10;
  20. int lights[15] ={1, 2, 4, 8, 16, 32, 16, 8, 4, 2, 1};
  21. int bar[15] = {1, 3, 7, 15, 31, 63, 127, 63, 31, 15, 7, 3, 1};
  22. int readVal= 0;
  23. int ledPin = 8; // choose the pin for the LED
  24. int inputPin = 4; // choose the input pin (for PIR sensor)
  25. int pirState = LOW; // we start, assuming no motion detected
  26. int val = 0;
  27.  
  28. void setup()
  29.  
  30.  
  31. {
  32. pinMode(pinButton, INPUT);
  33. lcd.begin (16, 2);
  34. lcd.print( "hello");
  35. miServito.attach(5);
  36. pinMode ( PotPin, INPUT);
  37. Serial.begin (9600);
  38. Serial.println (analogRead(PotPin));
  39. pinMode(ledPin, OUTPUT); // declare LED as output
  40. pinMode(inputPin, INPUT); // declare sensor as input
  41. pinMode(SER, OUTPUT);
  42. pinMode(LATCH, OUTPUT);
  43. pinMode(CLK, OUTPUT);
  44. pinMode(pinButton, INPUT);
  45. digitalWrite(LATCH, LOW);
  46. shiftOut(SER, CLK, MSBFIRST, B111111);
  47. digitalWrite(LATCH, HIGH);
  48. }
  49.  
  50. void loop()
  51. {
  52. PotVal= analogRead(PotPin);
  53. angle = map( PotVal, 0, 1023, 0, 179);
  54. angle= constrain(angle, 0, 179);
  55. miServito.write( angle);
  56.  
  57. {
  58. for (int i = 0; i < 12; i++)
  59. {
  60. digitalWrite(LATCH, LOW);
  61. shiftOut (SER, CLK, MSBFIRST, bar[i]);
  62. digitalWrite(LATCH, HIGH);
  63. delay(100);
  64. }
  65.  
  66. //{
  67. // if( pirState== HIGH)
  68. //
  69. //}
  70.  
  71. }
  72. {
  73. val = digitalRead(inputPin); // read input value
  74. if (val == HIGH) { // check if the input is HIGH
  75. digitalWrite(ledPin, HIGH); // turn LED ON
  76. if (pirState == LOW) {
  77. // we have just turned on
  78. Serial.println("Motion detected!");
  79. // We only want to print on the output change, not state
  80. pirState = HIGH;
  81. }
  82. } else {
  83. digitalWrite(ledPin, LOW); // turn LED OFF
  84. if (pirState == HIGH){
  85. // we have just turned of
  86. Serial.println("Motion ended!");
  87. // We only want to print on the output change, not state
  88. pirState = LOW;
  89. }
  90. }
  91. }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement