Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.12 KB | None | 0 0
  1. int OUT1 = 2; // OUT1 is the output signal 1
  2. int OUT2 = 3; // OUT2 is the output signal 2
  3. int OUT3 = 4; // OUT3 is the output signal 3
  4. int LED7 = 5; // OUT3 is the output signal 3
  5.  
  6. int LEDOUT1 = 6; // LEDOUT1 is the feedback for OUT1
  7. int LEDOUT2 = 7; // LEDOUT2 is the feedback for OUT2
  8. int LEDOUT3 = 8; // LEDOUT3 is the feedback for OUT3
  9. int LEDOUT4 = 9; // LEDOUT3 is the feedback for OUT3
  10. int LEDSENSOR = 13;
  11.  
  12. int LEDSTATE1 = 0;
  13. int LEDSTATE2 = 0;
  14. int LEDSTATE3 = 0;
  15. int MasterState1 = 0;
  16. int MasterState2 = 0;
  17.  
  18. int forceSensor = 1; // forceSensor is connected to A0 to reading the forceSensor data
  19. int readingForceSensor; // variable to reading the forceSensor data
  20.  
  21.  
  22.  
  23. void setup() {
  24.  
  25. Serial.begin(9600);
  26.  
  27. pinMode(OUT1, OUTPUT); // declare OUT1 (digital pin 2) as an output
  28. pinMode(OUT2, OUTPUT); // declare OUT2 (digital pin 3) as an output
  29. pinMode(OUT3, OUTPUT); // declare OUT3 (digital pin 4) as an output
  30.  
  31. pinMode(LEDOUT1, OUTPUT); // declare LEDOUT1 (digital pin 5) as an output
  32. pinMode(LEDOUT2, OUTPUT); // declare LEDOUT2 (digital pin 6) as an output
  33. pinMode(LEDOUT3, OUTPUT); // declare LEDOUT3 (digital pin 7) as an output
  34. pinMode(LEDOUT4, OUTPUT); // declare LEDOUT3 (digital pin 7) as an output
  35. pinMode(LEDSENSOR, OUTPUT);
  36.  
  37. }
  38.  
  39. void loop() {
  40.  
  41. readingForceSensor = analogRead(forceSensor);
  42.  
  43. if ((readingForceSensor > 10) && (readingForceSensor < 200))
  44. {
  45. digitalWrite(OUT1, HIGH);
  46. digitalWrite(LEDOUT1, HIGH);
  47. digitalWrite(LEDSENSOR, HIGH);
  48. }
  49. else
  50. {
  51. digitalWrite(OUT1, LOW);
  52. digitalWrite(LEDOUT1, LOW);
  53. }
  54.  
  55.  
  56. if ((readingForceSensor > 200) && (readingForceSensor < 400))
  57. {
  58. digitalWrite(OUT2, HIGH);
  59. digitalWrite(LEDOUT2, HIGH);
  60. digitalWrite(LEDSENSOR, HIGH);
  61. delay(200);
  62. digitalWrite(LEDSENSOR, LOW);
  63. delay(200);
  64. }
  65. else
  66. {
  67. digitalWrite(OUT2, LOW);
  68. digitalWrite(LEDOUT2, LOW);
  69. }
  70.  
  71. if (readingForceSensor > 400) // if the force sensor is more than 400, OUT3 & LEDOUT3 gets a HIGH signal
  72. { // LEDSTATE3 goes HIGH
  73. digitalWrite(OUT3, HIGH); // OUTPUT 3 goes HIGH
  74. digitalWrite(LEDOUT3, HIGH);
  75. digitalWrite(LEDSENSOR, HIGH); // LED 1 goes HIGH} // LED 1 goes HIGH
  76. delay(70);
  77. digitalWrite(LEDSENSOR, LOW);
  78. delay(70);// LED 3 goes HIGH
  79. }
  80. else // if not the switchPin gives a LOW signal
  81. {
  82. digitalWrite(OUT3, LOW); // OUTPUT 3 goes LOW
  83. digitalWrite(LEDOUT3, LOW);
  84. }
  85.  
  86.  
  87.  
  88. if (readingForceSensor < 1)
  89. {digitalWrite(LEDSENSOR, LOW);}
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement