Advertisement
Ollivier

RF433 servo potent Recepteur

Apr 28th, 2020
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. // ************************************************
  2. // * Branchements *
  3. // ************************************************
  4. // D0 =>
  5. // D1 =>
  6. // D2 => Récepteur RF433
  7. // D3 => Phares
  8. // D4 => Direction Moteur 1
  9. // D5 => Contrôle moteur 1
  10. // D6 => Contrôle moteur 2
  11. // D7 => Direction Moteur 2
  12. // D8 => Feux arrière et intérieure Rouge
  13. // D9 => Feux de position Bleus
  14. // D10 => Servo Tourelle
  15. // D11 => Servo Pince
  16. // D12 => Oeil (projecteur tourelle)
  17. // D13 => Buzzer
  18. // ************************************************
  19.  
  20. #include <RCSwitch.h>
  21. #include <Servo.h>
  22.  
  23. Servo monServo;
  24. Servo maPince;
  25. RCSwitch mySwitch = RCSwitch();
  26.  
  27. int rotationServo;
  28.  
  29. long temporisation;
  30.  
  31. int oeil = 12;
  32. int fArr = 8;
  33. int buzz = 13;
  34. int bleu = 9;
  35. bool etatOeil = 0;
  36. bool etatFArr = 0;
  37. bool etatBleu = 0;
  38. int lum = 0;
  39. int valBleu = 0;
  40. long temp;
  41.  
  42. void setup() {
  43. Serial.begin(115200);
  44. mySwitch.enableReceive(0);
  45. pinMode(oeil, OUTPUT);
  46. pinMode(fArr, OUTPUT);
  47. pinMode(bleu, OUTPUT);
  48. pinMode(buzz, OUTPUT);
  49. monServo.attach(10);
  50. maPince.attach(11);
  51. temp = millis();;
  52. }
  53.  
  54. void loop() {
  55.  
  56. // Partie qui ne fonctionne pas :( **********************************************************************************
  57.  
  58. if ((millis() - temp) >= 1500) { // on execute la suite toutes les 1.5 s
  59. Serial.println((millis() - temp)); // Debug ************************************************************
  60. if (analogRead(A0) != lum) { // on execute la suite que si la valeur de lum a changé
  61. lum = analogRead(A0); // lum prend la valeur lue en A0 (photorésistance)
  62. Serial.println(analogRead(A0)); // Debug ************************************************************
  63. valBleu = map(lum, 0, 1023, 255, 0); // valBleu prend la valeur de la conversion
  64. analogWrite(bleu, valBleu); // on allume les leds bleues de la valeur valBleu
  65. // Cela devrait, mais cela ne s'allume pas...
  66. Serial.println(valBleu); // Debug ************************************************************
  67. }
  68. temp = millis(); // on réinitialise le "chrono"
  69. }
  70. // ******************************************************************************************************************
  71. // Pourtant :
  72. // fonctionnait en D6 hier soir et un peu moins fort aujourd'hui (il fait jour)
  73. // (J'ai besoin du D6 pour le contrôle du futur moteur 2)
  74. // La led est bonne
  75. // La valeur valBleu varie bien, mais ne semble pas etre transmise à la led
  76. // tous les branchements sont vérifiés 200 fois :)
  77. // pas de faux contact
  78. // ******************************************************************************************************************
  79.  
  80. if (mySwitch.available()) {
  81. if (mySwitch.getReceivedValue() >= 3000 && mySwitch.getReceivedValue() < 4000) {
  82. Serial.println (mySwitch.getReceivedValue());
  83. rotationServo = mySwitch.getReceivedValue() - 3000;
  84. monServo.write(rotationServo);
  85. delay (200);
  86. mySwitch.resetAvailable();
  87. } else if (mySwitch.getReceivedValue() == 2001) {
  88. if (etatOeil == 1) {
  89. etatOeil = 0;
  90. } else if (etatOeil == 0) {
  91. etatOeil = 1;
  92. }
  93. digitalWrite(oeil, etatOeil);
  94. delay (500);
  95. } else if (mySwitch.getReceivedValue() == 2002) {
  96. if (etatFArr == 1) {
  97. etatFArr = 0;
  98. } else if (etatFArr == 0) {
  99. etatFArr = 1;
  100. }
  101. digitalWrite(fArr, etatFArr);
  102. delay (500);
  103. } else if (mySwitch.getReceivedValue() == 2003) {
  104. tone(buzz, 329, 200);
  105. delay (100);
  106. tone(buzz, 329, 200);
  107. delay (250);
  108. }
  109. mySwitch.resetAvailable();
  110. }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement