Last active
May 11, 2020 03:01
-
-
Save tjpeden/4d46bab2a85636c8c5c4c9c2415c0dae to your computer and use it in GitHub Desktop.
Pot driven relay toggle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is a global variable | |
const int relay1 = 7; // let's call pin 7 relay1 | |
// This is the setup function which gets run once, when the MCU gets reset | |
void setup() { | |
pinMode(relay1, OUTPUT); // set pin 7 to an output pin | |
digitalWrite(relay1, HIGH); // set pin 7 high | |
} | |
// This is the loop function which gets called repeatedly forever | |
void loop() { | |
int value = 100 + analogRead(A0); // read analog pin 0 and store it in `value` (adding 100 means it won't go below that) | |
digitalWrite(relay1, LOW); // set pin 7 low | |
delay(value); // wait `value` ms | |
digitalWrite(relay1, HIGH); // set pin 7 high | |
delay(value); // wait `value` ms | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment