Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <nRF24L01.h>
- #include <RF24.h>
- #include <Servo.h>
- RF24 radio(7, 8); // CE, CSN
- const byte addresses[6] = "00001";
- const int enbA = 5;
- const int IN1 = 4;
- const int IN2 = 3;
- int s1 = 0;
- int s2 = 0;
- int spe, dir, vol;
- typedef struct{
- int viteza;
- int unghi;
- } mesaj;
- Servo myServo;
- void setup() {
- pinMode(enbA, OUTPUT);
- pinMode(IN1, OUTPUT);
- pinMode(IN2, OUTPUT);
- digitalWrite(IN1, LOW);
- digitalWrite(IN2, HIGH);
- myServo.attach(6);
- radio.begin();
- radio.openReadingPipe(0, addresses);
- radio.setPALevel(RF24_PA_LOW);
- radio.setDataRate(RF24_2MBPS);
- radio.setChannel(124);
- Serial.begin(9600);
- }
- void loop() {
- delay(5);
- radio.startListening();
- if ( radio.available()) {
- while (radio.available()) {
- mesaj mesajDePrimit;
- radio.read(&mesaj, sizeof(mesaj));
- vol = map (mesajDePrimit.unghi, 0, 1023, -135, 135);
- dir = map (mesajDePrimit.unghi, 350, 650, 80, 92);
- spe = map (mesajDePrimit.viteza , 0, 1023, 0, 255);
- Serial.print("Volan: ");
- Serial.print(mesajDePrimit.unghi);
- //Serial.print(" Directie: ");
- // Serial.print(dir);
- Serial.print(" Viteza: ");
- Serial.println(mesajDePrimit.viteza);
- myServo.write(dir);
- analogWrite(enbA, spe);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement