Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Const int setup
- const int buttonPin = 2; // the number of the pushbutton pin
- const int Magnet = 10; // the number of the Magnet pin
- const int Ledstrip = 9; // the number of the Ledstrip pin
- // Time setup
- const long oneSecond = 1000; // a second is a thousand milliseconds
- const long oneMinute = oneSecond * 60;
- const long thirtyMinutes = oneMinute * 30;
- const long oneHour = oneMinute * 60;
- const long oneDay = oneHour * 24;
- int buttonState = 0; // variable for reading the pushbutton status
- void setup() {
- // initialize the LED pin as an output:
- pinMode(Magnet, OUTPUT);
- // initialize the pushbutton pin as an input:
- pinMode(buttonPin, INPUT);
- // initialize the Ledstrip pin as an input:
- pinMode(Ledstrip, INPUT);
- }
- void loop(){
- // read the state of the pushbutton value:
- buttonState = digitalRead(buttonPin);
- // check if the pushbutton is pressed.
- // if it is, the buttonState is HIGH:
- if (buttonState == HIGH) {
- // turn Ledstrip on:
- digitalWrite(Ledstrip, HIGH);
- // turn magnet on:
- digitalWrite(Magnet, HIGH);
- // run for 30 min
- delay(thirtyMinutes);
- }
- else {
- // turn Magnet off:
- digitalWrite(Magnet, LOW);
- // turn Ledstrip off:
- digitalWrite(Ledstrip, LOW);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement