How can I 'map' this? Need help..!

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!

Chae:

  rgb == frequencyR*65536+frequencyG*256+frequencyB;

[/quote]

why is that here. replace the '==' by '=' and see if you got is working

  int rgb;
  rgb == frequencyR*65536+frequencyG*256+frequencyB;

Even when you fix the problem with the == then is this going to work ?

What is the largest number than a signed int can hold ?

[quote author=sherzaad link=msg=3876883 date=1537272913]
why is that here. replace the '==' by '=' and see if you got is working

[/quote]

thank you for reply!

UKHeliBob:

  int rgb;

rgb == frequencyR65536+frequencyG256+frequencyB;



Even when you fix the problem with the == then is this going to work ?

What is the largest number than a signed int can hold ?

Oops...right...I was completely forgot about that. Thank you.
Then, is there way to hold larger number than signed int could?

Chae:
Oops...right...I was completely forgot about that. Thank you.
Then, is there way to hold larger number than signed int could?

I found 'long' and trying more..:slight_smile:

Then, is there way to hold larger number than signed int could?

long
unsigned long
long long
unsigned long long

PaulS:
long
unsigned long
long long
unsigned long long

Thank you for answering! I'm looking for those references. However, I tried 'long' still 4118, 4117...this kind of numbers came out on Serial monitor:(

However, I tried 'long' still 4118, 4117...this kind of numbers came out on Serial monitor:(

So, you changed your code, but failed to post it, and want us to guess what is wrong. My guess is that there is a problem on line 528916198163491066354.

Am I close?

PaulS:
So, you changed your code, but failed to post it, and want us to guess what is wrong. My guess is that there is a problem on line 528916198163491066354.

Am I close?

Sorry...I don't know where is line 528916198163491066354...

Chae:
Sorry...I don't know where is line 528916198163491066354...

If you posted your code, you wouldn't need to look for that line number.

I first tried...this.

Serial.print(frequencyR*65536+frequencyG*256+frequencyB);
  Serial.print("  ");
  long chae = frequencyR*65536+frequencyG*256+frequencyB;
  chae = map(chae, 16600000, 460000, 4186, 33);
  Serial.print(chae);
  Serial.println("  ");
  delay(100);

And then, I tried this second one.

Serial.print("  ");
  Serial.print(frequencyR*65536+frequencyG*256+frequencyB);
  Serial.print("  ");
  long chae = Serial.print(frequencyR*65536+frequencyG*256+frequencyB);
  chae = map(chae, 16600000, 460000, 4186, 33);
  Serial.print(chae);
  Serial.println("  ");
  delay(100);

Second one's numbers on Serial monitor got really large...

long chae = frequencyR65536UL+frequencyG256UL+frequencyB;

What types are frequencyR, G, and B?

long chae = Serial.print(frequencyR*65536+frequencyG*256+frequencyB);

Serial print returns how many bytes were printed which is rarely useful. Is that what you really want ?

PaulS:
long chae = frequencyR65536UL+frequencyG256UL+frequencyB;

What types are frequencyR, G, and B?

Sorry! This is full code.

/*     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, 80,1610,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, 75,1290,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, 20,415,255,0);
  // Printing the value on the serial monitor
  Serial.print("B= ");//printing name
  Serial.print(frequencyB);//printing RED color frequency
  Serial.print("  ");
  Serial.print(frequencyR*65536+frequencyG*256+frequencyB);
  Serial.print("  ");
  long chae = frequencyR*65536+frequencyG*256+frequencyB;
  chae = map(chae, 16600000, 460000, 4186, 33);
  Serial.print(chae);
  Serial.println("  ");
  delay(100);
}

I just tried long chae = frequencyR65536UL+frequencyG256UL+frequencyB; and it's not working. Numbers around 4186 are on Serial monitor whatever I do.

UKHeliBob:

long chae = Serial.print(frequencyR*65536+frequencyG*256+frequencyB);

Serial print returns how many bytes were printed which is rarely useful. Is that what you really want ?

Ah...I see...nope..that's not I want.
I just typed I've seen somewhere...