Уважаемые коллеги, проблема в том, что при компилировании программа пишет ошибку в коде. Я новичок в этом деле и не понимаю, как исправить ситуацию Вот код #include <MD_TCS230.h> #define DEBUG_TCS230 0 #if DEBUG_TCS230 #define DUMP(s, v) { Serial.print(F(s)); Serial.print(v); } #define DUMPS(s) Serial.print(F(s)) #else #define DUMP(s, v) #define DUMPS(s) #endif void MD_TCS230::initialise(void) // initialise all object variables { _OE = NO_PIN; _S0 = NO_PIN; _S1 = NO_PIN; _S2 = NO_PIN; _S3 = NO_PIN; _readDiv = 10; _freqSet = TCS230_FREQ_HI; for (uint8_t i=0; i<RGB_SIZE; i++) { _Fd.value = 6000L; // just typical numbers read by a sensor to ensure ... _Fw.value = 55000L; // ... something sensible is returned with no calibration } } MD_TCS230::MD_TCS230(uint8_t s2, uint8_t s3) { initialise(); _S2 = s2; _S3 = s3; } MD_TCS230::MD_TCS230(uint8_t s2, uint8_t s3, uint8_t oe) { initialise(); _S2 = s2; _S3 = s3; _OE = oe; } MD_TCS230::MD_TCS230(uint8_t s2, uint8_t s3, uint8_t s0, uint8_t s1) { initialise(); _S0 = s0; _S1 = s1; _S2 = s2; _S3 = s3; } MD_TCS230::MD_TCS230(uint8_t s2, uint8_t s3, uint8_t s0, uint8_t s1, uint8_t oe) { initialise(); _S0 = s0; _S1 = s1; _S2 = s2; _S3 = s3; _OE = oe; } MD_TCS230::~MD_TCS230(void) { } void MD_TCS230::begin() { #define SET_OUTPUT(x) if (x!=NO_PIN) pinMode(x,OUTPUT) SET_OUTPUT(_S0); SET_OUTPUT(_S1); SET_OUTPUT(_S2); SET_OUTPUT(_S3); SET_OUTPUT(_OE); setEnable(false); setFrequency2(_freqSet); #undef SET_OUTPUT DUMPS("\nLibrary begin initialised"); } void MD_TCS230::setFilter(uint8_t f) // set the sensor color filter { if ((_S2 == NO_PIN) || (_S3 == NO_PIN)) return; DUMPS("\nsetFilter "); switch (f) { case TCS230_RGB_R: DUMPS("R"); digitalWrite(_S2, LOW); digitalWrite(_S3, LOW); break; case TCS230_RGB_G: DUMPS("G"); digitalWrite(_S2, HIGH); digitalWrite(_S3, HIGH); break; case TCS230_RGB_B: DUMPS("B"); digitalWrite(_S2, LOW); digitalWrite(_S3, HIGH); break; case TCS230_RGB_X: DUMPS("X"); digitalWrite(_S2, HIGH); digitalWrite(_S3, LOW); break; default: DUMP("Unknown filter option", f); break; } } void MD_TCS230::setFrequency2(uint8_t f) // set the sensor frequency prescaler (internal function only) { if ((_S0 == NO_PIN) || (_S0 == NO_PIN)) return; DUMPS("\nsetFrequency "); switch (f) { case TCS230_FREQ_HI: DUMPS("HI"); digitalWrite(_S0, HIGH); digitalWrite(_S1, HIGH); break; case TCS230_FREQ_MID: DUMPS("MID"); digitalWrite(_S0, HIGH); digitalWrite(_S1, LOW); break; case TCS230_FREQ_LO: DUMPS("LO"); digitalWrite(_S0, LOW); digitalWrite(_S1, HIGH); break; case TCS230_FREQ_OFF: DUMPS("OFF"); digitalWrite(_S0, LOW); digitalWrite(_S1, LOW); break; default: DUMP("Unknown freq option", f); break; } } void MD_TCS230::setFrequency(uint8_t f) // set the sensor frequency prescaler (user function) // saves the value the user sets so we can return to it { _freqSet = f; setFrequency2(f); } void MD_TCS230::setSampling(uint8_t t) // set sampling rate divisor for frequency counter { _readDiv = (t > 0 ? t : _readDiv); } void MD_TCS230::setEnable(bool b) // enable the sensor output (b=true) // can be done by toggling OE (preferred) or by setting the frequency output { if (b) DUMPS("\nEn"); else DUMPS("\nDis"); DUMPS("abling using "); if (_OE != NO_PIN) { DUMPS("OE"); digitalWrite(_OE, (b) ? LOW : HIGH); // reverse logic } else { DUMPS("FREQ"); setFrequency2((b) ? _freqSet : TCS230_FREQ_OFF); } } void MD_TCS230::setDarkCal(sensorData *d) // set dark calibration data for rgb calculations { if (d == NULL) return; DUMPS("\nsetDarkCal"); for (uint8_t i=0; i<RGB_SIZE; i++) { DUMP(" ", d->value); _Fd.value = d->value; } } void MD_TCS230::setWhiteCal(sensorData *d) // set white calibration data for rgb calculations { if (d == NULL) return; DUMPS("\nsetWhiteCal"); for (uint8_t i=0; i<RGB_SIZE; i++) { DUMP(" ", d->value); _Fw.value = d->value; } } void MD_TCS230::getRGB(colorData *rgb) // get the rgb value of the current reading { if (rgb == NULL) return; DUMPS("\ngetRGB"); for (uint8_t i=0; i<RGB_SIZE; i++) { rgb->value = _rgb.value; DUMP(" ", rgb->value); } } void MD_TCS230::getRaw(sensorData *d) // get the raw data of the current reading // useful to set dark and white calibration data { if (d == NULL) return; DUMPS("\ngetRAW"); for (uint8_t i=0; i<RGB_SIZE; i++) { d->value = _Fo.value; DUMP(" ", d->value); } } uint32_t MD_TCS230::readSingle(void) // blocking read of a single sensor value (ie, not rgb) { DUMPS("\nreadSingle"); FreqCount.begin(1000/_readDiv); // start while (!FreqCount.available()) // wait { DUMPS("."); } FreqCount.end(); // stop DUMP("VALUE ", FreqCount.read()); return(FreqCount.read() * _readDiv); } void MD_TCS230::read(void) // initiate the finite state machine for reading a value { _readState = readFSM(0); } bool MD_TCS230::available(void) // check if a value is ready. Called repeatedly until it is! { _readState = readFSM(_readState); return(_readState == 0); } uint8_t MD_TCS230::readFSM(uint8_t s) // Finite State Machine to read a value (internal function) { static const uint8_t seq[] = { TCS230_RGB_R, TCS230_RGB_G, TCS230_RGB_B }; static uint8_t currCol; // index for seq above switch(s) { case 0: // enable the hardware for reading DUMPS("\n0"); currCol = 0; // RGB_R but we don't care setEnable(true); s++; // fall through to the next state case 1: // select a filter and start a reading DUMPS("\n1"); setFilter(seq[currCol]); FreqCount.begin(1000/_readDiv); s++; break; case 2: // see if a value is available DUMPS("2"); if (FreqCount.available()) { DUMP(" VALUE ", FreqCount.read()); // read the value and save it _Fo.value[seq[currCol++]] = FreqCount.read() * _readDiv; if (currCol < RGB_SIZE) { // loop around again on next call to available() s--; } else { // end this reading session FreqCount.end(); setEnable(false); RGBTransformation(); s = 0; } } break; } return(s); } void MD_TCS230::RGBTransformation(void) // Exploiting linear relationship to remap the range { int32_t x; for (uint8_t i=0; i<RGB_SIZE; i++) { x = (_Fo.value - _Fd.value) * 255; x /= (_Fw.value - _Fd.value); // copy results back into the global structures if (x < 0) _rgb.value = 0; else if (x > 255) _rgb.value = 255; else _rgb.value[i] = x; } }[/i]
Извините, прислала не тот код #include <MD_TCS230.h> #include <FreqCount.h> #include "ColorMatch.h" #define BLACK_CAL 0 #define WHITE_CAL 1 #define READ_VAL 2 #define LEARN_VAL 3 #define LEARN_MODE 'L' #define MATCH_MODE 'M' // Pin definitions #define S2_OUT 12 #define S3_OUT 13 #define OE_OUT 8 // LOW = ENABLED MD_TCS230 CS(S2_OUT, S3_OUT, OE_OUT); // Global variables uint8_t modeOp = 0; // mode of operation uint8_t ctIndex; colorData rgb; void setup() { Serial.begin(57600); Serial.print(F("\n[TCS230 Calibrator Example]")); // input mode of operation while (modeOp == 0) { Serial.print(F("\nOperate in Learn or Match mode?")); modeOp = getChar(); if (modeOp != LEARN_MODE && modeOp != MATCH_MODE) modeOp = 0; else clearInput(); } // initialise color sensor CS.begin(); if (modeOp == MATCH_MODE) // use calibration parameters from the header file { CS.setDarkCal(&sdBlack); CS.setWhiteCal(&sdWhite); } } char getChar() // blocking wait for an input character from the input stream { while (Serial.available() == 0) ; return(toupper(Serial.read())); } void clearInput() // clear out serial input { while (Serial.read() != -1) ; } char *readASCII(uint8_t size) // read up to size-1 characters from the serial input // this is quick and dirty code { #define BUF_SIZE 12 static char s[BUF_SIZE]; uint8_t i = 0; char c; s[0] = '\0'; size--; while ((i < size) && (size < BUF_SIZE-1)) { c = getChar(); if (c == '\n') break; s[i++] = c; s = '\0'; } clearInput(); return(s); #undef BUF_SIZE } void outputHeader(void) // wite out the new header file with sensor values included { Serial.print(F("\n// Header file for the ColorMatch application")); Serial.print(F("\n// This file is generated by the ColorMatch Application in Learn Mode")); Serial.print(F("\n\n// Calibration data")); Serial.print(F("\nsensorData sdBlack = { ")); Serial.print(sdBlack.value[0]); Serial.print(F(", ")); Serial.print(sdBlack.value[1]); Serial.print(F(", ")); Serial.print(sdBlack.value[2]); Serial.print(F(" };")); Serial.print(F("\nsensorData sdWhite = { ")); Serial.print(sdWhite.value[0]); Serial.print(F(", ")); Serial.print(sdWhite.value[1]); Serial.print(F(", ")); Serial.print(sdWhite.value[2]); Serial.print(F(" };")); Serial.print(F("\n\n// Color Table for matching")); Serial.print(F("\ntypedef struct\n{\n char name[9]; // color name 8+nul\n colorData rgb; // RGB value\n} colorTable;")); Serial.print(F("\n\ncolorTable ct[] = \n{")); for (uint8_t i=0; i<ARRAY_SIZE(ct); i++) { Serial.print(F("\n {\"")); Serial.print(ct.name); Serial.print(F("\", {")); Serial.print(ct.rgb.value[0]); Serial.print(F(", ")); Serial.print(ct.rgb.value[1]); Serial.print(F(", ")); Serial.print(ct.rgb.value[2]); Serial.print(F("} },")); } Serial.print(F("\n};\n")); } uint8_t fsmReadValue(uint8_t state, uint8_t valType) // Finite State Machine for reading a value from the sensor // Current FSM state is passed in and returned // Type of value being read is passed in // Current reading stored in a global rgb buffer { static uint8_t selChannel; static uint8_t readCount; static sensorData sd; switch(state) { case 0: // Prompt for the user to start Serial.print(F("\n\nReading value for ")); switch(valType) { case BLACK_CAL: Serial.print(F("BLACK calibration")); break; case WHITE_CAL: Serial.print(F("WHITE calibration")); break; case READ_VAL: Serial.print(F("color MATCH")); break; case LEARN_VAL: Serial.print(ct[ctIndex].name); break; default: Serial.print(F("??")); break; } clearInput(); if (valType == LEARN_VAL) { char *p; Serial.print(F("\nNew name (<enter> for old) to start: ")); p = readASCII(ARRAY_SIZE(ct[0].name)); if (*p != '\0') strcpy(ct[ctIndex].name, p); Serial.print(ct[ctIndex].name); } else { Serial.print(F("\nPress any key to start ...")); getChar(); clearInput(); } state++; break; case 1: // start the reading process CS.read(); state++; break; case 2: // wait for a read to complete if (CS.available()) { switch(valType) { case BLACK_CAL: CS.getRaw(&sdBlack); CS.setDarkCal(&sdBlack); break; case WHITE_CAL: CS.getRaw(&sdWhite); CS.setWhiteCal(&sdWhite); break; case READ_VAL: case LEARN_VAL: CS.getRGB(&rgb); Serial.print(F("\nRGB is [")); Serial.print(rgb.value[TCS230_RGB_R]); Serial.print(F(",")); Serial.print(rgb.value[TCS230_RGB_G]); Serial.print(F(",")); Serial.print(rgb.value[TCS230_RGB_B]); Serial.print(F("]")); break; } state++; } break; default: // reset fsm state = 0; break; } return(state); } uint8_t colorMatch(colorData *rgb) // Root mean square distance between the color and colors in the table. // FOr a limited range of colors this method works ok using RGB // We don't work out the square root or the mean as it has no effect on the // comparison for minimum. Square os the distance is used to ensure that // negative distances do not substract from the total. { int32_t d; uint32_t v, minV = 999999L; uint8_t minI; for (uint8_t i=0; i<ARRAY_SIZE(ct); i++) { v = 0; for (uint8_t j=0; j<RGB_SIZE; j++) { d = ct.rgb.value[j] - rgb->value[j]; v += (d * d); } if (v < minV) // new best { minV = v; minI = i; } if (v == 0) // perfect match, no need to search more break; } return(minI); } void loop() { static uint8_t runState = 0; static uint8_t readState = 0; if (modeOp == LEARN_MODE) // Learning mode { switch(runState) { case 0: // calibrate black readState = fsmReadValue(readState, BLACK_CAL); if (readState == 0) runState++; break; case 1: // calibrate white readState = fsmReadValue(readState, WHITE_CAL); if (readState == 0) runState++; break; case 2: // prep for learing mode Serial.println(F("\n\nFor each color, enter name and sense color")); ctIndex = 0; runState++; break; case 3: // learn color values readState = fsmReadValue(readState, LEARN_VAL); if (readState == 0) { for (uint8_t j=0; j<RGB_SIZE; j++) { ct[ctIndex].rgb.value[j] = rgb.value[j]; } ctIndex++; if (ctIndex >= ARRAY_SIZE(ct)) runState++; } break; case 4: // output the text data outputHeader(); runState++; break; default: runState = 0; // start again if we get here as something is wrong } } else // Matching mode { switch(runState) { case 0: // read a value readState = fsmReadValue(readState, READ_VAL); if (readState == 0) runState++; break; case 1: // find the matching color { uint8_t i = colorMatch(&rgb); Serial.print(F("\nClosest color is ")); Serial.print(ct.name); runState++; } break; default: runState = 0; // start again if we get here as something is wrong } } }
Это код снятия данных с сенсора оттенка цвета, основанный на TCS3200 чипе. Странно то, что на другом компьютере все работает. Возможно ли эта проблема из-за неправильного добавления скетча?
Вот то, что он выдает In file included from ColorMatch_TCS230.ino:24: C:\Users\Маша\Documents\Arduino\libraries\ColorMatchTCS230/ColorMatch.h:5: error: 'sensorData' does not name a type C:\Users\Маша\Documents\Arduino\libraries\ColorMatchTCS230/ColorMatch.h:6: error: 'sensorData' does not name a type C:\Users\Маша\Documents\Arduino\libraries\ColorMatchTCS230/ColorMatch.h:12: error: 'colorData' does not name a type C:\Users\Маша\Documents\Arduino\libraries\ColorMatchTCS230/ColorMatch.h:25: error: too many initializers for 'colorTable' C:\Users\Маша\Documents\Arduino\libraries\ColorMatchTCS230/ColorMatch.h:25: error: too many initializers for 'colorTable' C:\Users\Маша\Documents\Arduino\libraries\ColorMatchTCS230/ColorMatch.h:25: error: too many initializers for 'colorTable' C:\Users\Маша\Documents\Arduino\libraries\ColorMatchTCS230/ColorMatch.h:25: error: too many initializers for 'colorTable' C:\Users\Маша\Documents\Arduino\libraries\ColorMatchTCS230/ColorMatch.h:25: error: too many initializers for 'colorTable' C:\Users\Маша\Documents\Arduino\libraries\ColorMatchTCS230/ColorMatch.h:25: error: too many initializers for 'colorTable' C:\Users\Маша\Documents\Arduino\libraries\ColorMatchTCS230/ColorMatch.h:25: error: too many initializers for 'colorTable' C:\Users\Маша\Documents\Arduino\libraries\ColorMatchTCS230/ColorMatch.h:25: error: too many initializers for 'colorTable' ColorMatch_TCS230:46: error: 'colorData' was not declared in this scope ColorMatch_TCS230:46: error: 'rgb' was not declared in this scope ColorMatch_TCS230:41: error: 'MD_TCS230' does not name a type ColorMatch_TCS230:46: error: 'colorData' does not name a type ColorMatch_TCS230.ino: In function 'void setup()': ColorMatch_TCS230:65: error: 'CS' was not declared in this scope ColorMatch_TCS230:68: error: 'sdBlack' was not declared in this scope ColorMatch_TCS230:69: error: 'sdWhite' was not declared in this scope ColorMatch_TCS230.ino: In function 'void outputHeader()': ColorMatch_TCS230:122: error: 'sdBlack' was not declared in this scope ColorMatch_TCS230:127: error: 'sdWhite' was not declared in this scope ColorMatch_TCS230:135: error: 'ARRAY_SIZE' was not declared in this scope ColorMatch_TCS230:140: error: 'struct colorTable' has no member named 'rgb' ColorMatch_TCS230:142: error: 'struct colorTable' has no member named 'rgb' ColorMatch_TCS230:144: error: 'struct colorTable' has no member named 'rgb' ColorMatch_TCS230.ino: In function 'uint8_t fsmReadValue(uint8_t, uint8_t)': ColorMatch_TCS230:158: error: 'sensorData' does not name a type ColorMatch_TCS230:180: error: 'ARRAY_SIZE' was not declared in this scope ColorMatch_TCS230:195: error: 'CS' was not declared in this scope ColorMatch_TCS230:205: error: 'sdBlack' was not declared in this scope ColorMatch_TCS230:210: error: 'sdWhite' was not declared in this scope ColorMatch_TCS230:216: error: 'rgb' was not declared in this scope ColorMatch_TCS230:218: error: 'TCS230_RGB_R' was not declared in this scope ColorMatch_TCS230:220: error: 'TCS230_RGB_G' was not declared in this scope ColorMatch_TCS230:222: error: 'TCS230_RGB_B' was not declared in this scope ColorMatch_TCS230.ino: At global scope: ColorMatch_TCS230:238: error: redefinition of 'uint8_t colorMatch' ColorMatch_TCS230:46: error: 'uint8_t colorMatch' previously defined here ColorMatch_TCS230:238: error: 'colorData' was not declared in this scope ColorMatch_TCS230:238: error: 'rgb' was not declared in this scope