Hi. I’m doing a project right now and I’m not sure what I’m doing wrong. The code is supposed to make the pitch of the buzzer alter as more or less light is detected from the photo resistor. Each time I upload it says exit status 1, and it says it has an error compiling. Here is my code.
Read the forum guidelines to see how to properly post code. Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.
Please include the entire error message. It is easy to do. There is a button (lower right of the IDE window) called "copy error message". Copy the error and paste into a post in code tags. Paraphrasing the error message leaves out important information.
Here is your code posted properly in code tags and formatted using the IDE autoformat tool. It now compiles for me. There seemed to be an invisible character in line 21 that I deleted.
int sensorValue;
int sensorLow = 1023;
int sensorHigh = 0;
int piezoPin = 8;
void setup()
{
Serial.begin(9600);
while (millis() < 5000)
{
sensorValue = analogRead(A0);
if (sensorValue < sensorHigh)
{
sensorHigh = sensorValue;
}
if (sensorValue > sensorLow)
{
sensorLow = sensorValue;
}
}
}
void loop()
{
sensorValue = analogRead(A0);
int pitch = map(sensorValue, sensorLow, sensorHigh, 50, 4000);
tone(piezoPin, pitch, 50);
Serial.print("pitch: ");
Serial.println(pitch);
delay(10);
}
Hi! Thank you! I didn’t know of the rule before I posted because I was kind of in a rush. Thanks for letting me know! Also, thank you for the tweak in my code. I’ll try it out now.