我的代码有多个错误,经过几个小时的调试后,我无法编译它。这段代码应该在循环中运行,这样它就可以读取和澄清不同的颜色类别。我还用了一个接近感应器来激活密码。
代码将在七个循环中运行。在我定义为p的每个循环中,它会将来自函数rgb_process的澄清值放入一个名为block [p]的堆栈中。错误如下:
警告:参数"rgb_c“已设置但从未在"main.cpp”中使用,第: 22行,第49列警告:参数"rgb_r“已设置但从未在"main.cpp”中使用,第: 22行,第59列警告:参数"rgb_g“已设置但从未在"main.cpp”中使用,第: 22行,第69列警告:参数"rgb_b“已设置但从未在"main.cpp”中使用,第: 22行,第: 79列错误:"main.cpp“中未定义标识符"rgb_readings”,第40行,列: 20错误:表达式必须在"main.cpp“中具有指向对象的指针类型,行: 45,列: 30错误:表达式必须在"main.cpp”中具有指向对象的指针类型,行: 45,列: 46错误:表达式必须在"main.cpp“中具有指向对象的指针类型,行: 45,列: 62错误:表达式必须在"main.cpp”中具有指向对象的指针类型,行: 45,列: 78错误:表达式必须在"main.cpp“中具有指向对象的指针类型,行: 50,列: 34错误:表达式必须在“main.cpp”中具有指向对象的指针类型,行: 50,列: 50错误:表达式必须在“main.cpp”中具有指向对象的指针类型,行: 50,列: 66错误:表达式必须在“main.cpp”中具有指向对象的指针类型,行: 50,列: 82错误:表达式必须在"main.cpp",行: 55,列: 38中具有指向对象的指针类型。错误:表达式必须在"main.cpp",行: 55,列: 54错误:表达式必须在“main.cpp”中具有指向对象的指针类型,行: 55,列: 70错误:表达式必须在“main.cpp”中具有指向对象的指针类型,行: 55,列: 86错误:表达式必须在“main.cpp”中具有指向对象的指针类型,行: 60,列: 42错误:表达式必须在"main.cpp",行: 60,列: 58中具有指向对象的指针类型。错误:表达式必须在"main.cpp",行: 60,列: 74错误:表达式必须在“main.cpp”中具有指向对象的指针类型,行: 60,列: 90错误:表达式必须在“main.cpp”中具有指向对象的指针类型,行: 65,列: 46错误:表达式必须在“main.cpp”中具有指向对象的指针类型,行: 65,列: 62错误:表达式必须在"main.cpp",行: 65,列: 78中具有指向对象的指针类型。错误:表达式必须在"main.cpp",行: 65,列: 94错误:表达式必须在“main.cpp”中具有指向对象的指针类型,行: 70,列: 49错误:表达式必须在"main.cpp",行: 70,列: 65中具有指向对象的指针类型。错误:表达式必须在"main.cpp",行: 70,列: 81中具有指向对象的指针类型。错误:表达式必须在"main.cpp",行: 70,列: 97中具有指向对象的指针类型。错误:"main.cpp",行: 101,列: 28错误:"main.cpp“中应为")”,行: 101,列: 32错误:"main.cpp“中的函数调用中的参数太少,行: 101,列: 32错误:应为";“在"main.cpp”中,行: 102,列: 10错误:"main.cpp“中不允许类型名称,行: 131,列: 27
#include "mbed.h"
#include "stdint.h"
#include "MCP23017.h"
#include "C12832.h"
#include "TCS3472_I2C.h"
#include "VL6180.h"
#include <string>
#include <iostream>
using namespace std;
DigitalOut RED_CHIP(p21);
DigitalOut BLUE_CHIP(p22);
DigitalOut GREEN_CHIP(p23);
DigitalOut Red(p23);
DigitalOut Green(p24);
DigitalOut Blue(p25);
TCS3472_I2C rgb_sensor(p9,p10);
C12832 lcd(p5,p7,p6,p8,p11);
Serial pc(USBTX,USBRX);
VL6180 TOF_sensor(p28,p27);
void coloursensorread (int rgb_readings[3],int rgb_c,int rgb_r,int rgb_g,int rgb_b) //colour sensor read
{
wait(3);
rgb_sensor.enablePowerAndRGBC();
rgb_sensor.setIntegrationTime(100);
rgb_sensor.getAllColors(rgb_readings);
rgb_c= rgb_readings[0];
rgb_r= rgb_readings[1];
rgb_g= rgb_readings[2];
rgb_b= rgb_readings[3];
//pc.printf("C:%d, R:%d, G:%d, B:%d\n",rgb_readings[0],rgb_readings[1],rgb_readings[2],rgb_readings[3]);
wait(2);
}
void rgb_process(int p,int rgb_c,int rgb_r,int rgb_g,int rgb_b,int block [5])
{
if ((4000<rgb_readings[0]<2300)&(2450<rgb_readings[1]<1750)&(850<rgb_readings[2]<400)&(800<rgb_readings[3]<400)) //red
{
block [p] = 0;
//r = r+1;
}
else if ((rgb_c[0]>1000)&(rgb_r[1]<1000)&(rgb_g[2]>2000)&(rgb_b[3]<1000)) //green
{
block [p] = 1;
//r = r+1;
}
else if ((rgb_c[0]>1000)&(rgb_r[1]<1000)&(rgb_g[2]<1000)&(rgb_b[3]>2000)) //blue
{
block [p] =2;
//r = r+1;
}
else if ((rgb_c[0]>1000)&(rgb_r[1]<1000)&(rgb_g[2]>2000)&(rgb_b[3]<1000)) //yellow (edit values)
{
block [p] = 3;
// r = r+1;
}
else if ((rgb_c[0]>1000)&(rgb_r[1]<1000)&(rgb_g[2]>2000)&(rgb_b[3]<1000)) //orange (edit Values)
{
block [p]=4;
// r = r+1;
}
else if ((rgb_c[0]>1000)&(rgb_r[1]<1000)&(rgb_g[2]>2000)&(rgb_b[3]<1000)) //white (edit values)
{
block [p] =5;
//r = r+1;
}
else if((rgb_c[0]>1000)&(rgb_r[1]<1000)&(rgb_g[2]>2000)&(rgb_b[3]<1000)) //black (edit values)
{
block [p]=6;
//r = r+1;
}
}
void prox_sensor()
{
uint8_t dist;
TOF_sensor.VL6180_Init();
pc.printf("TOF Sensor");
wait(2);
//lcd.cls(); lcd.locate(0,0);
//lcd.cls();
dist = TOF_sensor.getDistance();
pc.printf("D=%d",dist);
wait(1);
//lcd.locate(0,0);
}
void colourresult(int p, int block[5],int rgb_readings[3],int rgb_c,int rgb_r,int rgb_g,int rgb_b,int b0,int b1,int b2,int b3,int b4,int b5)
{
for (p = 0;p<6;p++)
{
coloursensorread (int rgb_readings[3],int rgb_c,int rgb_r,int rgb_g,int rgb_b)
rgb_process(int p,int rgb_c,int rgb_r,int rgb_g,int rgb_b,int block [5])
wait(1);
}
b0 = block [0];
b1 = block [1];
b2 = block [2];
b3 = block [3];
b4 = block [4];
b5 = block [5];
pc.printf("%d,%d,%d,%d,%d,%d\n",b0,b1,b2,b3,b4,b5);
}
void ReadData(int p, int block[5],int rgb_readings[3],int rgb_c,int rgb_r,int rgb_g,int rgb_b,int b0,int b1,int b2,int b3,int b4,int b5)
{
uint8_t dist;
TOF_sensor.VL6180_Init();
for (;;)
{
//lcd.cls();
dist = TOF_sensor.getDistance();
//lcd.locate(0,0);
pc.printf("Distance=%d", dist);
wait(1);
if (dist>99)
{
colourresult(int p, int block[5],int rgb_readings[3],int rgb_c,int rgb_r,int rgb_g,int rgb_b,int b0,int b1,int b2,int b3,int b4,int b5);
return ReadData(int p, int block[5],int rgb_readings[3],int rgb_c,int rgb_r,int rgb_g,int rgb_b,int b0,int b1,int b2,int b3,int b4,int b5);
}
else {
wait(3);
return ReadData(int p, int block[5],int rgb_readings[3],int rgb_c,int rgb_r,int rgb_g,int rgb_b,int b0,int b1,int b2,int b3,int b4,int b5);
}
}
}
int main()
{
int rgb_readings[3];
int block [5];
int b0;
int b1;
int b2;
int b3;
int b4;
int b5;
int rgb_c;
int rgb_r;
int rgb_g;
int rgb_b;
int p;
ReadData(int p, int block[5],int rgb_readings[3],int rgb_c,int rgb_r,int rgb_g,int rgb_b,int b0,int b1,int b2,int b3,int b4,int b5);发布于 2017-11-08 00:14:31
如果您需要调试代码的帮助,我建议您共享一个可以导入在线编译器的链接。否则,我最终可能会使用不同版本的库或其他东西。
请共享您代码的链接,以便我们可以尝试提供帮助。
-Austin arm Mbed
发布于 2018-06-04 03:39:45
您将rgb_readings3传递给函数,该函数是一个整数(位于数组的第四个索引处)。在函数中,您将rgb_readings视为一个数组,尽管它只是一个整数。在函数定义中,如果想要使用数组,则将括号保留为空的int rgb_readings[],然后在主应用程序代码中调用它,而不使用任何索引。
https://stackoverflow.com/questions/47050925
复制相似问题