i want what is problem in this code it doesnt work with transmit code
reciver code
1 - gnd | arduino uno
2 - vcc 3.3v !!! not 5v |
3 - ce arduino pin 9 |
4 - csn arduino pin 10 |
5 - sck arduino pin 13 | 53
6 - mosi arduino pin 11 |
7 - miso arduino pin 12 |
8 - unused
///////////////////////////////////////////////////////////arduino uno//////////////////////////////////////////////////////////////////////
*/
/////////////pinos utilizados digital 3,5,6,8,9,10,11,12,13
#include <spi.h>
#include <nrf24l01.h>
#include <rf24.h>
#include <printf.h>
rf24 radio(9,10);
const uint64_t pipe = 0xe8e8f0f0e1ll;
int joystick[8];
//////////motor 1//////////////////////
byte in1 = 3;
byte in2 = 5;
////////////////////motor 2//////////////////////
byte in3 = 6;
byte in4 = 7;
/////////////////////////////////////////////////
void right(){
analogwrite(in3,250);
analogwrite(in4,0);
analogwrite(in1,250);
analogwrite(in2,0);
}
///////////////////////////////////////////////////
void left(){
analogwrite(in3,0);
analogwrite(in4,250);
analogwrite(in1,0);
analogwrite(in2,250);
}
///////////////////////////////////////////////////
void up(){
analogwrite(in3,250);
analogwrite(in4,0);
analogwrite(in1,0);
analogwrite(in2,250);
}
/////////////////////////////////////////////////
void down(){
analogwrite(in3,0);
analogwrite(in4,250);
analogwrite(in1,250);
analogwrite(in2,0);
}
//////////////////////////////////////////////////
void off(){
analogwrite(in3,0);
analogwrite(in4,0);
analogwrite(in1,0);
analogwrite(in2,0);
}
void setup()
{
serial.begin(9600);
delay(1000);
serial.println("");
radio.begin();
radio.openreadingpipe(1,pipe);
radio.startlistening();
pinmode(in1,output);
pinmode(in2,output);
pinmode(in3,output);
pinmode(in4,output);
}
void loop()
{
if ( radio.available() )
while (!radio.available())
{
radio.read( joystick, sizeof(joystick) ); // compile error
if (joystick[2]==0 ||joystick[1]){up();}
/////////////////////////////////////////
else if (joystick[3]==0 ||joystick[1]){right();}
/////////////////////////////////////////
else if (joystick[4]==0 ){down();}
/////////////////////////////////////////
else if (joystick[5]==0){left();}
serial.println("x = ");
serial.print(joystick[0]);
serial.println("y = ");
serial.print(joystick[1]);
serial.println("up = ");
serial.print(joystick[2]);
serial.println("right = ");
serial.print(joystick[3]);
serial.println("down = ");
serial.print(joystick[4]);
serial.println("left = ");
serial.print(joystick[5]);
serial.println("start = ");
serial.print(joystick[6]);
serial.println("select= ");
serial.print(joystick[7]);
}
else
{
serial.println("no radio available");
}
}
trasmit code0000000000
#include <spi.h>
#include "rf24.h"
#include <nrf24l01.h>
#include <printf.h>
rf24 radio(9,10);
const uint64_t pipe = 0xe8e8f0f0e1ll;
int joystick[8];
int selectbut = 7;
int startbut =6;
int rightbut = 3;
int upbut = 2;
int downbut = 4;
int leftbut = 5;
int joystickx = 0;
int joysticky = 1;
void setup() {
serial.begin(9600);
radio.begin();
printf_begin();
radio.openwritingpipe(pipe);
pinmode(upbut,input);
digitalwrite(upbut,low);
pinmode(rightbut,input);
digitalwrite(rightbut,low);
pinmode(downbut,input);
digitalwrite(downbut,low);
pinmode(leftbut,input);
digitalwrite(leftbut,low);
pinmode(selectbut,input);
digitalwrite(selectbut,low);
pinmode(startbut,input);
digitalwrite(startbut,low);
}
void loop()
{
joystick[0]=analogread(joystickx);
joystick[1]=analogread(joysticky);
joystick[2]=digitalread(upbut);
joystick[3]=digitalread(rightbut);
joystick[4]=digitalread(downbut);
joystick[5]=digitalread(leftbut);
joystick[6]=digitalread(startbut);
joystick[7]=digitalread(selectbut);
radio.write(joystick,sizeof(joystick));
serial.print("x = ");
serial.print(analogread(joystickx));serial.print(" ");
serial.print("y = ");
serial.print(analogread(joysticky));serial.print(" ");
serial.print("up = ");
serial.print(digitalread(upbut));serial.print(" ");
serial.print("right = ");
serial.print(digitalread(rightbut));serial.print(" ");
serial.print("down = ");
serial.print(digitalread(downbut));serial.print(" ");
serial.print("left = ");
serial.print(digitalread(leftbut));serial.print(" ");
serial.print("start = ");
serial.print(digitalread(startbut));serial.print(" ");
serial.print("select = ");
serial.print(digitalread(selectbut));serial.print(" ");
serial.print("\n");
}
1 - gnd | arduino uno
2 - vcc 3.3v !!! not 5v |
3 - ce arduino pin 9 |
4 - csn arduino pin 10 |
5 - sck arduino pin 13 | 53
6 - mosi arduino pin 11 |
7 - miso arduino pin 12 |
8 - unused
///////////////////////////////////////////////////////////arduino uno//////////////////////////////////////////////////////////////////////
*/
/////////////pinos utilizados digital 3,5,6,8,9,10,11,12,13
#include <spi.h>
#include <nrf24l01.h>
#include <rf24.h>
#include <printf.h>
rf24 radio(9,10);
const uint64_t pipe = 0xe8e8f0f0e1ll;
int joystick[8];
//////////motor 1//////////////////////
byte in1 = 3;
byte in2 = 5;
////////////////////motor 2//////////////////////
byte in3 = 6;
byte in4 = 7;
/////////////////////////////////////////////////
void right(){
analogwrite(in3,250);
analogwrite(in4,0);
analogwrite(in1,250);
analogwrite(in2,0);
}
///////////////////////////////////////////////////
void left(){
analogwrite(in3,0);
analogwrite(in4,250);
analogwrite(in1,0);
analogwrite(in2,250);
}
///////////////////////////////////////////////////
void up(){
analogwrite(in3,250);
analogwrite(in4,0);
analogwrite(in1,0);
analogwrite(in2,250);
}
/////////////////////////////////////////////////
void down(){
analogwrite(in3,0);
analogwrite(in4,250);
analogwrite(in1,250);
analogwrite(in2,0);
}
//////////////////////////////////////////////////
void off(){
analogwrite(in3,0);
analogwrite(in4,0);
analogwrite(in1,0);
analogwrite(in2,0);
}
void setup()
{
serial.begin(9600);
delay(1000);
serial.println("");
radio.begin();
radio.openreadingpipe(1,pipe);
radio.startlistening();
pinmode(in1,output);
pinmode(in2,output);
pinmode(in3,output);
pinmode(in4,output);
}
void loop()
{
if ( radio.available() )
while (!radio.available())
{
radio.read( joystick, sizeof(joystick) ); // compile error
if (joystick[2]==0 ||joystick[1]){up();}
/////////////////////////////////////////
else if (joystick[3]==0 ||joystick[1]){right();}
/////////////////////////////////////////
else if (joystick[4]==0 ){down();}
/////////////////////////////////////////
else if (joystick[5]==0){left();}
serial.println("x = ");
serial.print(joystick[0]);
serial.println("y = ");
serial.print(joystick[1]);
serial.println("up = ");
serial.print(joystick[2]);
serial.println("right = ");
serial.print(joystick[3]);
serial.println("down = ");
serial.print(joystick[4]);
serial.println("left = ");
serial.print(joystick[5]);
serial.println("start = ");
serial.print(joystick[6]);
serial.println("select= ");
serial.print(joystick[7]);
}
else
{
serial.println("no radio available");
}
}
trasmit code0000000000
#include <spi.h>
#include "rf24.h"
#include <nrf24l01.h>
#include <printf.h>
rf24 radio(9,10);
const uint64_t pipe = 0xe8e8f0f0e1ll;
int joystick[8];
int selectbut = 7;
int startbut =6;
int rightbut = 3;
int upbut = 2;
int downbut = 4;
int leftbut = 5;
int joystickx = 0;
int joysticky = 1;
void setup() {
serial.begin(9600);
radio.begin();
printf_begin();
radio.openwritingpipe(pipe);
pinmode(upbut,input);
digitalwrite(upbut,low);
pinmode(rightbut,input);
digitalwrite(rightbut,low);
pinmode(downbut,input);
digitalwrite(downbut,low);
pinmode(leftbut,input);
digitalwrite(leftbut,low);
pinmode(selectbut,input);
digitalwrite(selectbut,low);
pinmode(startbut,input);
digitalwrite(startbut,low);
}
void loop()
{
joystick[0]=analogread(joystickx);
joystick[1]=analogread(joysticky);
joystick[2]=digitalread(upbut);
joystick[3]=digitalread(rightbut);
joystick[4]=digitalread(downbut);
joystick[5]=digitalread(leftbut);
joystick[6]=digitalread(startbut);
joystick[7]=digitalread(selectbut);
radio.write(joystick,sizeof(joystick));
serial.print("x = ");
serial.print(analogread(joystickx));serial.print(" ");
serial.print("y = ");
serial.print(analogread(joysticky));serial.print(" ");
serial.print("up = ");
serial.print(digitalread(upbut));serial.print(" ");
serial.print("right = ");
serial.print(digitalread(rightbut));serial.print(" ");
serial.print("down = ");
serial.print(digitalread(downbut));serial.print(" ");
serial.print("left = ");
serial.print(digitalread(leftbut));serial.print(" ");
serial.print("start = ");
serial.print(digitalread(startbut));serial.print(" ");
serial.print("select = ");
serial.print(digitalread(selectbut));serial.print(" ");
serial.print("\n");
}
code: [select]
radio.read( joystick, sizeof(joystick) ); // compile error
you seem have forgotten post compiler error.
the read() function not populate array of ints.
you failed read stickies @ top of forum, have learned post code properly.
Arduino Forum > Using Arduino > Programming Questions > i want what is problem in this code it doesnt work with transmit code
arduino
Comments
Post a Comment