Display SSD1306 for ESP32
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

706 lines
25 KiB

  1. #include <SPI.h>
  2. #include <Wire.h>
  3. #include <Adafruit_GFX.h>
  4. #include <Adafruit_SSD1306.h>
  5. #define __DEBUG__
  6. //The following constants are used to configure the behaviour of the interface
  7. // MAX_OPTIONS defines the maximum number of options a menu can hold
  8. // MAX_MENUS declares the maximum number of menu screens in the interface
  9. // MAX_GRAPHS is the maximum number of graphs to create
  10. // DISP_WIDTH and DISP_HEIGHT are hardware specific (SSD1306)
  11. // REFRESH: is the time in miliseconds the interface will take in refreshing (this time affects the loop, keep that in mind)
  12. #define MAX_OPTIONS 10 //Maximum number of options for each menu
  13. #define MAX_MENUS 3
  14. #define MAX_GRAPHS 3
  15. #define DISP_WIDTH 128 // OLED display width
  16. #define DISP_HEIGHT 64 // OLED display height
  17. #define REFRESH 10 //Refresh time in ms
  18. #define ADDRESS 0x3C //I2C address of the display
  19. Adafruit_SSD1306 display(DISP_WIDTH, DISP_HEIGHT, &Wire, -1);
  20. class Option{
  21. private:
  22. int sizex; //Defines the size it will occupy in the x axis (width), this value is gotten from the menu
  23. int sizey; //Defines the height of the option (this value is gotten from the menu it belongs to)
  24. String content; //Text of the option
  25. int pos; //Defines the position it has in the menu
  26. int textSpacing; //According to the height, defines the space for the text, so that it's vertically centered
  27. bool fill = false; //In case an option is not selected this should be false
  28. bool disp = false; //In case an option is not configured, it should be false and, thus hidden
  29. int destinationType; //Defines what the option leads to (another menu, graph, something else)
  30. int destinationIndex; //Defines where the option leads to (index of the destination)
  31. public:
  32. //Option(){}
  33. //Method to configure an option, all attributes are assigned, and disp is true, so the option can be displayed
  34. void configure(String content, int sizex, int sizey, int pos, int destinationType, int destinationIndex){
  35. this->sizex = sizex;
  36. this->sizey = sizey;
  37. this->content = content;
  38. this->pos = pos;
  39. this->destinationType = destinationType;
  40. this->destinationIndex = destinationIndex;
  41. this->disp = true;
  42. this->textSpacing = ((sizey - 7)/2) + 7;
  43. }
  44. int getDestinationType(){
  45. int destinationType = this->destinationType;
  46. return destinationType;
  47. }
  48. int getDestinationIndex(){
  49. int destinationIndex = this->destinationIndex;
  50. return destinationIndex;
  51. }
  52. //This method draws each option
  53. void drawopt(int page, int pos, int optPPage){
  54. if(this->disp){ //Checks if the option was configured and, as a result, is displayable
  55. if(this->pos == pos){ //If the position of the option corresponds to the position passed to the function, then it should be selected
  56. display.fillRect(0, (this->sizey)*(this->pos) + 1 - (page*optPPage*this->sizey), this->sizex, this->sizey, WHITE);
  57. display.setTextColor(SSD1306_BLACK);
  58. display.setCursor(5, (this->sizey)*(this->pos + 1) - (page*optPPage*this->sizey) - this->textSpacing);
  59. display.print(this->content);
  60. display.setTextColor(SSD1306_WHITE);
  61. }
  62. else{ //If the option is not selected, the rectangle containing it shouldn't be filled
  63. display.drawRect(0, (this->sizey)*(this->pos) + 1 - (page*optPPage*this->sizey), this->sizex, this->sizey, WHITE);
  64. display.setCursor(5, (this->sizey)*(this->pos + 1) - (page*optPPage*this->sizey) - this->textSpacing);
  65. display.print(this->content);
  66. }
  67. }
  68. }
  69. };
  70. class Menu{ //ContentType (1)
  71. private:
  72. int sizex; //X size for each option in the menu
  73. int sizey; //Y size of each option in the menu
  74. int options = 0; //This indicates the number of options created
  75. int pos = 0; //This indicates the position of the cursor
  76. int page = 0; //If the menu is too long, this indicates the page that is being displayed
  77. Option opt[MAX_OPTIONS];
  78. int optPPage;
  79. int previousScreen = 0;
  80. int previousContentType = 0;
  81. public:
  82. void configure(int sizex, int sizey){ //This method configures the menu created from Screen
  83. this->sizex = sizex;
  84. this->sizey = sizey;
  85. this->optPPage = DISP_HEIGHT / this->sizey;
  86. }
  87. //The following method is used to created an option for the menu
  88. void createOption(String content, bool destinationTypeMenu, int destinationIndex){
  89. //The option takes the place in the array defined by the options number variable (options), which is later increased.
  90. this->opt[this->options].configure(content, this->sizex, this->sizey, this->options++, destinationTypeMenu, destinationIndex);
  91. }
  92. int extractDestinationType(){
  93. int destinationType = this->opt[this->pos].getDestinationType();
  94. return destinationType;
  95. }
  96. int extractDestinationIndex(){
  97. int destinationIndex = this->opt[this->pos].getDestinationIndex();
  98. return destinationIndex;
  99. }
  100. //The following method draws the whole menu by drawing every option configured within it
  101. void drawMenu(){
  102. display.clearDisplay();
  103. this->page = pos/this->optPPage; //The current page is obtained by dividing the position by the number of options per page (only integer)
  104. for(int i = 0; i < options; i++){
  105. this->opt[i].drawopt(this->page, this->pos, this->optPPage);
  106. }
  107. display.display();
  108. }
  109. //Methods used by Screen
  110. int extractPos(){ //Gets the current position of the cursor
  111. return(this->pos);
  112. }
  113. int extractOptNumber(){ //Gets the number of options in the menu
  114. return(this->options);
  115. }
  116. void increasePos(){ //Increases the position of the cursor
  117. this->pos++;
  118. }
  119. void decreasePos(){ //Decreases the position of the cursor
  120. this->pos--;
  121. }
  122. //Both of the following methods store the values of the previous screen passed as parameters by Screen
  123. void setPreviousScreen(int prev){
  124. this->previousScreen = prev;
  125. }
  126. void setPreviousContentType(int prev){
  127. this->previousContentType = prev;
  128. }
  129. //Both of the following methods retrieve the values of the screen previous to the menu containing these data.
  130. int getPreviousScreen(){
  131. int prev = this->previousScreen;
  132. return prev;
  133. }
  134. int getPreviousContentType(){
  135. int prev = this->previousContentType;
  136. return prev;
  137. }
  138. };
  139. class Graph{
  140. private:
  141. String title;
  142. char graphType; //'a' Vertical Bar, 'b' Horizontal Bar, 'c' Cartesian Graph
  143. //Assign whatever value in "configure(..." if a parameter is not required for the specified graphType
  144. double value; //For: Vertical Bar Horizontal Bar Cartesian
  145. double xpos; //For: Vertical Bar Horizontal Bar Cartesian
  146. double ypos; //For: Vertical Bar Horizontal Bar Cartesian
  147. double height; //For: Vertical Bar Horizontal Bar Cartesian
  148. double width; //For: Vertical Bar Horizontal Bar Cartesian
  149. double yminimum; //For: Vertical Bar Cartesian
  150. double ymaximum; //For: Vertical Bar Cartesian
  151. double xminimum; //For: Horizontal Bar Cartesian
  152. double xmaximum; //For: Horizontal Bar Cartesian
  153. double yStepSize; //For: Vertical Bar Cartesian
  154. double xStepSize; //For: Horizontal Bar Cartesian
  155. int digit; //For: Vertical Bar Horizontal Bar Cartesian
  156. double x;
  157. double yrange;
  158. double xrange;
  159. double ox;
  160. double oy;
  161. double count;
  162. double graphScale;
  163. bool redraw = true;
  164. int previousScreen = 0;
  165. int previousContentType = 0;
  166. public:
  167. //This method configures the graph created, defines its parameters according the type of graph selected.
  168. void configure(String title, char graphType, double xpos, double ypos, double width, double height,
  169. double yminimum, double ymaximum, double xminimum, double xmaximum, double yStepSize, double xStepSize, int digit){
  170. this->title = title;
  171. this->graphType = graphType;
  172. this->yminimum = yminimum;
  173. this->ymaximum = ymaximum;
  174. this->xminimum = xminimum;
  175. this->count = xminimum;
  176. this->xmaximum = xmaximum;
  177. this->height = height;
  178. this->width = width;
  179. this->yStepSize = yStepSize;
  180. this->xStepSize = xStepSize;
  181. this->digit = digit;
  182. this->xpos = xpos;
  183. this->ypos = ypos;
  184. switch(graphType){
  185. case 'a':
  186. this->yrange = ymaximum - yminimum;
  187. this->graphScale = (yStepSize) * (height / this->yrange) - .001; //Adjusts the scale of the graph, according to the range and the size of the step
  188. break;
  189. case 'b':
  190. this->xrange = xmaximum - xminimum;
  191. this->graphScale = (xStepSize) * (width / this->xrange) - .001; //Adjusts the scale of the graph, according to the range and the size of the step
  192. break;
  193. case 'c':
  194. this->yrange = ymaximum - yminimum;
  195. this->xrange = xmaximum - xminimum;
  196. break;
  197. }
  198. }
  199. void drawGraph(){
  200. double level, data, i;
  201. switch(graphType){
  202. case 'a':
  203. double my;
  204. if (this->redraw) { //Prints the labels
  205. display.clearDisplay();
  206. this->redraw = false;
  207. display.fillRect(0, 0, 127 , 14, SSD1306_WHITE);
  208. display.setTextColor(SSD1306_BLACK, SSD1306_WHITE);
  209. display.setTextSize(1);
  210. display.setCursor(2, 4);
  211. display.println(this->title);
  212. for (i = 0; i <= this->height; i += this->graphScale) {
  213. my = this->ypos - this->height + i;
  214. display.drawFastHLine(this->xpos + this->width + 1, my, 5, SSD1306_WHITE);
  215. // draw lables
  216. display.setTextSize(1);
  217. display.setTextColor(SSD1306_WHITE, SSD1306_BLACK);
  218. display.setCursor(this->xpos + this->width + 12, my - 3 );
  219. data = this->ymaximum - ( i * (this->yStepSize / this->graphScale));
  220. display.print(data, this->digit);
  221. }
  222. }
  223. // compute level of bar graph that is scaled to the height and the hi and low vals
  224. // this is needed to accompdate for +/- range
  225. level = (this->height * (((this->value - this->yminimum) / (this->yrange))));
  226. // draw the bar graph
  227. // write a upper and lower bar to minimize flicker cause by blanking out bar and redraw on update
  228. display.drawRect(this->xpos, this->ypos - this->height, this->width, this->height, SSD1306_WHITE);
  229. display.fillRect(this->xpos, this->ypos - this->height, this->width, this->height - level, SSD1306_BLACK);
  230. display.drawRect(this->xpos, this->ypos - this->height, this->width, this->height, SSD1306_WHITE);
  231. display.fillRect(this->xpos, this->ypos - level, this->width, level, SSD1306_WHITE);
  232. // up until now print sends data to a video buffer NOT the screen
  233. // this call sends the data to the screen
  234. display.display();
  235. break;
  236. case 'b':
  237. if (this->redraw) {
  238. display.clearDisplay();
  239. this->redraw = false;
  240. display.fillRect(0, 0, 127 , 16, SSD1306_WHITE);
  241. display.setTextColor(SSD1306_BLACK, SSD1306_WHITE);
  242. display.setTextSize(1);
  243. display.setCursor(2, 4);
  244. display.println(this->title);
  245. // draw the text
  246. for (i = 0; i <= this->width; i += this->graphScale) {
  247. display.drawFastVLine(i + this->xpos , this->ypos , 5, SSD1306_WHITE);
  248. // draw lables
  249. display.setTextSize(1);
  250. display.setTextColor(SSD1306_WHITE, SSD1306_BLACK);
  251. display.setCursor(i + this->xpos , this->ypos + 10);
  252. // addling a small value to eliminate round off errors
  253. // this val may need to be adjusted
  254. data = ( i * (this->xStepSize / this->graphScale)) + this->xminimum + 0.00001;
  255. display.print(data, this->digit);
  256. }
  257. }
  258. // compute level of bar graph that is scaled to the width and the hi and low vals
  259. // this is needed to accompdate for +/- range capability
  260. // draw the bar graph
  261. // write a upper and lower bar to minimize flicker cause by blanking out bar and redraw on update
  262. level = (this->width * (((this->value - this->xminimum) / (this->xmaximum - this->xminimum))));
  263. display.fillRect(this->xpos + level, this->ypos - this->height, this->width - level, this->height, SSD1306_BLACK);
  264. display.drawRect(this->xpos, this->ypos - this->height, this->width, this->height, SSD1306_WHITE);
  265. display.fillRect(this->xpos, this->ypos - this->height, level, this->height, SSD1306_WHITE);
  266. // up until now print sends data to a video buffer NOT the screen
  267. // this call sends the data to the screen
  268. display.display();
  269. break;
  270. case 'c':
  271. double temp;
  272. if (this->redraw == true) {
  273. this->redraw = false;
  274. display.clearDisplay();
  275. display.fillRect(0, 0, 127 , 16, SSD1306_WHITE);
  276. display.setTextColor(SSD1306_BLACK, SSD1306_WHITE);
  277. display.setTextSize(1);
  278. display.setCursor(2, 4);
  279. display.println(title);
  280. this->ox = (this->count - this->xminimum) * (this->width) / (this->xrange) + this->xpos;
  281. this->oy = (this->value - this->yminimum) * (- this->height) / (this->yrange) + this->ypos;
  282. // draw y scale
  283. display.setTextSize(1);
  284. display.setTextColor(SSD1306_WHITE, SSD1306_BLACK);
  285. for ( i = this->yminimum; i <= this->ymaximum; i += this->yStepSize) {
  286. // compute the transform
  287. // note my transform funcition is the same as the map function, except the map uses long and we need doubles
  288. temp = (i - this->yminimum) * (- this->height) / (this->ymaximum - this->yminimum) + this->ypos;
  289. if (i == 0) {
  290. display.drawFastHLine(this->xpos - 3, temp, this->width + 3, SSD1306_WHITE);
  291. }
  292. else {
  293. display.drawFastHLine(this->xpos - 3, temp, 3, SSD1306_WHITE);
  294. }
  295. display.setCursor(this->xpos - 27, temp - 3);
  296. display.println(i, this->digit);
  297. }
  298. // draw x scale
  299. for (i = this->xminimum; i <= this->xmaximum; i += this->xStepSize) {
  300. // compute the transform
  301. display.setTextSize(1);
  302. display.setTextColor(SSD1306_WHITE, SSD1306_BLACK);
  303. temp = (i - this->xminimum) * (this->width) / (this->xrange) + this->xpos;
  304. if (i == 0) {
  305. display.drawFastVLine(temp, this->ypos - this->height, this->height + 3, SSD1306_WHITE);
  306. }
  307. else {
  308. display.drawFastVLine(temp, this->ypos, 3, SSD1306_WHITE);
  309. }
  310. display.setCursor(temp, this->ypos + 6);
  311. display.println(i, this->digit);
  312. }
  313. }
  314. // graph drawn now plot the data
  315. // the entire plotting code are these few lines...
  316. this->x = (this->count - this->xminimum) * (this->width) / (this->xrange) + this->xpos;
  317. this->value = (this->value - this->yminimum) * (- this->height) / (this->yrange) + this->ypos;
  318. display.drawLine(this->ox, this->oy, this->x, this->value, SSD1306_WHITE);
  319. display.drawLine(this->ox, this->oy - 1, this->x, this->value - 1, SSD1306_WHITE);
  320. this->ox = this->x;
  321. this->oy = this->value;
  322. // up until now print sends data to a video buffer NOT the screen
  323. // this call sends the data to the screen
  324. display.display();
  325. this->count += 1;
  326. if(this->ox >= (this->xpos + this->width)){
  327. this->redraw = true;
  328. this->count = xminimum;
  329. }
  330. }
  331. }
  332. void redrawFlag(){ // Activates the redraw bool to get the graph printed correctly
  333. this->redraw = true;
  334. }
  335. void setPreviousScreen(int prev){
  336. this->previousScreen = prev;
  337. }
  338. void setPreviousContentType(int prev){
  339. this->previousContentType = prev;
  340. }
  341. int getPreviousScreen(){
  342. int prev = this->previousScreen;
  343. return prev;
  344. }
  345. int getPreviousContentType(){
  346. int prev = this->previousContentType;
  347. return prev;
  348. }
  349. void assignValue(double value){
  350. this->value = value;
  351. }
  352. void reset(){
  353. this->x = 0;
  354. }
  355. };
  356. class Screen{
  357. private:
  358. Menu menu[MAX_MENUS]; //Array of menus to use
  359. Graph graph[MAX_GRAPHS]; //Array of graphs to use
  360. int counterM = 0; //Number of menus created
  361. int counterG = 0; //Number of graphs created
  362. bool redraw = true; //Redraw interface for when there is a change of screen
  363. int currentScreen = 0;
  364. int contentType = 0;
  365. public:
  366. void configure(bool fullsetting){ //This method allows the configuration of the display when the parameter is true. Otherwise only prints a greeting message.
  367. if(fullsetting){
  368. //Adafruit_SSD1306 display(DISP_WIDTH, DISP_HEIGHT, &Wire, -1);
  369. Serial.begin(115200);
  370. if (!display.begin(SSD1306_SWITCHCAPVCC, ADDRESS)) {
  371. #ifdef __DEBUG__
  372. Serial.println("Display not found!");
  373. #endif
  374. while (true);
  375. }
  376. }
  377. display.clearDisplay();
  378. // Text size
  379. display.setTextSize(2);
  380. // Text color
  381. display.setTextColor(SSD1306_WHITE);
  382. // Text position
  383. display.setCursor(25, 20);
  384. display.println("Welcome");
  385. display.setTextSize(1);
  386. display.display();
  387. delay(5000);
  388. }
  389. void createMenu(int sizex, int sizey){ //This method is used for the creation of a menu
  390. this->menu[counterM].configure(sizex, sizey);
  391. this->counterM++;
  392. }
  393. void createOption(int menuIndex, String content, bool destinationTypeMenu, int destinationIndex){ //this method should be used for creating an option in a menu
  394. this->menu[menuIndex].createOption(content, destinationTypeMenu, destinationIndex);
  395. }
  396. void createVGraph(String title, double xpos, double ypos, double width, double height,
  397. double yminimum, double ymaximum, double yStepSize, int digit){ //this method calls the configure() of graph for a vertical graph
  398. this->graph[counterG].configure(title, 'a', xpos, ypos, width, height, yminimum, ymaximum, 0, 0, yStepSize, 0, digit);
  399. this->counterG++;
  400. }
  401. void createHGraph(String title, double xpos, double ypos, double width, double height,
  402. double xminimum, double xmaximum, double xStepSize, int digit){ //this method calls the configure() of graph for a horizontal graph
  403. this->graph[counterG].configure(title, 'b', xpos, ypos, width, height, 0, 0, xminimum, xmaximum, 0, xStepSize, digit);
  404. counterG++;
  405. }
  406. void createCGraph(String title, double xpos, double ypos, double width, double height,
  407. double yminimum, double ymaximum, double xminimum, double xmaximum, double yStepSize, double xStepSize, int digit){ //this method calls the configure() of graph for a cartesian chart
  408. this->graph[counterG].configure(title, 'c', xpos, ypos, width, height, yminimum, ymaximum, xminimum, xmaximum, yStepSize, xStepSize, digit);
  409. counterG++;
  410. }
  411. /*
  412. void redrawFlag(){
  413. this->redraw = true;
  414. }
  415. */
  416. //The following method is used for assingning a value to a graph
  417. void graphAssignValue(int graphIndex, double value){
  418. this->graph[graphIndex].assignValue(value);
  419. this->redraw = true;
  420. }
  421. //This method controls the whole interface, it needs to be called within a loop
  422. void control(){
  423. if (redraw){
  424. if (contentType == 0){
  425. menu[currentScreen].drawMenu();
  426. }
  427. else if (contentType == 1){
  428. graph[currentScreen].drawGraph();
  429. }
  430. this->redraw = false;
  431. }
  432. }
  433. //The following two methods allow the change in position of the cursor
  434. void increasePos(){
  435. if(this->menu[this->currentScreen].extractPos() < this->menu[this->currentScreen].extractOptNumber() - 1)
  436. this->menu[this->currentScreen].increasePos();
  437. }
  438. void decreasePos(){
  439. if(this->menu[this->currentScreen].extractPos() > 0)
  440. this->menu[this->currentScreen].decreasePos();
  441. }
  442. //This method lets the user go into another screen by selecting an option
  443. void goTo(){
  444. if(this->contentType == 0){
  445. int newScreen = this->menu[this->currentScreen].extractDestinationIndex();
  446. int newContentType = this->menu[this->currentScreen].extractDestinationType();
  447. if (newContentType == 0){
  448. this->menu[newScreen].setPreviousScreen(this->currentScreen);
  449. this->menu[newScreen].setPreviousContentType(this->contentType);
  450. }
  451. else if(newContentType == 1){
  452. this->graph[newScreen].setPreviousScreen(this->currentScreen);
  453. this->graph[newScreen].setPreviousContentType(this->contentType);
  454. this->graph[newScreen].reset();
  455. this->graph[newScreen].redrawFlag();
  456. }
  457. else if(newContentType == 2){
  458. }
  459. this->contentType = newContentType;
  460. this->currentScreen = newScreen;
  461. this->redraw = true;
  462. }
  463. }
  464. void goBack(){
  465. if(contentType == 0){
  466. //Gets indexes from previous screen saved in actual screen if it is a menu, and sets them as the current indexes
  467. this->currentScreen = this->menu[this->currentScreen].getPreviousScreen();
  468. this->contentType = this->menu[this->currentScreen].getPreviousContentType();
  469. }
  470. else if(contentType == 1){
  471. //Gets indexes from previous screen saved in actual screen if it is a graph, and sets them as the current indexes
  472. this->currentScreen = this->graph[this->currentScreen].getPreviousScreen();
  473. this->contentType = this->graph[this->currentScreen].getPreviousContentType();
  474. }
  475. }
  476. //These methods control the plus and minus button actions
  477. void plusAction(){
  478. if(contentType == 0){
  479. increasePos();
  480. }
  481. }
  482. void minusAction(){
  483. if(contentType == 0){
  484. decreasePos();
  485. }
  486. }
  487. };
  488. class Keyboard{
  489. private:
  490. byte goTo;
  491. byte goBack;
  492. byte plus;
  493. byte minus;
  494. byte debounceTime;
  495. Screen *screen;
  496. public:
  497. //Keyboard constructor
  498. Keyboard(byte goTo, byte goBack, byte plus, byte minus, byte debounceTime, Screen * screen){
  499. this->goTo = goTo;
  500. this->goBack = goBack;
  501. this->plus = plus;
  502. this->minus = minus;
  503. this->debounceTime = debounceTime;
  504. this->screen = screen;
  505. pinMode(goTo, INPUT_PULLUP);
  506. pinMode(goBack, INPUT_PULLUP);
  507. pinMode(plus, INPUT_PULLUP);
  508. pinMode(minus, INPUT_PULLUP);
  509. }
  510. //Debouncing functions
  511. void checkGoTo(){
  512. static char cont;
  513. if(digitalRead(this->goTo) == LOW)
  514. cont++;
  515. else
  516. cont = 0;
  517. if(cont == debounceTime/REFRESH){
  518. this->screen->goTo();
  519. }
  520. }
  521. void checkGoBack(){
  522. static char cont;
  523. if(digitalRead(this->goBack) == LOW){
  524. cont++;
  525. }
  526. else
  527. cont = 0;
  528. if(cont == debounceTime/REFRESH){
  529. this->screen->goBack();
  530. }
  531. }
  532. void checkPlus(){
  533. static char cont;
  534. if(digitalRead(this->plus) == LOW)
  535. cont++;
  536. else
  537. cont = 0;
  538. if(cont == debounceTime/REFRESH){
  539. this->screen->plusAction();
  540. }
  541. }
  542. void checkMinus(){
  543. static char cont;
  544. if(digitalRead(this->minus) == LOW)
  545. cont++;
  546. else
  547. cont = 0;
  548. if(cont == debounceTime/REFRESH){
  549. this->screen->minusAction();
  550. }
  551. }
  552. // All buttons are checked with this method
  553. void control(){
  554. this->checkGoTo();
  555. this->checkGoBack();
  556. this->checkPlus();
  557. this->checkMinus();
  558. }
  559. };
  560. int i = 0;
  561. Screen screen;
  562. Keyboard keyboard(13, 12, 14, 27, 30, &screen);
  563. void setup(){
  564. screen.configure(true);
  565. screen.createMenu(128, 13); //Menu 0
  566. screen.createMenu(128, 13); //Menu 1
  567. /*String title, char graphType, double xpos, double ypos, double width, double height,
  568. double yminimum, double ymaximum, double xminimum, double xmaximum, double yStepSize, double xStepSize, double digit*/
  569. screen.createVGraph("Grafica 1", 25, 60, 40, 40, 0, 100, 10, 0); //Graph 0
  570. screen.createHGraph("Grafica 2", 10, 40, 100, 20, 0, 100, 10, 0); //Graph 1
  571. screen.createCGraph("Grafica 3", 30, 50, 75, 30, 0, 100, 0, 1000, 25, 250, 0); //Graph 2
  572. screen.createOption(0, "Vertical graph", 1, 0);
  573. //Creates the first option in Menu 0, directing to a graph (contentType = 1 (Graph)), 0 (Graph 0)
  574. screen.createOption(0, "Horizontal graph", 1, 1);
  575. screen.createOption(0, "Cartesian graph", 1, 2);
  576. screen.createOption(0, "Extra option", 0, 1);
  577. screen.createOption(1, "Test", 1, 3);
  578. screen.createOption(1, "Working?", 1, 4);
  579. // screen.increasePos();
  580. // screen.increasePos();
  581. // screen.goTo();
  582. // screen.graphAssignValue(2, 50);
  583. // screen.goBack();
  584. // screen.increasePos();
  585. // screen.goTo();
  586. // screen.goBack();
  587. // screen.decreasePos();
  588. }
  589. void loop(){
  590. screen.control(); //Controls the screen and redraws if needed
  591. keyboard.control();
  592. if(i <= 100){
  593. screen.graphAssignValue(1, i); //Assigning a demo value to Graph 1
  594. screen.graphAssignValue(2, i); //Assigning a demo value to Graph 2
  595. i++;
  596. }
  597. else
  598. i = 0;
  599. delay(REFRESH); //Refresh time (approx)
  600. }