Hello guys!
I'm very new to Arduino, so the following question might be very easy to answer, but I really have no idea why this happens.
I have as Color sensor the TCS3200 aand the board is a MEGA2560.
First of all, this was my code. The RGB-values were about 20,20,15, when I run this.
#include <Servo.h>
#include <MD_TCS230.h>
#include <FreqCount.h>
Servo servo1;
Servo servo2;
const int s0=8;
const int s1=9;
const int s2=12;
const int s3=11;
const int out=10;
int frequency = 0;
int R = 0;
int G = 0;
int B = 0;
void setup(){
-
pinMode(5, OUTPUT);*
-
servo1.attach(5);*
-
pinMode (13,OUTPUT);*
-
servo2.attach(13);*
-
pinMode(s0,OUTPUT);*
-
pinMode(s1,OUTPUT);*
-
pinMode(s2,OUTPUT);*
-
pinMode(s3,OUTPUT);*
-
pinMode(out,INPUT);*
-
digitalWrite(s0,HIGH);*
-
digitalWrite(s1,HIGH);*
-
Serial.begin(9600);*
}
void loop() {
digitalWrite(s2,LOW);
digitalWrite(s3,LOW);
frequency = pulseIn(out,LOW);
R = frequency;
Serial.print("r=");
Serial.print(R);
Serial.print(", ");
digitalWrite(s2,HIGH);
digitalWrite(s3,HIGH);
frequency = pulseIn(out,LOW);
G = frequency;
Serial.print("g=");
Serial.print(G);
Serial.print(", ");
digitalWrite(s2,LOW);
digitalWrite(s3,HIGH);
frequency = pulseIn(out,LOW);
B = frequency;
Serial.print("b=");
Serial.print(B);
Serial.print(", ");
Serial.print('\n');
}
But then I added this term at the end and nearly all the values got the doubled height. I don't really understand why this happens and I hope you understand my question
delay(1000);
-
if (R < 30){*
-
servo1.write(60);*
-
}*
-
else if (R > 30){*
-
servo1.write(150);*
-
}*
delay(2000);
servo1.write(0);
delay(500);
}
Thanks for your reply!