Спасибо, добрый вечер. Посмотрю, нельзя целиком код прислать?. Мой код #include <QTRSensors.h>
// This example is designed for use with six QTR-1A sensors or the first six sensors of a // QTR-8A module. These reflectance sensors should be connected to analog inputs 0 to 5. // The emitter control pin can optionally be connected to digital pin 2, or you can leave // it disconnected and change the EMITTER_PIN #define below from 2 to QTR_NO_EMITTER_PIN.
// The setup phase of this example calibrates the sensor for ten seconds and turns on // the pin 13 LED while calibration is going on. During this phase, you should expose each // reflectance sensor ot the lightest and darkest readings they will encounter. For // example, if you are making a line follower, you should slide the sensors across the // line during the calibration phase so that each sensor can get a reading of how dark the // line is and how light the ground is. Improper calibration will result in poor readings. // If you want to skip the calibration phase, you can get the raw sensor readings // (analog voltage readings from 0 to 1023) by calling qtra.read(sensorValues) instead of // qtra.readLine(sensorValues).
// The main loop of the example reads the calibrated sensor values and uses them to // estimate the position of a line. You can test this by taping a piece of 3/4" black // electrical tape to a piece of white paper and sliding the sensor across it. It // prints the sensor values to the serial monitor as numbers from 0 (maximum reflectance) // to 9 (minimum reflectance) followed by the estimated location of the line as a number // from 0 to 5000. 1000 means the line is directly under sensor 1, 2000 means directly // under sensor 2, etc. 0 means the line is directly under sensor 0 or was last seen by // sensor 0 before being lost. 5000 means the line is directly under sensor 5 or was // last seen by sensor 5 before being lost.
#define NUM_SENSORS 6 // number of sensors used #define NUM_SAMPLES_PER_SENSOR 4 // average 4 analog samples per sensor reading #define EMITTER_PIN 2 // emitter is controlled by digital pin 2
// sensors 0 through 5 are connected to analog inputs 0 through 5, respectively QTRSensorsAnalog qtra((unsigned char[]) {0, 1, 2, 3, 4, 5}, NUM_SENSORS, NUM_SAMPLES_PER_SENSOR, EMITTER_PIN); unsigned int sensorValues[NUM_SENSORS];
void setup() { delay(500); int i; pinMode(13, OUTPUT); digitalWrite(13, HIGH); // turn on LED to indicate we are in calibration mode for (i = 0; i < 400; i++) // make the calibration take about 10 seconds { qtra.calibrate(); // reads all sensors 10 times at 2.5 ms per six sensors (i.e. ~25 ms per call) } digitalWrite(13, LOW); // turn off LED to indicate we are through with calibration
// print the calibration minimum values measured when emitters were on Serial.begin(9600); for (i = 0; i < NUM_SENSORS; i++) { Serial.print(qtra.calibratedMinimumOn[i]); Serial.print(' '); } Serial.println(); // print the calibration maximum values measured when emitters were on for (i = 0; i < NUM_SENSORS; i++) { Serial.print(qtra.calibratedMaximumOn[i]); Serial.print(' '); } Serial.println(); Serial.println(); delay(1000); }
void loop() { // read calibrated sensor values and obtain a measure of the line position // from 0 to 5000, where 0 means directly under sensor 0 or the line was lost // past sensor 0, 1000 means directly under sensor 1, 200 means directly under sensor 2, etc. // Note: the values returned will be incorrect if the sensors have not been properly // calibrated during the calibration phase. To get raw sensor values, call: // qtra.read(sensorValues); unsigned int position = qtra.readLine(sensorValues);
// print the sensor values as numbers from 0 to 9, where 0 means maximum reflectance and // 9 means minimum reflectance, followed by the line position unsigned char i; for (i = 0; i < NUM_SENSORS; i++) { Serial.print(sensorValues[i] * 10 / 1001); Serial.print(' '); } Serial.print(" "); Serial.println(position); delay(250); }
Добавлено спустя 12 минут 49 секунд: Re: Модуль OR-BWSENS: Датчик цвета поверхности (черная/белая) Если ввести этот ко: #include <PololuQTRSensors.h>
#define LED 13 // LED на pin 13
// создаем объект, датчик подключен на pin 10 PololuQTRSensorsRC qtr((unsigned char[]) {10}, 1);
void setup() { pinMode(LED, OUTPUT); //установка LED pin как выход digitalWrite(LED, HIGH); // LED on // калибровка датчика int i; for (i = 0; i < 250; i++) { qtr.calibrate(); delay(20); } digitalWrite(LED, LOW); // LED off Serial.begin(9600); }
void loop() { digitalWrite(LED, LOW); // LED Off unsigned int sensors[1]; // результаты измерений сенсора int position = qtr.readLine(sensors); Serial.println(sensors[0], DEC); //результат измерений 0(самый белый) .. 1000(самый черный) if (sensors[0] > 500) // скорее черный чем белый { digitalWrite(LED, HIGH); // turns the LED on } delay(10); // waits for a 10 uSec }
то выдаёт ошибку
sketch_feb22b.cpp:1:30: error: PololuQTRSensors.h: No such file or directory sketch_feb22b:6: error: 'PololuQTRSensorsRC' does not name a type sketch_feb22b:6: error: expected unqualified-id before ',' token sketch_feb22b:6: error: expected unqualified-id before numeric constant sketch_feb22b.cpp: In function 'void setup()': sketch_feb22b:17: error: 'qtr' was not declared in this scope sketch_feb22b.cpp: In function 'void loop()': sketch_feb22b:28: error: 'qtr' was not declared in this scope
Добавлено спустя 3 минуты 32 секунды: Re: Модуль OR-BWSENS: Датчик цвета поверхности (черная/белая) ТА!! дам!!! с ошибкой справился и понял в синтаксис ошибки! Может чего то дальше получется?!)
|