Then I create "EasierPlotTest.ino", which is a copy of Adafruit's ssd1306_128x64_i2c.ino, with added
- Code: Select all | TOGGLE FULL SIZE
#include "EasierPlot.h"
[Arduino: 1.8.13 (Mac OS X), Board: "Arduino Uno"
In file included from /Users/dnfharris/Documents/Arduino/EasierPlotTest/EasierPlotTest.ino:28:0:
/Users/dnfharris/Documents/Arduino/libraries/EasierPlot/EasierPlot.h:11:0: error: unterminated #ifndef
#ifndef EasierPlot_h
exit status 1
Error compiling for board Arduino Uno.]
which seems odds it seems to be what the tutorial says to do!
If I comment out #ifndef EasierPlot.h, it then gives error
[EasierPlotTest:40:18: error: expected initializer before 'display'
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
^~~~~~~
/Users/dnfharris/Documents/Arduino/EasierPlotTest/EasierPlotTest.ino: In function 'void setup()':
EasierPlotTest:72:7: error: 'display' was not declared in this scope
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32
^~~~~~~
/Users/dnfharris/Documents/Arduino/EasierPlotTest/EasierPlotTest.ino:72:7: note: suggested alternative: 'delay'
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32
^~~~~~~
delay
EasierPlotTest:79:3: error: 'display' was not declared in this scope
display.display();
^~~~~~~
/Users/dnfharris/Documents/Arduino/EasierPlotTest/EasierPlotTest.ino:79:3: note: suggested alternative: 'delay'
display.display();
^~~~~~~
delay
EasierPlotTest:82:13: error: expected unqualified-id before '.' token
EasierPlot.setupBar(false, 1,20,40,20,2);
^
/Users/dnfharris/Documents/Arduino/EasierPlotTest/EasierPlotTest.ino: In function 'void loop()':
EasierPlotTest:94:13: error: expected unqualified-id before '.' token
EasierPlot.plotBar(val);
^
exit status 1
expected initializer before 'display'].
I assume I have missed some declaration or something? Is it because EasierPlot.cpp uses some of Adafruit's calls [eg display.drawRect() ] but I haven't declared them properly?
Apologies if it should be obvious!
Many thanks
David
Code of EasierPlot.h
- Code: Select all | TOGGLE FULL SIZE
/*
* EasierPlot.h - Library for some useful routine
* when using simple SSD 1306, to avoid problems
* with the defualt y0 being at the top of the screen
* Also has
* bar graph - vertical or horizantal with digital value
* Created by David Harris, December 2020
* Released into the public domain
*/
#ifndef EasierPlot_h
#define EasierPlot_h
#include "Arduino.h"
#include "wire.h"
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
class EasierPlot {
public:
EasierPlot(); // construtor
void setupBar(bool vertical, int x0, int y0, int xSize, int ySize, int textSize);
/* plot an outline rectangle of the bar chart area, and set text parameters if wanted
vertical is TRUE if plotting a column, FALSE if a bar */
void plotBar(int value);
/* plot a bar the size of the value, nd text value if wanted */a
private:
void printValue(int _value, bool _vertical);
int plotY(int y);
int _value;
bool _vertical;
bool _textSize;
int _x0;
int _y0;
int _xSize;
int _ySize;
}