Advertisement
talofer99

Shutter For colin

May 14th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.44 KB | None | 0 0
  1. #define buttonPin  2 // the number of the pushbutton pin
  2. #define solenoidPin 4 // the number of the solenoid pin
  3. #define potPin A0 // Pot should be connected to this analog pin
  4. #define shutterMinTime 500 // min shutter millis
  5. #define shutterMaxTime 2000 // mas shutter millis
  6.  
  7.  
  8.  
  9. int selnoidOpenTime = 2000;
  10. unsigned long TimerStart;
  11. bool Timer_Started; // is set when Timer is started
  12.  
  13. // variables will change:
  14. boolean buttonState; // variable for reading the pushbutton status
  15.  
  16. void setup() {
  17.   // initialize the LED pin as an output: pin as an output:
  18.   pinMode(solenoidPin, OUTPUT);
  19.   // initialize the pushbutton pin as an input:
  20.   pinMode(buttonPin, INPUT);
  21. }
  22.  
  23. void loop() {
  24.   // read the state of the pushbutton value:
  25.   buttonState = digitalRead(buttonPin);
  26.  
  27.   // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  28.   if (buttonState == HIGH) {
  29.  
  30.     if (!Timer_Started) {
  31.       int analogReadValue = analogRead(potPin);
  32.       selnoidOpenTime = map(analogReadValue,0,1024,shutterMinTime,shutterMaxTime);
  33.  
  34.       digitalWrite(solenoidPin, HIGH); // Open // turn LED ON
  35.       TimerStart = millis(); // starting Timer
  36.       Timer_Started = true;
  37.     } //end if
  38.   } //end if
  39.  
  40.  
  41.   // if timer already started
  42.   if (Timer_Started) {
  43.     if (  TimerStart  + selnoidOpenTime <= millis()) {
  44.       digitalWrite(solenoidPin, LOW); // Open // turn LED OFF
  45.       Timer_Started = false;
  46.     } //end if
  47.   } //end if
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement