was not declared in this scope {again}

I have 2 working sketches that I want to combine but get was not declared in this scope errors
I know its the curly brackets but the sketch is too long and im lost inside it
any pointers?

Arduino: 1.8.10 (Mac OS X), Board: "Generic STM32F103C series, STM32F103CB (20k RAM. 128k Flash), Serial, 72Mhz (Normal), Smallest (default)"

/Users/lee/Documents/Arduino/touch_pedal_graph_white/touch_pedal_graph_white.ino: In function 'void setup()':
touch_pedal_graph_white:160:15: error: 'analogMeter' was not declared in this scope
   analogMeter(); // Draw analogue meter
               ^
/Users/lee/Documents/Arduino/touch_pedal_graph_white/touch_pedal_graph_white.ino: In function 'void loop()':
touch_pedal_graph_white:216:26: error: 'plotNeedle' was not declared in this scope
     plotNeedle(reading, 0); // Update analogue meter, 8ms delay per needle increment
                          ^
/Users/lee/Documents/Arduino/touch_pedal_graph_white/touch_pedal_graph_white.ino: At global scope:
touch_pedal_graph_white:221:1: error: expected unqualified-id before '{' token
 {
 ^
/Users/lee/Documents/Arduino/touch_pedal_graph_white/touch_pedal_graph_white.ino: In function 'void DrawBarChartP1(Adafruit_ILI9341&, double, double, double, double, double, double, double, double, int, int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, String, boolean&)':
touch_pedal_graph_white:276:1: error: a function-definition is not allowed here before '{' token
 {
 ^
touch_pedal_graph_white:851:1: error: expected '}' at end of input
 }
 ^
touch_pedal_graph_white:851:1: error: expected '}' at end of input
touch_pedal_graph_white:851:1: error: expected '}' at end of input
Multiple libraries were found for "Adafruit_ILI9341.h"
 Used: /Users/lee/Documents/Arduino/libraries/Adafruit_ILI9341
 Not used: /Users/lee/Library/Arduino15/packages/stm32duino/hardware/STM32F1/2019.6.29/libraries/Adafruit_ILI9341
Multiple libraries were found for "SPI.h"
 Used: /Users/lee/Library/Arduino15/packages/stm32duino/hardware/STM32F1/2019.6.29/libraries/SPI
Multiple libraries were found for "XPT2046_Touchscreen.h"
 Used: /Users/lee/Documents/Arduino/libraries/XPT2046_Touchscreen
Multiple libraries were found for "Adafruit_GFX.h"
 Used: /Users/lee/Documents/Arduino/libraries/Adafruit_GFX_Library
exit status 1
'analogMeter' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

touch_graph_white.ino (28.2 KB)

Leetut:
I have 2 working sketches that I want to combine but get was not declared in this scope errors

Please post the error message. It will identify the line where the compiler got stuck.

...R

Robin2:
Please post the error message. It will identify the line where the compiler got stuck.

...R

that is the error message, and the sketch

Step 1 is to Auto Format the sketch in the IDE and note that the analogMeter() function does not start on the left margin. Having noted that work your way up the program making sure that each { has a matching } in the correct place. For instance, where does the DrawBarChartP1() function end ?

analogMeter() and DrawBarChartP1() are in the same place as in the working sketches,
attached both working sketches

touch_pedal_graph_white.ino (24.5 KB)

Meter1copy.ino (4.15 KB)

analogMeter() and DrawBarChartP1() are in the same place as in the working sketches

Here is a portion of Meter1copy.ino after Auto Formatting

void loop()
{
  if (updateTime <= millis())
  {
    updateTime = millis() + 0;
    int reading = 0;
    reading = map(analogRead(PB0), 0, 4195, 0, 100); // Test with value form Analogue 0, orig 1023
    plotNeedle(reading, 0); // Update analogue meter, 8ms delay per needle increment
  }
}


// #########################################################################
//  Draw the analogue meter on the screen
// #########################################################################
void analogMeter()
{
  tft.setTextColor(ILI9341_BLACK);  // Text colour
etc, etc

Note how the function name is on the left margin

Compare that with a portion of touch_graph_white.ino after Auto Formatting

  if (ts.touched())
  {
    TS_Point p = ts.getPoint();
    //    Serial.print("Pressure = ");
    //    Serial.print(p.z);
    //    Serial.print(", x = ");
    //    Serial.print(p.x);
    //    Serial.print(", y = ");
    //    Serial.print(p.y);
    //delay(30);
    //  Serial.println();
    // Meter Code -------------------------------------
    if ((p.x > 2880) && (p.x < 3840) && (p.y > 313) && (p.y < 3680))
    {
      // #########################################################################
      //  If Meter Button is touched Draw the analogue meter on the screen
      // #########################################################################
      void analogMeter()
      {
        tft.setTextColor(ILI9341_BLACK);  // Text colour
etc, etc

You have screwed up your pairs of braces somewhere when copy/pasting to create the combined program

I know I have but I can’t figure it out

At some point your code was slightly smaller/different to the 28k it is now, but it compiled.
Go back to that version, and work forward.

I asked before where the DrawBarChartP1() function ends. Are you able to answer that ?

UKHeliBob:
I asked before where the DrawBarChartP1() function ends. Are you able to answer that ?

I think its at the very bottom, last brace

TheMemberFormerlyKnownAsAWOL:
At some point your code was slightly smaller/different to the 28k it is now, but it compiled.
Go back to that version, and work forward.

ive done that numerous times, and tried to put things in different places, I still get errors

I think its at the very bottom, last brace

Correct

So why are the analogMeter() and plotNeedle() functions slap bang in the middle of it ?

They surely weren't in the middle of another function in your working programs

because ive added a touch button, and I think ive added it to only load if I touch the button

    if ((p.x > 2880) && (p.x < 3840) && (p.y > 313) && (p.y < 3680))
    {
      // #########################################################################
      //  If Meter Button is touched Draw the analogue meter on the screen
      // #########################################################################
      void analogMeter()
      {

        tft.setTextColor(ILI9341_BLACK);  // Text colour
        tft.fillRect(0, 0, 240, 100, meterCream);

        // draw meter background
        int h = 53, w = 240, row, col, buffidx = 0;
        for (row = 0; row < h; row++) { // For each scanline...
          for (col = 0; col < w; col++) { // For each pixel...
            //To read from Flash Memory, pgm_read_XXX is required.
            //Since image is stored as uint16_t, pgm_read_word is used as it uses 16bit address
            tft.drawPixel(col, row, pgm_read_word(vumeter + buffidx));
            buffidx++;
          } // end pixel
        }


        plotNeedle(0, 0); // Put meter needle at 0
      }

      // #########################################################################
      // Update needle position
      // This function is blocking while needle moves, time depends on ms_delay
      // 10ms minimises needle flicker if text is drawn within needle sweep area
      // Smaller values OK if text not in sweep area, zero for instant movement but
      // does not look realistic... (note: 100 increments for full scale deflection)
      // #########################################################################
      void plotNeedle(int value, byte ms_delay)
      {
        tft.setTextColor(TFT_BLACK, meterCream);
        char buf[8]; dtostrf(value, 4, 0, buf);
        tft.setCursor(5, 80);
        tft.print(buf);

        if (value < -10) value = -10; // Limit value to emulate needle end stops
        if (value > 110) value = 110;

        // Move the needle util new value reached
        while (!(value == old_analog)) {
          if (old_analog < value) old_analog++;
          else old_analog--;

          if (ms_delay == 0) old_analog = value; // Update immediately if delay is 0

          float sdeg = map(old_analog, -10, 110, -150, -30); // Map value to angle
          // Calcualte tip of needle coords
          float sx = cos(sdeg * 0.0174532925);
          float sy = sin(sdeg * 0.0174532925);

          // Calculate x delta of needle start (does not start at pivot point)
          float tx = tan((sdeg + 90) * 0.0174532925);

          // Erase old needle image
          tft.drawLine(120 + 20 * ltx - 1, 119 - 20, osx - 1, osy, meterCream); //119
          tft.drawLine(120 + 20 * ltx, 119 - 20, osx, osy, meterCream);
          tft.drawLine(120 + 20 * ltx + 1, 119 - 20, osx + 1, osy, meterCream);


          // Store new needle end coords for next erase
          ltx = tx;
          osx = sx * 118 + 120; // 188 + 120
          osy = sy * 38 + 85; // 98 + 140 , 38 + 85

          // Draw the needle in the new postion, magenta makes needle a bit bolder
          // draws 3 lines to thicken needle
          tft.drawLine(120 + 20 * ltx - 1, 119 - 20, osx - 1, osy, 0xc801);
          tft.drawLine(120 + 20 * ltx, 119 - 20, osx, osy, 0xc801);
          tft.drawLine(120 + 20 * ltx + 1, 119 - 20, osx + 1, osy, 0xc801);

          // Slow needle down slightly as it approaches new postion
          // if (abs(old_analog - value) < 10) ms_delay += ms_delay / 5;

          // Wait before next update
          //  delay(ms_delay);
        }
      }
    }
  }
   if ((p.x > 2880) && (p.x < 3840) && (p.y > 313) && (p.y < 3680))
    {
      // #########################################################################
      //  If Meter Button is touched Draw the analogue meter on the screen
      // #########################################################################
      void analogMeter()
      {
etc, etc

That is not calling the analogMeter() function it is defining it

A call to the function would be
analogMeter();which is what you do in setup(), but the function definition itself cannot be inside another one.

analogMeter(); is in setup
its where the error keeps pointing me I think

That's a call to the function, but where is the function defined?

You're missing what folks are trying to tell you: you can't define a function inside another. You have done something akin to this, which the compiler is barfing on

void setup
{
MyFunc();  //Call myFunc - the compiler can't find it
}

void loop()
{
  void MyFunc()  // Illegal attempt to define myFunc
  {
  analogRead(A0);
  }
}

I'm still missing it, if its 'Illegal attempt to define myFunc' why does it work in the sketch im copying it from
im copying it from the exact place, and putting it in the same place im copying it from

Leetut:
I'm still missing it, if its 'Illegal attempt to define myFunc' why does it work in the sketch im copying it from
im copying it from the exact place, and putting it in the same place im copying it from

It's not that we don't trust/believe you, but you are going to have to provide proof.

I got the button loading the meter, code at the very bottom, but I can't copy the rest of the meter sketch for the errors

touch_graph_white.ino (25.7 KB)