how to use namespace?

I was trying to test an accelerometer/OLED-display program from

I had installed the jugle libraries for OLED1306 display.
Compiling the sketch posted on instructables I receive the error
scr.flush "scr was not declared in this scope"
Probably it has to do with namespace. I am not an expert in Arduino, unfortunately.
Any suggestion on how to fix?

Probably it has to do with namespace

Probably not

Please post the code that you are trying to compile

Scope has nothing to do with namespace.

Scope can be global or local to a block defined by {}. When it says "not defined in this scope" it means "you forgot to define it, silly."

Namespaces are useful for larger programs, like you might have a color LCD screen and a multi-color LED. The constant YELLOW has different meaning in the two libraries you picked to drive those two devices.

AccelStepper is the only Arduino library I know of in common usage which encourages you to use the namespace. Most others just use distinct names, such as RA8875_YELLOW in the RA8875 LCD library.

Here is the code:
//https://www.instructables.com/id/Interacting-With-an-OLED-and-an-Accelerometer/
#include <JUGL.h>
#include <SPI.h>
#include <Wire.h>
#include <JUGL_SSD1306_128x64.h>
using namespace JUGL;
SSD1306_128x64 driver;

const int xpin = A3; //Assign pin A3 to x
const int ypin = A2; //Assign pin A2 to y
int x, y, x1, y1, r, varx, vary, width, height; //Define variables
int xy [2]; //Array to hold (x,y) coordinate

//Declaration of functions
void Circle(IScreen& scr);
void move_right(IScreen& scr);
void stop_right(IScreen& scr);
void move_left(IScreen& scr);
void stop_left(IScreen& scr);
void move_up(IScreen& scr);
void stop_up(IScreen& scr);
void move_down(IScreen& scr);
void stop_down(IScreen& scr);

void setup(){
IScreen& screen = driver; //Make reference to driver
screen.Begin(); //Initialize screen
width = screen.GetWidth(); //Get width of screen (128)
height = screen.GetHeight(); //Get height of screen (64)
Circle(screen); //Draw circle
}

void loop(){
x1 = analogRead(xpin); //Read x analog data
y1 = analogRead(ypin); //Read y analog data

IScreen& screen = driver; //Make reference to driver

if(x1<500){ //Check if sensor is tilted to the right
move_right(screen); //Move ball right
if(varx>=width-1-r ){ //Check if ball reached end of screen
stop_right(screen); //Stop moving
}
}

if(x1>520){ //Check if sensor is tilted to the left
move_left(screen); //Move ball left
if(varx=height-1-r){ //Check if ball reached end of screen
stop_up(screen); //Stop moving
}
}

if(y1>510){ //Check if sensor is tilted down
move_down(screen); //Move ball down
if(vary<r){ //Check if ball is within boundaries
scr->Flush(); //Display on screen
}
}

void stop_left(IScreen& scr){
scr.Clear(); //Clear screen
varx = r; //Update varx
xy[0] = varx; //Store new varx value
scr.FillCircle(Point(5,xy[1]),r); //Draw circle
scr.Flush(); //Display on screen
}

void move_up(IScreen& scr){
scr.Clear(); //Clear screen
vary += 10; //Move ball 10 pixels up, assign value to vary
xy[1] = vary; //Store new vary value
scr.FillCircle(Point(xy[0],vary),r); //Draw circle
if(varyr){ //Check if ball is within boundaries
scr.Flush(); //Display on screen
}
}

void stop_down(IScreen& scr){
scr.Clear(); //Clear screen
vary = r; //Update vary
xy[1] = vary; //Store new vary value
scr.FillCircle(Point(xy[0],5),r); //Draw circle
scr.Flush(); //Display on screen
}

scr is undefined in your loop.
Try replacing it with screen.
Also it should probably be

screen.Flush();

instead of

screen->Flush();

Thank you very much Ugolonix,

replacing scr by screen removes the previous error
but now this error occurs:
68: void move_up(IScreen& scr){

"A function definition is not allowed here before '{'token

resources:

if(y1>510){ //Check if sensor is tilted down

move_down(screen); //Move ball down
if(vary<r){ //Check if ball is within boundaries
scr->Flush(); //Display on screen
}
}

You should add a } after this, else you are not closing the loop.

Doesn't help, exactly the same error

Post your current, updated code. USE CODE TAGS!!!!

I missed the </>, sorry.

//https://www.instructables.com/id/Interacting-With-an-OLED-and-an-Accelerometer/
#include <JUGL.h>
#include <SPI.h>
#include <Wire.h>
#include <JUGL_SSD1306_128x64.h>
using namespace JUGL;
SSD1306_128x64 driver;
 
const int xpin = A3; //Assign pin A3 to x                 
const int ypin = A2; //Assign pin A2 to y
int x, y, x1, y1, r, varx, vary, width, height; //Define variables
int xy [2]; //Array to hold (x,y) coordinate
 
//Declaration of functions
void Circle(IScreen& scr);
void move_right(IScreen& scr);
void stop_right(IScreen& scr);
void move_left(IScreen& scr);
void stop_left(IScreen& scr);
void move_up(IScreen& scr);
void stop_up(IScreen& scr);
void move_down(IScreen& scr);
void stop_down(IScreen& scr);
 
void setup(){
  IScreen& screen = driver;  //Make reference to driver
  screen.Begin(); //Initialize screen
  width = screen.GetWidth(); //Get width of screen (128)
  height = screen.GetHeight(); //Get height of screen (64)
  Circle(screen); //Draw circle
}
 
void loop(){
  x1 = analogRead(xpin); //Read x analog data
  y1 = analogRead(ypin); //Read y analog data
 
  IScreen& screen = driver; //Make reference to driver
 
  if(x1<500){ //Check if sensor is tilted to the right
  move_right(screen); //Move ball right
  if(varx>=width-1-r ){ //Check if ball reached end of screen
    stop_right(screen); //Stop moving
  }
  }
 
 if(x1>520){ //Check if sensor is tilted to the left
 move_left(screen); //Move ball left
 if(varx=height-1-r){ //Check if ball reached end of screen
 stop_up(screen); //Stop moving
 }
 }
 
 if(y1>510){ //Check if sensor is tilted down
 move_down(screen); //Move ball down
 if(vary<r){ //Check if ball is within boundaries
  screen.Flush(); //Display on screen
  }
}
 
void stop_left(IScreen& scr){
  screen.Clear(); //Clear screen
  varx = r; //Update varx
  xy[0] = varx; //Store new varx value
  screen.FillCircle(Point(5,xy[1]),r); //Draw circle
  scr.Flush(); //Display on screen
}
 
void move_up(IScreen& scr){
  screen.Clear(); //Clear screen
  vary += 10; //Move ball 10 pixels up, assign value to vary
  xy[1] = vary; //Store new vary value
  screen.FillCircle(Point(xy[0],vary),r); //Draw circle
  if(varyr){ //Check if ball is within boundaries
    scr.Flush(); //Display on screen
 }
}}
 
void stop_down(IScreen& scr){
  screen.Clear(); //Clear screen
  vary = r; //Update vary
  xy[1] = vary; //Store new vary value
  screen.FillCircle(Point(xy[0],5),r); //Draw circle
  screen.Flush(); //Display on screen
}

With your code in the Arduino IDE, press ctrl-t to auto-format and adjust indenting. All functions should start on the far left side. Your's don't because you're missing a '}' at the end of one of them.

Now all functions start on the far left side now.
Then, when I use scr instead of screen (screen had been suggested previously) i get the error
line 56: scr.flush "scr was not declared in this scope".
If I change in just that line scr to screen, I get the error
line 74 (if vary) { "vary was not declared in this scope"

//https://www.instructables.com/id/Interacting-With-an-OLED-and-an-Accelerometer/
#include <JUGL.h>
#include <SPI.h>
#include <Wire.h>
#include <JUGL_SSD1306_128x64.h>
using namespace JUGL;
SSD1306_128x64 driver;

const int xpin = A3; //Assign pin A3 to x
const int ypin = A2; //Assign pin A2 to y
int x, y, x1, y1, r, varx, vary, width, height; //Define variables
int xy [2]; //Array to hold (x,y) coordinate

//Declaration of functions
void Circle(IScreen& scr);
void move_right(IScreen& scr);
void stop_right(IScreen& scr);
void move_left(IScreen& scr);
void stop_left(IScreen& scr);
void move_up(IScreen& scr);
void stop_up(IScreen& scr);
void move_down(IScreen& scr);
void stop_down(IScreen& scr);

void setup() {
  IScreen& screen = driver;  //Make reference to driver
  screen.Begin(); //Initialize screen
  width = screen.GetWidth(); //Get width of screen (128)
  height = screen.GetHeight(); //Get height of screen (64)
  Circle(screen); //Draw circle
}

void loop() {
  x1 = analogRead(xpin); //Read x analog data
  y1 = analogRead(ypin); //Read y analog data

  IScreen& screen = driver; //Make reference to driver

  if (x1 < 500) { //Check if sensor is tilted to the right
    move_right(screen); //Move ball right
    if (varx >= width - 1 - r ) { //Check if ball reached end of screen
      stop_right(screen); //Stop moving
    }
  }

  if (x1 > 520) { //Check if sensor is tilted to the left
    move_left(screen); //Move ball left
    if (varx = height - 1 - r) { //Check if ball reached end of screen
      stop_up(screen); //Stop moving
    }
  }

  if (y1 > 510) { //Check if sensor is tilted down
    move_down(screen); //Move ball down
    if (vary < r) { //Check if ball is within boundaries
      scr.Flush(); //Display on screen
    }
  }
}

void stop_left(IScreen & scr) {
  scr.Clear(); //Clear screen
  varx = r; //Update varx
  xy[0] = varx; //Store new varx value
  scr.FillCircle(Point(5, xy[1]), r); //Draw circle
  scr.Flush(); //Display on screen
}

void move_up(IScreen & scr) {
  scr.Clear(); //Clear screen
  vary += 10; //Move ball 10 pixels up, assign value to vary
  xy[1] = vary; //Store new vary value
  scr.FillCircle(Point(xy[0], vary), r); //Draw circle
  if (varyr) { //Check if ball is within boundaries
    scr.Flush(); //Display on screen
  }
}
void stop_down(IScreen & scr) {
  scr.Clear(); //Clear screen
  vary = r; //Update vary
  xy[1] = vary; //Store new vary value
  scr.FillCircle(Point(xy[0], 5), r); //Draw circle
  scr.Flush(); //Display on screen
}
}

What does Line 74 REALLY say?

Apparently, >r was missing in the code from instructables.
I found this
if (varyr>r) { //Check if ball is within boundaries
at this website:

Was that your question?

It does not remove the error.

My money is on the compiler. If it says a variable is not defined / declare, then you have to figure out why it thinks that. So, where in your code the variable 'varyr' defined?

It should read vary not varyr. but fixing that other errors are popping up.
Maybe I should quit for now.
No fun with codes... posted elsewhere.
Thanks for your help.

For some reason, a lot of the Arduino projects on Instructables are very low quality. I'm sure there are some good ones, but you definitely need to take a minute to try to evaluate the source of the information you find online. I find that code on GitHub tends to be of higher quality, though there is certainly some bad code there too.

pert:
For some reason, a lot of the Arduino projects on Instructables are very low quality

You're being charitable.