Advertisement
Guest User

Relay not functioning

a guest
Apr 5th, 2013
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1.  
  2. const int buttonPin = 3; // pin to read button
  3. const int mode1 = 4; // relay 1
  4. const int mode2 = 8; // relay 2
  5. const int mode3 = 2; // relay 3
  6. const int mode4 = 7; // relay 4
  7. int yay = 0; //using this because I have no idea what im doing
  8. int D = 0; //using to test button
  9. int B = 0; // total # of button presses
  10.  
  11. void setup()
  12. {
  13. Serial.begin(9600);
  14. pinMode(buttonPin, INPUT);
  15. pinMode(mode1, OUTPUT);
  16. pinMode(mode2, OUTPUT);
  17. pinMode(mode3, OUTPUT);
  18. pinMode(mode4, OUTPUT);
  19.  
  20. }
  21.  
  22. void loop()
  23. {
  24. D = digitalRead(buttonPin);
  25. // if button is pressed
  26. if( digitalRead(buttonPin) ) {
  27.  
  28. // increment count
  29. yay = ++B;
  30. // debounce
  31. delay(200);
  32. if(B == 4) {
  33.  
  34. switch (yay) {
  35. case 0:
  36. digitalWrite(mode1, HIGH);
  37. break;
  38. case 1:
  39. digitalWrite(mode2, HIGH);
  40. break;
  41. case 2:
  42. digitalWrite(mode3, HIGH);
  43. break;
  44. case 3:
  45. digitalWrite(mode4, HIGH);
  46. break;
  47. default:
  48. B = 0;
  49.  
  50.  
  51. }
  52. }
  53. Serial.print(B);
  54. Serial.print("\t");
  55. Serial.print(yay);
  56. Serial.print("\t");
  57. Serial.println(digitalRead(mode1));
  58.  
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement