Hello.
I have done only a few project with Arduino. So, I don't know much of Arduino.
Also, please understand that English isn't my first language:)
I'm doing now, a project that using color sensor(TCS3200) and piezo buzzer.
Right before, I did tone the three piezo buzzers with each R, G, B values.
Now, I want to do frequencyR65536+frequencyG256+frequencyB and tone this value.
However, the value is too high for piezo buzzur, so I was trying to map this and I failed.
This is the code I've tried.
/* Arduino Color Sensing Tutorial
*
* by Dejan Nedelkovski, www.HowToMechatronics.com
*
*/
#define S0 4
#define S1 5
#define S2 6
#define S3 7
#define sensorOut 8
int frequencyR = 0;
int frequencyG = 0;
int frequencyB = 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);
Serial.begin(9600);
}
void loop() {
// Setting red filtered photodiodes to be read
digitalWrite(S2,LOW);
digitalWrite(S3,LOW);
// Reading the output frequency
frequencyR = pulseIn(sensorOut, LOW);
frequencyR = map(frequencyR, 55,440,255,0);
// Printing the value on the serial monitor
Serial.print("R= ");//printing name
Serial.print(frequencyR);//printing RED color frequency
Serial.print(" ");
delay(100);
// Setting Green filtered photodiodes to be read
digitalWrite(S2,HIGH);
digitalWrite(S3,HIGH);
// Reading the output frequency
frequencyG = pulseIn(sensorOut, LOW);
frequencyG = map(frequencyG, 55,390,255,0);
// Printing the value on the serial monitor
Serial.print("G= ");//printing name
Serial.print(frequencyG);//printing RED color frequency
Serial.print(" ");
delay(100);
// Setting Blue filtered photodiodes to be read
digitalWrite(S2,LOW);
digitalWrite(S3,HIGH);
// Reading the output frequency
frequencyB = pulseIn(sensorOut, LOW);
frequencyB = map(frequencyB, 16,125,255,0);
// Printing the value on the serial monitor
Serial.print("B= ");//printing name
Serial.print(frequencyB);//printing RED color frequency
Serial.print(" ");
int rgb;
rgb == frequencyR*65536+frequencyG*256+frequencyB;
rgb = map(rgb, 167000000, 130000, 4186, 33);
Serial.print(rgb);
Serial.println(" ");
delay(100);
tone(9,rgb, 10000);
}
I really really don't how to fix this. only 4118, 4117...this kind of numbers came out on Serial monitor.
What is wrong with this code? Let me know.
Please help me!