Go Down

Topic: was not declared in this scope {again} (Read 1 time) previous topic - next topic

Leetut

im trying to copy the relevant parts of "Meter1copy"
into "touch_graph_white


Robin2

#31
Oct 09, 2019, 03:52 pm Last Edit: Oct 09, 2019, 03:54 pm by Robin2
that is the error message, and the sketch
Sorry, my mistake - I thought it was just the program. (Senior moment :) )

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

TheMemberFormerlyKnownAsAWOL

im trying to copy the relevant parts of "Meter1copy"
into "touch_graph_white


This  bit
Code: [Select]
// #########################################################################
//  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
}

Leetut

This  bit
Code: [Select]
// #########################################################################
//  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
}

no, ive already added that part, everything else

Leetut

#34
Oct 09, 2019, 07:30 pm Last Edit: Oct 09, 2019, 07:33 pm by Leetut
I don't want anything drawn on the screen until I press a button

Code: [Select]
   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
      // #########################################################################


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

  }
}
}



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

/Users/lee/Desktop/touch_graph_white/touch_graph_white.ino: In function 'void loop()':
touch_graph_white:211:26: error: 'plotNeedle' was not declared in this scope
     plotNeedle(reading, 0); // Update analogue meter, 0ms delay per needle increment
                          ^
/Users/lee/Desktop/touch_graph_white/touch_graph_white.ino: At global scope:
touch_graph_white:214:1: error: expected unqualified-id before '{' token
 {
 ^
/Users/lee/Desktop/touch_graph_white/touch_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_graph_white:781:22: error: 'plotNeedle' was not declared in this scope
       plotNeedle(0, 0); // Put meter needle at 0
                      ^
touch_graph_white:792:5: error: a function-definition is not allowed here before '{' token
     {
     ^
touch_graph_white:843:1: error: expected '}' at end of input
 }
 ^
touch_graph_white:843: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
'plotNeedle' was not declared in this scope

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

TheMemberFormerlyKnownAsAWOL

Error messages without the code to which they refer are utterly useless.

UKHeliBob

Code: [Select]
touch_graph_white:843:1: error: expected '}' at end of input
This is very explicit.  You have at least one } missing at the end of the code

Have you posted the code that produced the error ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Leetut

sorry I thought I did, I have now, adding 1 or 2 or 3 } at the end makes no difference

TheMemberFormerlyKnownAsAWOL

#38
Oct 09, 2019, 07:39 pm Last Edit: Oct 09, 2019, 07:40 pm by TheMemberFormerlyKnownAsAWOL
Code: [Select]
void plotNeedle(int value, byte ms_delay)
    {
That should be hard against the left margin.
That it isn't suggests it is embedded in another function.

Leetut

Tried moving it up down left and sideways, errors every time

UKHeliBob

sorry I thought I did, I have now, adding 1 or 2 or 3 } at the end makes no difference
Have you posted the complete program ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Leetut

full sketch and its errors


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

/Users/lee/Desktop/touch_graph_white/touch_graph_white.ino: In function 'void loop()':
touch_graph_white:211:26: error: 'plotNeedle' was not declared in this scope
     plotNeedle(reading, 0); // Update analogue meter, 0ms delay per needle increment
                          ^
/Users/lee/Desktop/touch_graph_white/touch_graph_white.ino: At global scope:
touch_graph_white:214:1: error: expected unqualified-id before '{' token
 {
 ^
/Users/lee/Desktop/touch_graph_white/touch_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_graph_white:781:22: error: 'plotNeedle' was not declared in this scope
       plotNeedle(0, 0); // Put meter needle at 0
                      ^
touch_graph_white:792:5: error: a function-definition is not allowed here before '{' token
     {
     ^
touch_graph_white:843:1: error: expected '}' at end of input
 }
 ^
touch_graph_white:843:1: error: expected '}' at end of input
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
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
exit status 1
'plotNeedle' was not declared in this scope

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

UKHeliBob

Code: [Select]

void loop()
{
  if (updateTime <= millis())
  {
    updateTime = millis() + 0;
    int reading = 0;
    reading = map(analogRead(PB0), 0, 4195, 0, 100);
    plotNeedle(reading, 0); // Update analogue meter, 0ms delay per needle increment
  }
}
{  //<<<<<<< WHAT IS THIS NONSENSE ALL ABOUT ?  WHICH FUNCTION IS THE CODE IN ?
  p1volts = analogRead(PA0);
  p2volts = analogRead(PA1);


I am about to give up.

See my comment added to the code portion above
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Leetut

not sure which nonsense you're referring to, the { you're pointing at or above it
either way both are like that originally

Code: [Select]
{
  if (updateTime <= millis()) {
    updateTime = millis() + 0;
    int reading = 0;
    reading = map(analogRead(PB0), 0, 4195, 0, 100);
    plotNeedle(reading, 0); // Update analogue meter, 0ms delay per needle increment
  }
}



Code: [Select]
{
  p1volts = analogRead(PA0);
  p2volts = analogRead(PA1);
  p3volts = analogRead(PA2);
  p4volts = analogRead(PA4);
  p5volts = analogRead(PA3);
  DrawBarChartP1(tft, 10, 134, 140, 7, 0, 4195 , 409, p1volts, 0, 0, GREEN, DKGREY, BLACK, WHITE, BLACK, "POT1", graph_1);
  DrawBarChartP1(tft, 10, 177, 140, 7, 0, 4195 , 409, p2volts, 0, 0, GREEN, DKGREY, BLACK, WHITE, BLACK, "POT2", graph_2);
  DrawBarChartP1(tft, 10, 220, 140, 7, 0, 4195 , 409, p3volts, 0, 0, GREEN, DKGREY, BLACK, WHITE, BLACK, "POT3", graph_3);
  DrawBarChartP1(tft, 10, 263, 140, 7, 0, 4195 , 409, p4volts, 0, 0, GREEN, DKGREY, BLACK, WHITE, BLACK, "POT4", graph_4);
  DrawBarChartP1(tft, 10, 306, 140, 7, 0, 4195 , 409, p5volts, 0, 0, GREEN, DKGREY, BLACK, WHITE, BLACK, "POT5", graph_5);

}

Leetut

still not working

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

/Users/lee/Desktop/touch_graph_white/touch_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_graph_white:777:26: error: 'plotNeedle' was not declared in this scope
     plotNeedle(reading, 0); // Update analogue meter, 0ms delay per needle increment
                          ^
touch_graph_white:782:18: error: 'plotNeedle' was not declared in this scope
   plotNeedle(0, 0); // Put meter needle at 0
                  ^
touch_graph_white:793:1: error: a function-definition is not allowed here before '{' token
 {
 ^
touch_graph_white:843:1: error: expected '}' at end of input
 }
 ^
touch_graph_white:843:1: error: expected '}' at end of input
Multiple libraries were found for "Adafruit_GFX.h"
 Used: /Users/lee/Documents/Arduino/libraries/Adafruit_GFX_Library
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
exit status 1
'plotNeedle' was not declared in this scope

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


Code: [Select]
   // 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
      // #########################################################################


      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
      }

{
  if (updateTime <= millis()) {
    updateTime = millis() + 0;
    int reading = 0;
    reading = map(analogRead(PB0), 0, 4195, 0, 100);
    plotNeedle(reading, 0); // Update analogue meter, 0ms delay per needle increment
  }
}

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

Go Up