我的代码有多个错误,经过几个小时的调试后我无法编译。此代码应在循环中运行,以便读取并阐明不同的颜色类别。我还使用了接近传感器来激活代码。
代码将在七个循环中运行。在我定义为p
的每个循环中,它将把函数rgb_process
中的澄清值放入一个名为block [p]
的堆栈中。错误如下:
Warning: Parameter "rgb_c" was set but never used in "main.cpp", Line: 22, Col: 49 Warning: Parameter "rgb_r" was set but never used in "main.cpp", Line: 22, Col: 59 Warning: Parameter "rgb_g" was set but never used in "main.cpp", Line: 22, Col: 69 Warning: Parameter "rgb_b" was set but never used in "main.cpp", Line: 22, Col: 79 Error: Identifier "rgb_readings" is undefined in "main.cpp", Line: 40, Col: 20 Error: Expression must have pointer-to-object type in "main.cpp", Line: 45, Col: 30 Error: Expression must have pointer-to-object type in "main.cpp", Line: 45, Col: 46 Error: Expression must have pointer-to-object type in "main.cpp", Line: 45, Col: 62 Error: Expression must have pointer-to-object type in "main.cpp", Line: 45, Col: 78 Error: Expression must have pointer-to-object type in "main.cpp", Line: 50, Col: 34 Error: Expression must have pointer-to-object type in "main.cpp", Line: 50, Col: 50 Error: Expression must have pointer-to-object type in "main.cpp", Line: 50, Col: 66 Error: Expression must have pointer-to-object type in "main.cpp", Line: 50, Col: 82 Error: Expression must have pointer-to-object type in "main.cpp", Line: 55, Col: 38 Error: Expression must have pointer-to-object type in "main.cpp", Line: 55, Col: 54 Error: Expression must have pointer-to-object type in "main.cpp", Line: 55, Col: 70 Error: Expression must have pointer-to-object type in "main.cpp", Line: 55, Col: 86 Error: Expression must have pointer-to-object type in "main.cpp", Line: 60, Col: 42 Error: Expression must have pointer-to-object type in "main.cpp", Line: 60, Col: 58 Error: Expression must have pointer-to-object type in "main.cpp", Line: 60, Col: 74 Error: Expression must have pointer-to-object type in "main.cpp", Line: 60, Col: 90 Error: Expression must have pointer-to-object type in "main.cpp", Line: 65, Col: 46 Error: Expression must have pointer-to-object type in "main.cpp", Line: 65, Col: 62 Error: Expression must have pointer-to-object type in "main.cpp", Line: 65, Col: 78 Error: Expression must have pointer-to-object type in "main.cpp", Line: 65, Col: 94 Error: Expression must have pointer-to-object type in "main.cpp", Line: 70, Col: 49 Error: Expression must have pointer-to-object type in "main.cpp", Line: 70, Col: 65 Error: Expression must have pointer-to-object type in "main.cpp", Line: 70, Col: 81 Error: Expression must have pointer-to-object type in "main.cpp", Line: 70, Col: 97 Error: Type name is not allowed in "main.cpp", Line: 101, Col: 28 Error: Expected a ")" in "main.cpp", Line: 101, Col: 32 Error: Too few arguments in function call in "main.cpp", Line: 101, Col: 32 Error: Expected a ";" in "main.cpp", Line: 102, Col: 10 Error: Type name is not allowed in "main.cpp", Line: 131, Col: 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);
如果您需要帮助调试代码,我建议共享一个可以导入到在线编译器中的链接。否则我最终会使用不同版本的库或其他东西。
请分享您的代码链接,以便我们尽力提供帮助。
- 奥斯汀手臂Mbed
您正在将rgb_readings [3]传递给函数,该函数是一个整数(在数组的第四个索引处)。在函数中,您将rgb_readings视为一个数组,尽管它只是一个整数。在函数定义中,如果要使用数组,则将括号空为int rgb_readings [],然后在主应用程序代码中调用它而不使用任何索引。