Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <nRF24L01.h>
  3. #include <RF24.h>
  4. #include <Servo.h>
  5.  
  6. RF24 radio(7, 8); // CE, CSN
  7. const byte addresses[6] = "00001";
  8. const int enbA = 5;
  9. const int IN1 = 4;
  10. const int IN2 = 3;
  11. int s1 = 0;
  12. int s2 = 0;
  13. int spe, dir, vol;
  14.  
  15. typedef struct{
  16. int viteza;
  17. int unghi;
  18. } mesaj;
  19.  
  20. Servo myServo;
  21.  
  22.  
  23. void setup() {
  24. pinMode(enbA, OUTPUT);
  25. pinMode(IN1, OUTPUT);
  26. pinMode(IN2, OUTPUT);
  27.  
  28. digitalWrite(IN1, LOW);
  29. digitalWrite(IN2, HIGH);
  30. myServo.attach(6);
  31.  
  32. radio.begin();
  33. radio.openReadingPipe(0, addresses);
  34.  
  35. radio.setPALevel(RF24_PA_LOW);
  36. radio.setDataRate(RF24_2MBPS);
  37. radio.setChannel(124);
  38.  
  39. Serial.begin(9600);
  40. }
  41.  
  42. void loop() {
  43.  
  44. delay(5);
  45. radio.startListening();
  46. if ( radio.available()) {
  47. while (radio.available()) {
  48.  
  49. mesaj mesajDePrimit;
  50.  
  51.  
  52. radio.read(&mesaj, sizeof(mesaj));
  53.  
  54.  
  55.  
  56.  
  57. vol = map (mesajDePrimit.unghi, 0, 1023, -135, 135);
  58. dir = map (mesajDePrimit.unghi, 350, 650, 80, 92);
  59. spe = map (mesajDePrimit.viteza , 0, 1023, 0, 255);
  60.  
  61. Serial.print("Volan: ");
  62. Serial.print(mesajDePrimit.unghi);
  63. //Serial.print(" Directie: ");
  64. // Serial.print(dir);
  65. Serial.print(" Viteza: ");
  66. Serial.println(mesajDePrimit.viteza);
  67.  
  68.  
  69. myServo.write(dir);
  70. analogWrite(enbA, spe);
  71.  
  72. }
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement