Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********************************************
- * *
- * Relay Board Test Jig *
- * by Learnelectronics *
- * https://www.youtube.com/learnelectronics *
- * *
- ********************************************/
- void setup() { // Setup Loop - Runs once, set's the parameters of the Arduino
- pinMode(A0,INPUT); // set the analog 0 pin as input o control delay
- pinMode(7,OUTPUT); // set digital pins 7-4 as outputs
- pinMode(6,OUTPUT);
- pinMode(5,OUTPUT);
- pinMode(4,OUTPUT);
- digitalWrite(7,HIGH); // set digital pins 7-4 OUTPUT ON (HIGH)
- digitalWrite(6,HIGH); // relay works off of low signal
- digitalWrite(5,HIGH); // so a HIGH pin is an idle pin in this case
- digitalWrite(4,HIGH);
- }
- void loop() { //Main Loop - runs over and over
- int potraw = (analogRead(A0)); //get reading from the potentiomter on A0
- int waitfor = map(potraw, 0, 1024, 1, 254); //Take the raw value 0-1024 and convert it into
- //a 0-254 value the Arduino can use
- digitalWrite(7,LOW); //relay on
- delay(waitfor); //stay on for time determined by var waitfor
- digitalWrite(7,HIGH); //relay off
- digitalWrite(6,LOW);
- delay(waitfor);
- digitalWrite(6,HIGH);
- digitalWrite(5,LOW);
- delay(waitfor);
- digitalWrite(5,HIGH);
- digitalWrite(4,LOW);
- delay(waitfor);
- digitalWrite(4,HIGH);
- }
Advertisement
Add Comment
Please, Sign In to add comment