Dodanie jeszcze jednego Serwa.

Masz problem z Arduino? Tutaj możesz szukać pomocy.
ODPOWIEDZ
darex120
Młodszy majsterkowicz
Posty: 23
Rejestracja: 5 lut 2018, 17:36

Dodanie jeszcze jednego Serwa.

Post autor: darex120 » 10 maja 2018, 15:44

Witam Serdecznie , mam pytanie ,bo w żaden sposób nie mogę sobie z tym poradzić , chciałbym dodać jeszcze jedno Serwo ,siedzę z tym od rana i za nic w świecie nie daję rady ,mógłbym prosić o pomoc?

Kod Nadajnika

Kod: Zaznacz cały


/*
---- Transmitter Code ----
Mert Arduino Tutorial & Projects (YouTube)
Please Subscribe for Support
*/

#include <SPI.h>                      //the communication interface with the modem
#include "RF24.h"                     //the library which helps us to control the radio modem

int msg[1];


RF24 radio(9,10);                    

const uint64_t pipe = 0xE8E8F0F0E1LL; //the address of the modem, that will receive data from Arduino.


void setup(void){
  radio.begin();                      //it activates the modem.
  radio.openWritingPipe(pipe);        //sets the address of the receiver to which the program will send data.
}

void loop(void){
  msg[0] =  map (analogRead(0), 0, 1023, 0, 179); 
  radio.write(msg, 1);
  msg[1] =  map (analogRead(1), 0, 1023, 0, 179); 
  radio.write(msg, 2);
  
}

Kod Odbiornika

Kod: Zaznacz cały

/*
---- Receiver Code ----
Mert Arduino Tutorial & Projects (YouTube)
Please Subscribe for Support
*/

#include <Servo.h>    //the library which helps us to control the servo motor
#include <SPI.h>      //the communication interface with the modem
#include "RF24.h"     //the library which helps us to control the radio modem

Servo myServo;        //define the servo name

RF24 radio(9,10);     /*This object represents a modem connected to the Arduino. 
                      Arguments 5 and 10 are a digital pin numbers to which signals 
                      CE and CSN are connected.*/

const uint64_t pipe = 0xE8E8F0F0E1LL; //the address of the modem,that will receive data from the Arduino.

int msg[1];


void setup(){
  myServo.attach(3);   //3 is a digital pin to which servo signal connected.
  myServo.attach(4);
  
  radio.begin();                    //it activates the modem.
  radio.openReadingPipe(1, pipe);
  radio.openReadingPipe(2, pipe); //determines the address of our modem which receive data.
  radio.startListening();           //enable receiving data via modem
  }

void loop(){
  if(radio.available()){            //checks whether any data have arrived at the address of the modem
    bool done = false;              //returns a “true” value if we received some data, or “false” if no data.
    while (!done) {
      done = radio.read(msg, 1);
      myServo.write(msg[0]);
    }
        if(radio.available()){            //checks whether any data have arrived at the address of the modem
    bool done = false;              //returns a “true” value if we received some data, or “false” if no data.
    while (!done) {
      done = radio.read(msg, 2);
      myServo.write(msg[0]);
    }
  }
}
}

Co miesiąc do wygrania nagrody o wartości ponad 1600 zł!


ODPOWIEDZ

Strony partnerskie: