Components and supplies
Arduino Uno Rev3
Grove - OLED Display 0.96"
Apps and platforms
Arduino IDE 2.0 (beta)
Project description
Code
Arduino Code
cpp
1#include <SPI.h> 2 3#include <Wire.h> 4 5#include <Adafruit_GFX.h> 6 7#include <Adafruit_SSD1306.h> 8#define SCREEN_WIDTH 128 // OLED display width, in pixels 9 10#define SCREEN_HEIGHT 64 // OLED display height, in pixels 11// Declaration for SSD1306 display connected using I2C 12 13#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) 14 15#define SCREEN_ADDRESS 0x3C 16 17Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); 18// Declaration for SSD1306 display connected using software SPI: 19 20//#define OLED_MOSI 9 21 22//#define OLED_CLK 10 23 24//#define OLED_DC 11 25 26//#define OLED_CS 12 27 28//#define OLED_RESET 13 29 30//Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS); 31void setup() 32 33{ 34 35 Serial.begin(9600); 36 37 // initialize the OLED object 38 39 if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) { 40 41 Serial.println(F("SSD1306 allocation failed")); 42 43 for(;;); // Don't proceed, loop forever 44 45 } 46// Uncomment this if you are using SPI 47 48 //if(!display.begin(SSD1306_SWITCHCAPVCC)) { 49 50 // Serial.println(F("SSD1306 allocation failed")); 51 52 // for(;;); // Don't proceed, loop forever 53 54 //} 55// Clear the buffer. 56display.clearDisplay(); 57 58 // Display Text 59 60 display.setTextSize(1); 61 62 display.setTextColor(WHITE); 63 64 display.setCursor(0, 28); 65 66 display.println("Hello world!"); 67 68 display.display(); 69 70 delay(2000); 71 72 display.clearDisplay(); 73// Display Inverted Text 74 75 display.setTextColor(BLACK, WHITE); // 'inverted' text 76 77 display.setCursor(0, 28); 78 79 display.println("Hello world!"); 80 81 display.display(); 82 83 delay(2000); 84 85 display.clearDisplay(); 86// Changing Font Size 87 88 display.setTextColor(WHITE); 89 90 display.setCursor(0, 24); 91 92 display.setTextSize(2); 93 94 display.println("Hello!"); 95 96 display.display(); 97 98 delay(2000); 99 100 display.clearDisplay();) { 101 102} 103// Display Numbers 104 105 display.setTextSize(1); 106 107 display.setCursor(0, 28); 108 109 display.println(123456789); 110 111 display.display(); 112 113 delay(2000); 114 115 display.clearDisplay(); 116// Specifying Base For Numbers 117 118 display.setCursor(0, 28); 119 120 display.print("0x"); display.print(0xFF, HEX); 121 122 display.print("(HEX) = "); 123 124 display.print(0xFF, DEC); 125 126 display.println("(DEC)"); 127 128 display.display(); 129 130 delay(2000); 131 132 display.clearDisplay(); 133// Display ASCII Characters 134 135 display.setCursor(0, 24); 136 137 display.setTextSize(2); 138 139 display.write(1); 140 141 display.display(); 142 143 delay(2000); 144 145 display.clearDisplay(); 146// Scroll full screen 147 148 display.setCursor(0, 0); 149 150 display.setTextSize(1); 151 152 display.println("Full"); 153 154 display.println("screen"); 155 156 display.println("scrolling!"); 157 158 display.display(); 159 160 display.startscrollright(0x00, 0x07); 161 162 delay(4500); 163 164 display.stopscroll(); 165 166 delay(1000); 167 168 display.startscrollleft(0x00, 0x07); 169 170 delay(4500); 171 172 display.stopscroll(); 173 174 delay(1000); 175 176 display.startscrolldiagright(0x00, 0x07); 177 178 delay(4500); 179 180 display.startscrolldiagleft(0x00, 0x07); 181 182 delay(4500); 183 184 display.stopscroll(); 185 186 display.clearDisplay(); 187//draw rectangle 188 189 display.setTextSize(1); 190 191 display.setTextColor(WHITE); 192 193 display.setCursor(0, 0); 194 195 display.println("Rectangle"); 196 197 display.drawRect(0, 15, 60, 40, WHITE); 198 199 display.display(); 200 201 delay(2000); 202 203 display.clearDisplay(); 204//draw filled rectangle 205 206 display.setCursor(0, 0); 207 208 display.println("Filled Rectangle"); 209 210 display.fillRect(0, 15, 60, 40, WHITE); 211 212 display.display(); 213 214 delay(2000); 215 216 display.clearDisplay(); 217//draw rectangle with rounded corners 218 219 display.setCursor(0, 0); 220 221 display.println("Round Rectangle"); 222 223 display.drawRoundRect(0, 15, 60, 40, 8, WHITE); 224 225 display.display(); 226 227 delay(2000); 228 229 display.clearDisplay(); 230//draw circle 231 232 display.setCursor(0, 0); 233 234 display.println("Circle"); 235 236 display.drawCircle(20, 35, 20, WHITE); 237 238 display.display(); 239 240 delay(2000); 241 242 display.clearDisplay(); 243//draw filled circle 244 245 display.setCursor(0, 0); 246 247 display.println("Filled Circle"); 248 249 display.fillCircle(20, 35, 20, WHITE); 250 251 display.display(); 252 253 delay(2000); 254 255 display.clearDisplay(); 256//draw triangle 257 258 display.setCursor(0, 0); 259 260 display.println("Triangle"); 261 262 display.drawTriangle(30, 15, 0, 60, 60, 60, WHITE); 263 264 display.display(); 265 266 delay(2000); 267 268 display.clearDisplay(); 269//draw filled triangle 270 271 display.setCursor(0, 0); 272 273 display.println("Filled Triangle"); 274 275 display.fillTriangle(30, 15, 0, 60, 60, 60, WHITE); 276 277 display.display(); 278 279 delay(2000); 280 281 display.clearDisplay(); 282 283} 284#include <SPI.h> 285 286#include <Wire.h> 287 288#include <Adafruit_GFX.h> 289 290#include <Adafruit_SSD1306.h> 291#define SCREEN_WIDTH 128 // OLED display width, in pixels 292 293#define SCREEN_HEIGHT 64 // OLED display height, in pixels 294// Declaration for SSD1306 display connected using I2C 295 296#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) 297 298#define SCREEN_ADDRESS 0x3C 299 300Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); 301// Declaration for SSD1306 display connected using software SPI: 302 303//#define OLED_MOSI 9 304 305//#define OLED_CLK 10 306 307//#define OLED_DC 11 308 309//#define OLED_CS 12 310 311//#define OLED_RESET 13 312 313//Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS); 314void setup() 315 316{ 317 318 Serial.begin(9600); 319 320 // initialize the OLED object 321 322 if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) { 323 324 Serial.println(F("SSD1306 allocation failed")); 325 326 for(;;); // Don't proceed, loop forever 327 328 } 329// Uncomment this if you are using SPI 330 331 //if(!display.begin(SSD1306_SWITCHCAPVCC)) { 332 333 // Serial.println(F("SSD1306 allocation failed")); 334 335 // for(;;); // Don't proceed, loop forever 336 337 //} 338// Clear the buffer. 339display.clearDisplay(); 340 341 // Display Text 342 343 display.setTextSize(1); 344 345 display.setTextColor(WHITE); 346 347 display.setCursor(0, 28); 348 349 display.println("Hello world!"); 350 351 display.display(); 352 353 delay(2000); 354 355 display.clearDisplay(); 356// Display Inverted Text 357 358 display.setTextColor(BLACK, WHITE); // 'inverted' text 359 360 display.setCursor(0, 28); 361 362 display.println("Hello world!"); 363 364 display.display(); 365 366 delay(2000); 367 368 display.clearDisplay(); 369// Changing Font Size 370 371 display.setTextColor(WHITE); 372 373 display.setCursor(0, 24); 374 375 display.setTextSize(2); 376 377 display.println("Hello!"); 378 379 display.display(); 380 381 delay(2000); 382 383 display.clearDisplay();) { 384 385} 386// Display Numbers 387 388 display.setTextSize(1); 389 390 display.setCursor(0, 28); 391 392 display.println(123456789); 393 394 display.display(); 395 396 delay(2000); 397 398 display.clearDisplay(); 399// Specifying Base For Numbers 400 401 display.setCursor(0, 28); 402 403 display.print("0x"); display.print(0xFF, HEX); 404 405 display.print("(HEX) = "); 406 407 display.print(0xFF, DEC); 408 409 display.println("(DEC)"); 410 411 display.display(); 412 413 delay(2000); 414 415 display.clearDisplay(); 416// Display ASCII Characters 417 418 display.setCursor(0, 24); 419 420 display.setTextSize(2); 421 422 display.write(1); 423 424 display.display(); 425 426 delay(2000); 427 428 display.clearDisplay(); 429// Scroll full screen 430 431 display.setCursor(0, 0); 432 433 display.setTextSize(1); 434 435 display.println("Full"); 436 437 display.println("screen"); 438 439 display.println("scrolling!"); 440 441 display.display(); 442 443 display.startscrollright(0x00, 0x07); 444 445 delay(4500); 446 447 display.stopscroll(); 448 449 delay(1000); 450 451 display.startscrollleft(0x00, 0x07); 452 453 delay(4500); 454 455 display.stopscroll(); 456 457 delay(1000); 458 459 display.startscrolldiagright(0x00, 0x07); 460 461 delay(4500); 462 463 display.startscrolldiagleft(0x00, 0x07); 464 465 delay(4500); 466 467 display.stopscroll(); 468 469 display.clearDisplay(); 470//draw rectangle 471 472 display.setTextSize(1); 473 474 display.setTextColor(WHITE); 475 476 display.setCursor(0, 0); 477 478 display.println("Rectangle"); 479 480 display.drawRect(0, 15, 60, 40, WHITE); 481 482 display.display(); 483 484 delay(2000); 485 486 display.clearDisplay(); 487//draw filled rectangle 488 489 display.setCursor(0, 0); 490 491 display.println("Filled Rectangle"); 492 493 display.fillRect(0, 15, 60, 40, WHITE); 494 495 display.display(); 496 497 delay(2000); 498 499 display.clearDisplay(); 500//draw rectangle with rounded corners 501 502 display.setCursor(0, 0); 503 504 display.println("Round Rectangle"); 505 506 display.drawRoundRect(0, 15, 60, 40, 8, WHITE); 507 508 display.display(); 509 510 delay(2000); 511 512 display.clearDisplay(); 513//draw circle 514 515 display.setCursor(0, 0); 516 517 display.println("Circle"); 518 519 display.drawCircle(20, 35, 20, WHITE); 520 521 display.display(); 522 523 delay(2000); 524 525 display.clearDisplay(); 526//draw filled circle 527 528 display.setCursor(0, 0); 529 530 display.println("Filled Circle"); 531 532 display.fillCircle(20, 35, 20, WHITE); 533 534 display.display(); 535 536 delay(2000); 537 538 display.clearDisplay(); 539//draw triangle 540 541 display.setCursor(0, 0); 542 543 display.println("Triangle"); 544 545 display.drawTriangle(30, 15, 0, 60, 60, 60, WHITE); 546 547 display.display(); 548 549 delay(2000); 550 551 display.clearDisplay(); 552//draw filled triangle 553 554 display.setCursor(0, 0); 555 556 display.println("Filled Triangle"); 557 558 display.fillTriangle(30, 15, 0, 60, 60, 60, WHITE); 559 560 display.display(); 561 562 delay(2000); 563 564 display.clearDisplay(); 565 566}
Comments
Only logged in users can leave comments
jobitjoseph
0 Followers
•0 Projects
Table of contents
Intro
0
0