Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/147.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Arduino无线nrf24l01 i2c运行缓慢_C++_Performance_Arduino_I2c - Fatal编程技术网

C++ Arduino无线nrf24l01 i2c运行缓慢

C++ Arduino无线nrf24l01 i2c运行缓慢,c++,performance,arduino,i2c,C++,Performance,Arduino,I2c,我使用arduino pro mini制作了一个无线anamatronics平台,并与nrf24l01模块进行无线通信。我还使用Neopixels作为灯光。问题是,程序正在减慢周期,使褪色的led动画变得非常不稳定。有人能帮我找到是什么阻碍了我的代码,还是我正在使用的arduino没有达到标准 我包括了arduino pro mini控制木偶的代码 #define PIN 3 #define NUMPIXELS 6 #define UP 0 #define DOWN

我使用arduino pro mini制作了一个无线anamatronics平台,并与nrf24l01模块进行无线通信。我还使用Neopixels作为灯光。问题是,程序正在减慢周期,使褪色的led动画变得非常不稳定。有人能帮我找到是什么阻碍了我的代码,还是我正在使用的arduino没有达到标准

我包括了arduino pro mini控制木偶的代码

#define PIN            3
#define NUMPIXELS     6
#define UP 0
#define DOWN 1
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9, 10); // CE, CSN
//const byte address[6] = "00001";
const byte addresses[][6] = {"00001", "00002"};

int colorMode = 0;
unsigned long previousFadeMillis;
int brightness;
int fadeInterval = 1;
const byte pwmLED = 5;
byte fadeDirection = UP;
int fadeValue = 0;
byte fadeIncrement = 5;

// define directions for LED fade
#define UP 0
#define DOWN 1

// constants for min and max PWM
const int minPWM = 100;
const int maxPWM = 255;

typedef struct A_t {
  int X;
  int Y;
  int R;
  int G;
  int B;
  int Br;
};
A_t SendData;

typedef struct B_t {
  float nedVoltage;
  int connectCount;
};
B_t NedData;
void setup() {
  Serial.begin(9600);
  radio.begin();
  //radio.openReadingPipe(0, address);
  //radio.setPALevel(RF24_PA_MIN);

  radio.openWritingPipe(addresses[0]); // 00001
  radio.openReadingPipe(1, addresses[1]); // 00002
  radio.setPALevel(RF24_PA_MIN);
  radio.stopListening();
  NedData.connectCount = 0;

  strip.begin();
  strip.setPixelColor(4, 0, 200, 0);
  strip.setPixelColor(5, 0, 200, 0);
}
void loop() {
  unsigned long currentMillis = millis();
  switch (colorMode) {
    case 0:
      doTheFade(currentMillis);
      break;
    case 1:
      doTheFade(currentMillis);
      break;
    case 2:
      doTheFade(currentMillis);
      break;
    case 3:
      doTheFade(currentMillis);
      break;
  }
  while (radio.available()) {
    radio.read( &SendData, sizeof(SendData) );
    //char text[32] = "";
    //radio.read(&text, sizeof(text));
  }
  int sensorVoltage = analogRead(A0);
  float nedVoltage = sensorVoltage * (4.2 / 1023.0);
  NedData.nedVoltage = nedVoltage;
  NedData.connectCount = NedData.connectCount + 1;
  radio.stopListening();
  bool ok = radio.write( &NedData, sizeof(NedData) );
  radio.startListening();


  Serial.print("fadeValue = ");
  Serial.println(fadeValue);
  Serial.print("NedData.connectCount = ");
  Serial.println(NedData.connectCount);
  Serial.print("NedData.nedVoltage = ");
  Serial.println(NedData.nedVoltage);
  Serial.print("SendData.X = ");
  Serial.println(SendData.X);
  Serial.print("SendData.Y = ");
  Serial.println(SendData.Y);
  Serial.print("SendData.R = ");
  Serial.println(SendData.R);
  Serial.print("SendData.G = ");
  Serial.println(SendData.G);
  Serial.print("SendData.B = ");
  Serial.println(SendData.B);
  Serial.print("SendData.Br = ");
  Serial.println(SendData.Br);
}
void doTheFade(unsigned long thisMillis) {
  // is it time to update yet?
  // if not, nothing happens
  if (thisMillis - previousFadeMillis >= fadeInterval) {
    // yup, it's time!
    if (fadeDirection == UP) {
      fadeValue = fadeValue + fadeIncrement;
      if (fadeValue >= maxPWM) {
        // At max, limit and change direction
        fadeValue = maxPWM;
        fadeDirection = DOWN;
      }
    } else {
      //if we aren't going up, we're going down
      fadeValue = fadeValue - fadeIncrement;
      if (fadeValue <= minPWM) {
        // At min, limit and change direction
        fadeValue = minPWM;
        fadeDirection = UP;
      }
    }
    // Only need to update when it changes
    strip.setPixelColor(4, 0, fadeValue, 0);
    strip.setPixelColor(5, 0, fadeValue, 0);
    strip.show();
    previousFadeMillis = thisMillis;
  }
}```
#定义引脚3
#定义像素6
#向上定义0
#下定义1
Adafruit_NeoPixel条=Adafruit_NeoPixel(像素、引脚、NEO_GRB+NEO_KHZ800);
#包括
#包括
#包括
RF24无线电(9,10);//行政长官
//常量字节地址[6]=“00001”;
常量字节地址[][6]={“00001”、“00002”};
int colorMode=0;
未签名的长前Fademilis;
亮度;
int fadeInterval=1;
常量字节pwmLED=5;
字节fadeDirection=UP;
int fadeValue=0;
字节fadeIncrement=5;
//定义LED衰减的方向
#向上定义0
#下定义1
//最小和最大PWM的常数
常数int minPWM=100;
常数int maxPWM=255;
类型定义结构{
int X;
int-Y;
INTR;
int G;
int B;
int-Br;
};
发送数据;
类型定义结构{
浮动电压;
int连接计数;
};
B_tneddata;
无效设置(){
Serial.begin(9600);
收音机。开始();
//radio.openReadingPipe(0,地址);
//无线电设置电平(RF24\u PA\u MIN);
radio.openWritingPipe(地址[0]);//00001
radio.openReadingPipe(1,地址[1]);//00002
无线电设置电平(RF24\u PA\u MIN);
停止收听;
NedData.connectCount=0;
strip.begin();
strip.setPixelColor(4,0,200,0);
strip.setPixelColor(5,0,200,0);
}
void循环(){
无符号长电流毫秒=毫秒();
开关(彩色模式){
案例0:
doTheFade(当前毫秒);
打破
案例1:
doTheFade(当前毫秒);
打破
案例2:
doTheFade(当前毫秒);
打破
案例3:
doTheFade(当前毫秒);
打破
}
while(radio.available()){
radio.read(&SendData,sizeof(SendData));
//字符文本[32]=“”;
//radio.read(&text,sizeof(text));
}
int传感器电压=模拟读数(A0);
浮动电压=传感器电压*(4.2/1023.0);
NedData.nedVoltage=nedVoltage;
NedData.connectCount=NedData.connectCount+1;
停止收听;
bool ok=radio.write(&NedData,sizeof(NedData));
收音机;
Serial.print(“fadeValue=”);
串行打印LN(fadeValue);
Serial.print(“NedData.connectCount=”);
Serial.println(NedData.connectCount);
Serial.print(“NedData.nedVoltage=”);
Serial.println(NedData.nedprotation);
Serial.print(“SendData.X=”);
Serial.println(SendData.X);
Serial.print(“SendData.Y=”);
Serial.println(SendData.Y);
Serial.print(“SendData.R=”);
Serial.println(SendData.R);
Serial.print(“SendData.G=”);
Serial.println(SendData.G);
Serial.print(“SendData.B=”);
Serial.println(SendData.B);
Serial.print(“SendData.Br=”);
Serial.println(SendData.Br);
}
虚空不褪色(无符号长thisMillis){
//是时候更新了吗?
//如果没有,什么也不会发生
如果(thisMillis-previousFadeMillis>=fadeInterval){
//是的,时间到了!
如果(fadeDirection==向上){
fadeValue=fadeValue+fadeIncrement;
如果(fadeValue>=maxPWM){
//在最大值时,限制并改变方向
fadeValue=最大脉宽调制;
fadeDirection=DOWN;
}
}否则{
//如果我们不上去,我们就下去
fadeValue=fadeValue-fadeIncrement;

如果(fadeValue)您正试图以1000000 FPS(每μs更新一次led)。您还通过无线电发送更新,并在每次
loop()
调用时输出到串行。我使用毫秒计时器进行led淡入,因此它不会改变每个周期
currentMillis=micros()
您正在使用micros。哦,这只是一个测试,看看我是否加快了计时器,如果它能解决问题,它不会。忘记我在代码中加入了这个版本。我可以解决这个问题。您正在尝试以1000000 FPS(每μs更新一次LED)。您还通过无线电发送更新,并在每个
循环()上输出到串行
呼叫。我正在使用毫秒计时器进行led淡入,因此它不会改变每个周期
currentMillis=micros();
您正在使用micros。哦,这只是一个测试,看看我是否加快了计时器的速度,如果它能解决问题,它不会。忘记我在代码中添加了这个版本。我可以解决这个问题。