arduino a tcs230 farebný senzor

Wiring, C++, C, Java, ...
Pravidla fóra
Toto subfórum slouží k řešení obecných otázek kolem programování (konstrukce, knihovny, alokace paměti, ...)
Odpovědět
softomi
Příspěvky: 2
Registrován: 02 úno 2019, 11:13
Reputation: 0

arduino a tcs230 farebný senzor

Příspěvek od softomi » 02 úno 2019, 11:29

Dobrý den , potrebujem poradit lebo som už v koncoch . Robím projekt ktorý ma za úlohu roztriedit lentilky podla farby ale motorček ktorý ich ma triedit sa vobec nechce hýbať ako keby nedochádzalo ku komunikácii farebného senzora a motorčeka .tento motorček sa pri každej inej farbe ma dať do inej polohy ale ani sa nepohne. jedná sa o bottomServo. za každú radu budem veľmi vdačný .
#include <Servo.h>

#define S0 2
#define S1 3
#define S2 4
#define S3 5
#define sensorOut 6

Servo topServo;
Servo bottomServo;

int frequency = 0;
int color=0;

void setup() {
pinMode(S0, OUTPUT);
pinMode(S1, OUTPUT);
pinMode(S2, OUTPUT);
pinMode(S3, OUTPUT);
pinMode(sensorOut, INPUT);

// Setting frequency-scaling to 20%
digitalWrite(S0, HIGH);
digitalWrite(S1, LOW);

topServo.attach(7);
bottomServo.attach(8);

Serial.begin(9600);
}

void loop() {

topServo.write(150);
delay(500);

for(int i = 150; i > 80; i--) {
topServo.write(i);
delay(2);
}
delay(500);


color = readColor();

delay(10);

switch (color) {
case 1:
bottomServo.write(40);
break;

case 2:
bottomServo.write(70);
break;

case 3:
bottomServo.write(90);
break;

case 4:
bottomServo.write(115);
break;

case 5:
bottomServo.write(140);
break;

case 6:
bottomServo.write(175);
break;

case 0:
break;
}
delay(300);

for(int i = 80; i > 29; i--) {
topServo.write(i);
delay(2);
}
delay(200);

for(int i = 29; i < 150; i++) {
topServo.write(i);
delay(2);
}
color=0;
}

// Custom Function - readColor()
int readColor() {
// Setting red filtered photodiodes to be read
digitalWrite(S2, LOW);
digitalWrite(S3, LOW);
// Reading the output frequency
frequency = pulseIn(sensorOut, LOW);
int R = frequency;
// Printing the value on the serial monitor
Serial.print("R= ");//printing name
Serial.print(frequency);//printing RED color frequency
Serial.print(" ");
delay(50);

// Setting Green filtered photodiodes to be read
digitalWrite(S2, HIGH);
digitalWrite(S3, HIGH);
// Reading the output frequency
frequency = pulseIn(sensorOut, LOW);
int G = frequency;
// Printing the value on the serial monitor
Serial.print("G= ");//printing name
Serial.print(frequency);//printing RED color frequency
Serial.print(" ");
delay(50);

// Setting Blue filtered photodiodes to be read
digitalWrite(S2, LOW);
digitalWrite(S3, HIGH);
// Reading the output frequency
frequency = pulseIn(sensorOut, LOW);
int B = frequency;
// Printing the value on the serial monitor
Serial.print("B= ");//printing name
Serial.print(frequency);//printing RED color frequency
Serial.println(" ");
delay(50);

if(R<55 & R>75 & G<128 & G>155){
color = 1; // Red
}
if(G<90 & G>118 & B<70 &B>93){
color = 2; // Orange
}
if(R<98 & R>115 & G<100 & G>125){
color = 3; // Green
}
if(R<50 & R>71 & G<67 & G>100){
color = 4; // Yellow
}
if(R<56 & R>46 & G<65 & G>55){
color = 5; // Brown
}
if (G<50 & G>95 & B<36 &B>72){
color = 6; // Blue

}
return color;
}

jankop
Příspěvky: 1029
Registrován: 06 zář 2017, 20:04
Reputation: 0
Bydliště: Brno
Kontaktovat uživatele:

Re: arduino a tcs230 farebný senzor

Příspěvek od jankop » 02 úno 2019, 13:48

Když něco opisuješ, zvláště do školy, tak bys to měl aspoň opsat správně. V originále to mají dobře.

Kód: Vybrat vše

 if (R<55 & R>75 & G<128 & G>155) {
    color = 1; // Red
  }
  if (G<90 & G>118 & B<70 & B>93) {
    color = 2; // Orange
  }
  if (R<98 & R>115 & G<100 & G>125) {
    color = 3; // Green
  }
  if (R<50 & R>71 & G<67 & G>100) {
    color = 4; // Yellow
  }
  if (R<56 & R>46 & G<65 & G>55) {
    color = 5; // Brown
  }
  if (G<50 & G>95 & B<36 & B>72) {
    color = 6; // Blue
Tyto podmínky jsou všechny špatně, protože žádná z nich nemůže být nikdy splněna. Číslo nemůže být menší než 90 a současně větší než 118 atd. Nevím, jestli jsou tvoje konstanty správné, ale relační operátory "<" a ">" máš nepochybně prohozeny.

softomi
Příspěvky: 2
Registrován: 02 úno 2019, 11:13
Reputation: 0

Re: arduino a tcs230 farebný senzor

Příspěvek od softomi » 02 úno 2019, 14:25

dakujem velmi pekne ja som s toho už bol tak na nervy že som si to ani nevšimol ..už mi to funguje dakujem velmi pekne.

Odpovědět

Kdo je online

Uživatelé prohlížející si toto fórum: Žádní registrovaní uživatelé a 15 hostů