Advertisement
edofhell

Osmose Timer V0.3B2

Sep 16th, 2014
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. int green = 4;
  2. int brightness = 0;
  3. int fadeAmount = 5;
  4.  
  5. // Const int setup
  6. const int buttonPin = 10; // the number of the pushbutton pin
  7. const int Magnet = 2; // the number of the Magnet pin
  8. const int Ledstrip = 3; // the number of the Ledstrip pin
  9.  
  10.  
  11. // Time setup
  12. const long oneSecond = 1000; // a second is a thousand milliseconds
  13. const long oneMinute = oneSecond * 60;
  14. const long thirtyMinutes = oneMinute * 30;
  15. const long oneHour = oneMinute * 60;
  16. const long oneDay = oneHour * 24;
  17.  
  18.  
  19. int buttonState = 0; // variable for reading the pushbutton status
  20.  
  21.  
  22. void setup() {
  23.  
  24. // initialize the LED pin as an output:
  25. pinMode(Magnet, OUTPUT);
  26.  
  27. // initialize the pushbutton pin as an input:
  28. pinMode(buttonPin, INPUT);
  29.  
  30. // initialize the Ledstrip pin as an input:
  31. pinMode(Ledstrip, INPUT);
  32.  
  33. pinMode(green, OUTPUT);
  34.  
  35.  
  36. }
  37.  
  38.  
  39. void loop(){
  40. // read the state of the pushbutton value:
  41. buttonState = digitalRead(buttonPin);
  42.  
  43. // check if the pushbutton is pressed.
  44. // if it is, the buttonState is HIGH:
  45. if (buttonState == HIGH) {
  46.  
  47. // turn Ledstrip on:
  48. digitalWrite(Ledstrip, HIGH);
  49.  
  50. // turn magnet on:
  51. digitalWrite(Magnet, HIGH);
  52.  
  53. // run for 30 min
  54. delay(thirtyMinutes);
  55. }
  56.  
  57.  
  58. else {
  59.  
  60.  
  61. // turn Magnet off:
  62. digitalWrite(Magnet, LOW);
  63.  
  64. // turn Ledstrip off:
  65. digitalWrite(Ledstrip, LOW);
  66.  
  67. analogWrite(green, brightness);
  68. brightness = brightness + fadeAmount;
  69. if (brightness == 0 || brightness == 255) {
  70. fadeAmount = -fadeAmount ;
  71. delay(1200);}
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement