hi. trying to call function Bar() but receiving error no matter where Bar(potVal) is placed within the sketch
glcd_with_bar_test_2.ino: In function 'void loop()':
glcd_with_bar_test_2:34: error: 'Bar' was not declared in this scope
#include "ST7565.h"
int redPin = 12;
int greenPin = 11;
int bluePin = 10;
int pot = A7;
ST7565 glcd(9, 8, 7, 6, 5);
void setup()
{
Serial.begin(9600);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(pot, INPUT);
// initialize and set the contrast to 0x18
glcd.begin(0x18);
glcd.display();
}
void loop()
{
int potVal = analogRead(pot);
Bar(potVal);
}
void Bar(int value = pot, int low = 0, int high = 1024, int x = 20, int y = 16, int w = 6, int h = 30, int F_color = BLACK, int B_color = WHITE)
{
int potVal = analogRead(pot);
static int lastV = -1, move = 0;
int Val = map(value, low, high, h, y);
if (Val != lastV) // prevents it from constantly being redrawn on the screen
{
if ( Val > lastV)
{
for (move; move < Val; move++)
{
glcd.fillrect(x, y, w + 1, (h - 1) - move, F_color);
}
lastV = Val;
}
else
{
for (move; move > (lastV + 1); move--)
{
glcd.fillrect(x + w, y + h, w + 1, (h - 1) + move, B_color);
}
lastV = Val;
glcd.display();
}
}
}
The alternative is to add your own, however the default values can only go on the prototype if added (which is why the IDE most probably can't add its own).
void Bar(int value = pot, int low = 0, int high = 1024, int x = 20, int y = 16, int w = 6, int h = 30, int F_color = BLACK, int B_color = WHITE);
void setup(){
}
void loop(){
}
void Bar(int value, int low, int high, int x, int y, int w, int h, int F_color, int B_color){
}
This way seams to compile it successfully.
the Bargraph still don`t work but at least i moved a little bit forward since friday.
Thank you
void Bar(int value = pot, int low = 0, int high = 1024, int x = 20, int y = 16, int w = 6, int h = 30, int F_color = BLACK, int B_color = WHITE);
void setup()
{
Serial.begin(9600);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(pot, INPUT);
// initialize and set the contrast to 0x18
glcd.begin(0x18);
glcd.display();
}
void loop()
{
int potVal = analogRead(pot);
Bar(potVal);
}
void Bar(int value, int low, int high, int x, int y, int w, int h, int F_color, int B_color)
{
}
What is wrong with it? does fillrect not draw anything?
At the end of the iteration lastV is set to Val
Then next iteration the statements say "do nothing unless value has changed from previous stored value"
Then the next statement says, "Do one thing if new value is greater, do another if lower".
Then the new value is copied into the old value storage, so simply rinse & repeat only acting on different data.
Either way, that code was written before it compiled, so I'd say the OP would notice the missing display data.