My Arduino Code Won’t Compile, But it Works on TinkerCad

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);
}
1 Like