Advertisement
Krejzi_Dark

rc-lights

May 7th, 2024 (edited)
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. void loop() {
  2. in_str = pulseIn(STR, HIGH, pulse_time);
  3. in_thr = pulseIn(THR, HIGH, pulse_time);
  4.  
  5. in_ch3 = pulseIn(CH3, HIGH, pulse_time);
  6. if (in_ch3 < 1100 || in_ch3 >= 2000) out_ch3 = 0;
  7. if (in_ch3 == 0 || in_ch3 >= 1100 && in_ch3 < 1600) out_ch3 = 1;
  8. if (in_ch3 >= 1600 && in_ch3 < 2000) out_ch3 = 2;
  9.  
  10. in_ch4 = pulseIn(CH4, HIGH, pulse_time);
  11. if (in_ch4 < 1100) out_ch4 = 0;
  12. if (in_ch4 >= 1100) out_ch4 = 1;
  13.  
  14. if (serial == 1) {
  15. Serial.print("in_str: ");
  16. Serial.print(in_str);
  17. Serial.print(" out_str: ");
  18. Serial.println(out_str);
  19.  
  20. Serial.print("in_thr: ");
  21. Serial.print(in_thr);
  22. Serial.print(" out_thr: ");
  23. Serial.println(out_thr);
  24.  
  25. Serial.print("in_ch3: ");
  26. Serial.print(in_ch3);
  27. Serial.print(" out_ch3: ");
  28. Serial.println(out_ch3);
  29.  
  30. Serial.print("in_ch4: ");
  31. Serial.print(in_ch4);
  32. Serial.print(" out_ch4: ");
  33. Serial.println(out_ch4);
  34. }
  35.  
  36. analogWrite(FW, 255);
  37.  
  38. //Rear Light
  39. if (in_thr > neut_thr - 50 && in_thr < neut_thr + 50) {
  40. analogWrite(RL, 255);
  41. start = millis(); // start czas bezczynnosci
  42. } else {
  43. analogWrite(RL, 0);
  44. start = 0;
  45. }
  46.  
  47. //Reverse Gear
  48. if (in_thr >= neut_thr + 50) {
  49. analogWrite(RG, 255);
  50. } else {
  51. analogWrite(RG, 0);
  52. }
  53.  
  54. //Fasher
  55. if (in_str < neut_str - 150) {
  56. //Right Flasher
  57. analogWrite(RF, 255);
  58. delay(400);
  59.  
  60. analogWrite(RF, 0);
  61. delay(400);
  62.  
  63. } else if (in_str > neut_str + 150) {
  64. //Left Flasher
  65. analogWrite(LF, 255);
  66. delay(400);
  67.  
  68. analogWrite(LF, 0);
  69. delay(400);
  70. } else {
  71. analogWrite(LF, 0);
  72. analogWrite(RF, 0);
  73. }
  74.  
  75. /*/Warning Lights - inaction
  76. czas = millis() - start;
  77. if (czas > 10000) {
  78. Serial.println("Warning Lights - inaction");
  79. analogWrite(RF, 255);
  80. analogWrite(LF, 255);
  81. delay(400);
  82.  
  83. analogWrite(RF, 0);
  84. analogWrite(LF, 0);
  85. delay(400);
  86. } else {
  87. analogWrite(RF, 0);
  88. analogWrite(LF, 0);
  89. }*/
  90.  
  91. //Winch
  92. if (out_ch3 == 1) {
  93. myservo.write(90);
  94. } else {
  95. //Winch In
  96. if (out_ch3 == 0) {
  97. myservo.write(82); //45
  98. }
  99. //Winch Out
  100. if (out_ch3 == 2) {
  101. myservo.write(98); //135
  102. }
  103. }
  104.  
  105. //Ledbar
  106. if (out_ch4 == 1) {
  107. digitalWrite(LB, HIGH);
  108. analogWrite(FD, 255);
  109. } else {
  110. digitalWrite(LB, LOW);
  111. analogWrite(FD, 0);
  112. }
  113. }
  114.  
  115.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement