Project tutorial
Psychic Arduino

Psychic Arduino

You do not need a psychic when dealing with life's problems! Let Arduino answer your every question which may confound you.

  • 3,659 views
  • 0 comments
  • 3 respects

Components and supplies

GLCD 128x128 Color TFT / SPI Interface
http://www.ebay.com/itm/310876068105
×1
Ard nano
Arduino Nano R3
http://www.ebay.com/itm/New-Mini-USB-Nano-V3-0-ATmega328-5V-16M-Micro-controller-board-Arduino-/200964325858
×1
Mercury Switch (optional)
Automobile or Appliance store or eBay
×1

About this project

If life has been too serious for you lately, this weekend project will take some of the stress out of your life and create a really neat toy in the process; a delight for a child or for those children who gather around your desk at work!

Remember those Magic 8 Balls from the '50's and '60's?

Deja vu

These are still available today. Essentially a dark liquid in a plastic ball with a clear plastic viewing port on the bottom. Ask a question, shake the ball, turn it over, and soon a message will appear to answer your question; or sometimes you just get put-off and have to try again.

Those 20 classic phrases are repeated in this Arduino project and randomly chosen each time power is applied. Use a push-button or a mercury switch to activate the power to the Arduino and have the answer appear on the colored LCD display within seconds!

Great fun. For more fun, edit the storage array in the source code and create your own phrases, or translate the English to your native tongue. Using inexpensive Chinese supplied parts, this project will cost under $10.

Construction ideas: Use a clear acrylic globe or a hampster exercise ball for the project. Paint it black, add a white "?" or "8" and a double-AA battery pack.  

Warning: This is a 3.3 Volt ONLY project so significant adjustments will be required to run above 3.6 volts absolute maximum.  For extra long life, use "C" alkaline batteries, x2. I have yet to have a Nano clone from China fail to work at 3.3V but the factory specifications are for 5V and therefore one does take a chance with a lower voltage. You may wish to consider this ProMicro clone if you want a bit of insurance and do not want to test the fates: https://www.sparkfun.com/products/12587

YouTube Demo
See notes on SPI below
Warning: embedding parts within the project story has been deprecated. To edit, remove or add more parts, go to the "Hardware" tab. To remove this list from the story, click on it to trigger the context menu, then click the trash can button (this won't delete it from the "Hardware" tab).
GLCD 128x128 Color TFT / SPI Interface
http://www.ebay.com/itm/310876068105
Ard nano
Arduino Nano R3
http://www.ebay.com/itm/New-Mini-USB-Nano-V3-0-ATmega328-5V-16M-Micro-controller-board-Arduino-/200964325858
Mercury Switch (optional)
Automobile or Appliance store or eBay
SPI Connection notes
Untitled file

Warning: Embedding code files within the project story has been deprecated. To edit this file or add more files, go to the "Software" tab. To remove this file from the story, click on it to trigger the context menu, then click the trash can button (this won't delete it from the "Software" tab).

/*

GLCD                     Signal           Arduino 328P

J2#                        Name           Pin / Signal

1 . . . . . . . . . . . .  Vcc . . . . .  Pin#27 on Nano

2 . . . . . . . . . . . .  GND . . . . .  Pin#29 on Nano

3 . . . . . . . . . . . .   CS . . . . .  D10

4 . . . . . . . . . . . .  Reset . . . .  D12

5 . . . . . . . . . . . .  DC(A0). . . .   D9

6 . . . . . . . . . . . .  MOSI(SDA) . .  D11

7 . . . . . . . . . . . .  SCLK(SCK) . .  D13

8 . . . . . . . . . . . .  LED Backlight  3.3 Vcc (Verify 10 Ohm on display)



Note: This example sketch and wiring REQUIRES that the Nano be run at 3.3V maximum

*/
Ray's Notes
Untitled file

Warning: Embedding code files within the project story has been deprecated. To edit this file or add more files, go to the "Software" tab. To remove this file from the story, click on it to trigger the context menu, then click the trash can button (this won't delete it from the "Software" tab).

/*

   Hardware Library for 128x128 GLCD: https://github.com/sumotoy/TFT_ILI9163C

   Author/Ref: http://forum.pjrc.com/threads/25862-ILI9163C-128x128-TFT-driver

   

   Adafruit (Ladyada) Graphic core: https://github.com/adafruit/Adafruit-GFX-Library

   

   GLCD source: http://www.ebay.com/itm/310876068105



   YouTube of testing: http://youtu.be/RLDTBaXMmX4 



http://en.wikipedia.org/wiki/Magic_8-Ball

Magic 8 Ball...

The 20 answers inside a Magic 8 Ball are:



G  It is certain

G  It is decidedly so

G  Without a doubt

G  Yes definitely

G  You may rely on it

G  As I see it, yes

G  Most likely

G  Outlook good

G  Yes

G  Signs point to yes

Y  Reply hazy try again

Y  Ask again later

Y  Better not tell you now

Y  Cannot predict now

Y  Concentrate and ask again

R  Don't count on it

R  My reply is no

R  My sources say no

R  Outlook not so good

R  Very doubtful

Ten of the possible answers are Positive(G), five are Negative (R), and five are Neutral(Y).
Arduino Source
Untitled file

Warning: Embedding code files within the project story has been deprecated. To edit this file or add more files, go to the "Software" tab. To remove this file from the story, click on it to trigger the context menu, then click the trash can button (this won't delete it from the "Software" tab).

/* Binary sketch size: 9,598 bytes (of a 30,720 byte maximum)

   Compiled and tested on Arduino (clone) Nano

// 20140814 using 1.0.5r2 */



#include <SPI.h>

#include <Adafruit_GFX.h>

#include <TFT_ILI9163C.h>



// Connecct all 5 connections to LCD for hardware SPI

#define __DC   9

#define __CS  10

// MOSI(SDA) D11

#define __RST 12

// SCLK(SCK) D13



// Color definitions

#define	BLACK           0x0000

#define	BLUE            0x001F

#define	RED             0xF800

#define	GREEN           0x07E0

#define CYAN            0x07FF

#define MAGENTA         0xF81F

#define YELLOW          0xFFE0  

#define WHITE           0xFFFF

#define TRANSPARENT     -1



char* PROGMEM Spirits[] = {"It is\ncertain",      // Green

                           "It is\ndecidedly\nso",

                           "Without a\ndoubt",

                           "Yes\ndefinitely",

                           "You may\nrely on it",

                           "As I see\nit, yes",

                           "Most\nlikely",

                           "Outlook\ngood",

                           "Yes",

                           "Signs\npoint\nto yes", // end of Green. Begin Yellow

                           "Reply hazy\ntry again",

                           "Ask again\nlater",

                           "Better nottell you\nnow",

                           "Cannot\npredict\nnow",  // end of Yellow. Begin Red

                           "Reflect\nand ask\nagain",

                           "Don't\ncount on\nit",

                           "My reply\nis no",

                           "My sourcessay no",

                           "Outlook\nnot so\ngood",

                           "Very\ndoubtful"} ;



TFT_ILI9163C display = TFT_ILI9163C(__CS, __DC, __RST);



float p = 3.1415926;

int nIndex = 0;



void setup(void) {

  // pinMode() 

  display.begin();

  display.setBitrate(16000000); // 16MHz clock: UNO (24000000 Teensy)



  uint16_t time = millis();

  time = millis() - time;



  display.clearScreen();

}



void loop() {

    randomSeed(analogRead(0));

    nIndex = random(0, 19) ;

    display.clearScreen();

    display.setCursor(0, 45);

    if (nIndex < 10) {

      display.setTextColor(GREEN, BLACK);

      } else if (nIndex < 15) {

        display.setTextColor(YELLOW, BLACK);

      } else {

        display.setTextColor(MAGENTA, BLACK);

      }

    display.setTextSize(2);

    display.print(Spirits[nIndex]);

    delay(10000) ;  // 10 seconds



  // testlines(random(0x0010,0xFFFF));

  // randomLines();

  randomCircles(1);

  // randomCircles(0);

  // randomRect(1);

  // randomRect(1);

  // randomRect(1);

  // randomRect(1);

  // randomRect(1);

  // randomRect(0);

  // randomRect(0);

  // randomRect(0);

  // randomRect(0);

  // randomRect(0);

  // randomRect(0);

  // randomPoints();

}



void testlines(uint16_t color) {

  display.clearScreen();

  for (int16_t x=0; x < display.width()-1; x+=6) {

    display.drawLine(0, 0, x, display.height()-1, color);

  }

  for (int16_t y=0; y < display.height()-1; y+=6) {

    display.drawLine(0, 0, display.width()-1, y, color);

  }

  display.clearScreen();

  for (int16_t x=0; x < display.width()-1; x+=6) {

    display.drawLine(display.width()-1, 0, x, display.height()-1, color);

  }

  for (int16_t y=0; y < display.height()-1; y+=6) {

    display.drawLine(display.width()-1, 0, 0, y, color);

  }



  display.clearScreen();

  for (int16_t x=0; x < display.width()-1; x+=6) {

    display.drawLine(0, display.height()-1, x, 0, color);

  }

  for (int16_t y=0; y < display.height()-1; y+=6) {

    display.drawLine(0, display.height()-1, display.width()-1, y, color);

  }

  display.clearScreen();

  for (int16_t x=0; x < display.width()-1; x+=6) {

    display.drawLine(display.width()-1, display.height()-1, x, 0, color);

  }

  for (int16_t y=0; y < display.height()-1; y+=6) {

    display.drawLine(display.width()-1, display.height()-1, 0, y, color);

  }

  delay(500);

}





void testdrawtext(char *text, uint16_t color) {

  display.setTextSize(1);

  display.setTextColor(WHITE);

  display.setCursor(0,0);



  for (uint8_t i=0; i < 168; i++) {

    if (i == '\n') continue;

    display.write(i);

    if ((i > 0) && (i % 21 == 0))

      display.println();

  }    

}



void testfastlines(uint16_t color1, uint16_t color2) {

  display.clearScreen();

  for (int16_t y=0; y < display.height()-1; y+=5) {

    display.drawFastHLine(0, y, display.width()-1, color1);

  }

  for (int16_t x=0; x < display.width()-1; x+=5) {

    display.drawFastVLine(x, 0, display.height()-1, color2);

  }

}



void testdrawrects(uint16_t color) {

  display.clearScreen();

  for (int16_t x=0; x < display.height()-1; x+=6) {

    display.drawRect((display.width()-1)/2 -x/2, (display.height()-1)/2 -x/2 , x, x, color);

  }

}



void testfillrects(uint16_t color1, uint16_t color2) {

  display.clearScreen();

  for (int16_t x=display.height()-1; x > 6; x-=6) {

    display.fillRect((display.width()-1)/2 -x/2, (display.height()-1)/2 -x/2 , x, x, color1);

    display.drawRect((display.width()-1)/2 -x/2, (display.height()-1)/2 -x/2 , x, x, color2);

  }

}



void testfillcircles(uint8_t radius, uint16_t color) {

  for (uint8_t x=radius; x < display.width()-1; x+=radius*2) {

    for (uint8_t y=radius; y < display.height()-1; y+=radius*2) {

      display.fillCircle(x, y, radius, color);

    }

  }  

}



void testdrawcircles(uint8_t radius, uint16_t color) {

  for (int16_t x=0; x < (display.width()-1)+radius; x+=radius*2) {

    for (int16_t y=0; y < (display.height())-1+radius; y+=radius*2) {

      display.drawCircle(x, y, radius, color);

    }

  }  

}



void testtriangles() {

  display.clearScreen();

  int color = 0xF800;

  int t;

  int w = display.width()/2;

  int x = display.height();

  int y = 0;

  int z = display.width();

  for(t = 0 ; t <= 15; t+=1) {

    display.drawTriangle(w, y, y, x, z, x, color);

    x-=4;

    y+=4;

    z-=4;

    color+=100;

  }

}



void testroundrects() {

  display.clearScreen();

  int color = 100;

  int i;

  int t;

  for(t = 0 ; t <= 4; t+=1) {

    int x = 0;

    int y = 0;

    int w = display.width();

    int h = display.height();

    for(i = 0 ; i <= 24; i+=1) {

      display.drawRoundRect(x, y, w, h, 5, color);

      x+=2;

      y+=3;

      w-=4;

      h-=6;

      color+=1100;

    }

    color+=100;

  }

}



void tftPrintTest() {

  display.clearScreen();

  display.setCursor(0, 5);

  display.setTextColor(RED);  

  display.setTextSize(1);

  display.println("Hello World!");

  display.setTextColor(YELLOW, GREEN);

  display.setTextSize(2);

  display.print("Hello Wo");

  display.setTextColor(BLUE);

  display.setTextSize(3);

  display.print(12.57);

  delay(1500);

  display.setCursor(0, 5);

  display.clearScreen();

  display.setTextColor(WHITE);

  display.setTextSize(0);

  display.println("Hello World!");

  display.setTextSize(1);

  display.setTextColor(GREEN);

  display.print(p, 5);

  display.println(" Want pi?");

  display.print(8675309, HEX); 

  display.print(" Print HEX");

  display.setTextColor(WHITE);

  display.println("Sketch has been");

  display.println("running for: ");

  display.setTextColor(MAGENTA);

  display.print(millis() / 1000);

  display.setTextColor(WHITE);

  display.print(" sec.");

}





void randomRect(bool fill){

  display.clearScreen();

  uint8_t k,c;

  for (k = 0; k < 16; k++) {

    for (c = 0; c < 32; c++) {

      uint8_t cx, cy, x, y, w, h;

      //  center

      cx = random(0,display.width());

      cy = random(0,display.height());

      //  size

      w = random(0,30 + 6);

      h = random(0,20 + 4);

      //  upper-left

      x = cx - w / 2;

      y = cy - h / 2;

      if (x < 0) x = 0;

      if (y < 0) y = 0;

      //  adjust size

      if (x + w > display.width()) w = display.width() - x;

      if (y + h > display.height()) h = display.height() - y;

      if (fill){

        display.fillRect(x, y, w, h,random(0x0010,0xFFFF));

      } 

      else {

        display.drawRect(x, y, w, h,random(0x0010,0xFFFF));

      }



    }

    display.clearScreen();

  }

}



void randomCircles(bool fill){

  display.clearScreen();

  uint8_t k,c;

  for (k = 0; k < display.height(); k++) {

    for (c = 0; c < display.height()/2; c++) {

      //  coordinates

      uint8_t x = random(0,120 + 3), y = random(0,90 + 2), r = random(0,40 + 1);

      if (x - r <  0) r = x;

      if (x + r > (display.width()-1)) r = (display.width() - 1) - x;

      if (y - r <  0) r = y;

      if (y + r > (display.height()-1)) r = (display.height() - 1) - y;

      if (fill){

        display.fillCircle(x, y, r,random(0x0010,0xFFFF));

      } 

      else {

        display.drawCircle(x, y, r,random(0x0010,0xFFFF));

      }

    }

    if (!fill)display.clearScreen();

  }

}





void randomLines(){

  display.clearScreen();

  uint8_t k,c;

  for (k = 0; k < display.height(); k++) {

    for (c = 0; c < display.height()/2; c++) {

      uint8_t x1 = random(0,display.width()), y1 = random(0,display.height()), x2 = random(0,display.width()), y2 = random(0,display.height());

      display.drawLine(x1, y1, x2, y2,random(0x0010,0xFFFF));

    }

    display.clearScreen();

  }

}





void randomPoints(){

  display.clearScreen();

  int k,c;

  for (k = 0; k < 128; k++) {

    for (c = 0; c < 1000; c++) {

      uint8_t x = random(0,display.width()), y = random(0,display.height());

      display.drawPixel(x, y,random(0x0010,0xFFFF));

    }

    display.clearScreen();

  }

}
Source Code
ILI9163 Datasheet


Code

file_3556.txtPlain text
SPI Connection notes
/*

GLCD                     Signal           Arduino 328P

J2#                        Name           Pin / Signal

1 . . . . . . . . . . . .  Vcc . . . . .  Pin#27 on Nano

2 . . . . . . . . . . . .  GND . . . . .  Pin#29 on Nano

3 . . . . . . . . . . . .   CS . . . . .  D10

4 . . . . . . . . . . . .  Reset . . . .  D12

5 . . . . . . . . . . . .  DC(A0). . . .   D9

6 . . . . . . . . . . . .  MOSI(SDA) . .  D11

7 . . . . . . . . . . . .  SCLK(SCK) . .  D13

8 . . . . . . . . . . . .  LED Backlight  3.3 Vcc (Verify 10 Ohm on display)



Note: This example sketch and wiring REQUIRES that the Nano be run at 3.3V maximum

*/
file_3557.txtPlain text
Ray's Notes
/*

   Hardware Library for 128x128 GLCD: https://github.com/sumotoy/TFT_ILI9163C

   Author/Ref: http://forum.pjrc.com/threads/25862-ILI9163C-128x128-TFT-driver

   

   Adafruit (Ladyada) Graphic core: https://github.com/adafruit/Adafruit-GFX-Library

   

   GLCD source: http://www.ebay.com/itm/310876068105



   YouTube of testing: http://youtu.be/RLDTBaXMmX4 



http://en.wikipedia.org/wiki/Magic_8-Ball

Magic 8 Ball...

The 20 answers inside a Magic 8 Ball are:



G  It is certain

G  It is decidedly so

G  Without a doubt

G  Yes definitely

G  You may rely on it

G  As I see it, yes

G  Most likely

G  Outlook good

G  Yes

G  Signs point to yes

Y  Reply hazy try again

Y  Ask again later

Y  Better not tell you now

Y  Cannot predict now

Y  Concentrate and ask again

R  Don't count on it

R  My reply is no

R  My sources say no

R  Outlook not so good

R  Very doubtful

Ten of the possible answers are Positive(G), five are Negative (R), and five are Neutral(Y).
file_3558.txtPlain text
Arduino Source
/* Binary sketch size: 9,598 bytes (of a 30,720 byte maximum)

   Compiled and tested on Arduino (clone) Nano

// 20140814 using 1.0.5r2 */



#include <SPI.h>

#include <Adafruit_GFX.h>

#include <TFT_ILI9163C.h>



// Connecct all 5 connections to LCD for hardware SPI

#define __DC   9

#define __CS  10

// MOSI(SDA) D11

#define __RST 12

// SCLK(SCK) D13



// Color definitions

#define	BLACK           0x0000

#define	BLUE            0x001F

#define	RED             0xF800

#define	GREEN           0x07E0

#define CYAN            0x07FF

#define MAGENTA         0xF81F

#define YELLOW          0xFFE0  

#define WHITE           0xFFFF

#define TRANSPARENT     -1



char* PROGMEM Spirits[] = {"It is\ncertain",      // Green

                           "It is\ndecidedly\nso",

                           "Without a\ndoubt",

                           "Yes\ndefinitely",

                           "You may\nrely on it",

                           "As I see\nit, yes",

                           "Most\nlikely",

                           "Outlook\ngood",

                           "Yes",

                           "Signs\npoint\nto yes", // end of Green. Begin Yellow

                           "Reply hazy\ntry again",

                           "Ask again\nlater",

                           "Better nottell you\nnow",

                           "Cannot\npredict\nnow",  // end of Yellow. Begin Red

                           "Reflect\nand ask\nagain",

                           "Don't\ncount on\nit",

                           "My reply\nis no",

                           "My sourcessay no",

                           "Outlook\nnot so\ngood",

                           "Very\ndoubtful"} ;



TFT_ILI9163C display = TFT_ILI9163C(__CS, __DC, __RST);



float p = 3.1415926;

int nIndex = 0;



void setup(void) {

  // pinMode() 

  display.begin();

  display.setBitrate(16000000); // 16MHz clock: UNO (24000000 Teensy)



  uint16_t time = millis();

  time = millis() - time;



  display.clearScreen();

}



void loop() {

    randomSeed(analogRead(0));

    nIndex = random(0, 19) ;

    display.clearScreen();

    display.setCursor(0, 45);

    if (nIndex < 10) {

      display.setTextColor(GREEN, BLACK);

      } else if (nIndex < 15) {

        display.setTextColor(YELLOW, BLACK);

      } else {

        display.setTextColor(MAGENTA, BLACK);

      }

    display.setTextSize(2);

    display.print(Spirits[nIndex]);

    delay(10000) ;  // 10 seconds



  // testlines(random(0x0010,0xFFFF));

  // randomLines();

  randomCircles(1);

  // randomCircles(0);

  // randomRect(1);

  // randomRect(1);

  // randomRect(1);

  // randomRect(1);

  // randomRect(1);

  // randomRect(0);

  // randomRect(0);

  // randomRect(0);

  // randomRect(0);

  // randomRect(0);

  // randomRect(0);

  // randomPoints();

}



void testlines(uint16_t color) {

  display.clearScreen();

  for (int16_t x=0; x < display.width()-1; x+=6) {

    display.drawLine(0, 0, x, display.height()-1, color);

  }

  for (int16_t y=0; y < display.height()-1; y+=6) {

    display.drawLine(0, 0, display.width()-1, y, color);

  }

  display.clearScreen();

  for (int16_t x=0; x < display.width()-1; x+=6) {

    display.drawLine(display.width()-1, 0, x, display.height()-1, color);

  }

  for (int16_t y=0; y < display.height()-1; y+=6) {

    display.drawLine(display.width()-1, 0, 0, y, color);

  }



  display.clearScreen();

  for (int16_t x=0; x < display.width()-1; x+=6) {

    display.drawLine(0, display.height()-1, x, 0, color);

  }

  for (int16_t y=0; y < display.height()-1; y+=6) {

    display.drawLine(0, display.height()-1, display.width()-1, y, color);

  }

  display.clearScreen();

  for (int16_t x=0; x < display.width()-1; x+=6) {

    display.drawLine(display.width()-1, display.height()-1, x, 0, color);

  }

  for (int16_t y=0; y < display.height()-1; y+=6) {

    display.drawLine(display.width()-1, display.height()-1, 0, y, color);

  }

  delay(500);

}





void testdrawtext(char *text, uint16_t color) {

  display.setTextSize(1);

  display.setTextColor(WHITE);

  display.setCursor(0,0);



  for (uint8_t i=0; i < 168; i++) {

    if (i == '\n') continue;

    display.write(i);

    if ((i > 0) && (i % 21 == 0))

      display.println();

  }    

}



void testfastlines(uint16_t color1, uint16_t color2) {

  display.clearScreen();

  for (int16_t y=0; y < display.height()-1; y+=5) {

    display.drawFastHLine(0, y, display.width()-1, color1);

  }

  for (int16_t x=0; x < display.width()-1; x+=5) {

    display.drawFastVLine(x, 0, display.height()-1, color2);

  }

}



void testdrawrects(uint16_t color) {

  display.clearScreen();

  for (int16_t x=0; x < display.height()-1; x+=6) {

    display.drawRect((display.width()-1)/2 -x/2, (display.height()-1)/2 -x/2 , x, x, color);

  }

}



void testfillrects(uint16_t color1, uint16_t color2) {

  display.clearScreen();

  for (int16_t x=display.height()-1; x > 6; x-=6) {

    display.fillRect((display.width()-1)/2 -x/2, (display.height()-1)/2 -x/2 , x, x, color1);

    display.drawRect((display.width()-1)/2 -x/2, (display.height()-1)/2 -x/2 , x, x, color2);

  }

}



void testfillcircles(uint8_t radius, uint16_t color) {

  for (uint8_t x=radius; x < display.width()-1; x+=radius*2) {

    for (uint8_t y=radius; y < display.height()-1; y+=radius*2) {

      display.fillCircle(x, y, radius, color);

    }

  }  

}



void testdrawcircles(uint8_t radius, uint16_t color) {

  for (int16_t x=0; x < (display.width()-1)+radius; x+=radius*2) {

    for (int16_t y=0; y < (display.height())-1+radius; y+=radius*2) {

      display.drawCircle(x, y, radius, color);

    }

  }  

}



void testtriangles() {

  display.clearScreen();

  int color = 0xF800;

  int t;

  int w = display.width()/2;

  int x = display.height();

  int y = 0;

  int z = display.width();

  for(t = 0 ; t <= 15; t+=1) {

    display.drawTriangle(w, y, y, x, z, x, color);

    x-=4;

    y+=4;

    z-=4;

    color+=100;

  }

}



void testroundrects() {

  display.clearScreen();

  int color = 100;

  int i;

  int t;

  for(t = 0 ; t <= 4; t+=1) {

    int x = 0;

    int y = 0;

    int w = display.width();

    int h = display.height();

    for(i = 0 ; i <= 24; i+=1) {

      display.drawRoundRect(x, y, w, h, 5, color);

      x+=2;

      y+=3;

      w-=4;

      h-=6;

      color+=1100;

    }

    color+=100;

  }

}



void tftPrintTest() {

  display.clearScreen();

  display.setCursor(0, 5);

  display.setTextColor(RED);  

  display.setTextSize(1);

  display.println("Hello World!");

  display.setTextColor(YELLOW, GREEN);

  display.setTextSize(2);

  display.print("Hello Wo");

  display.setTextColor(BLUE);

  display.setTextSize(3);

  display.print(12.57);

  delay(1500);

  display.setCursor(0, 5);

  display.clearScreen();

  display.setTextColor(WHITE);

  display.setTextSize(0);

  display.println("Hello World!");

  display.setTextSize(1);

  display.setTextColor(GREEN);

  display.print(p, 5);

  display.println(" Want pi?");

  display.print(8675309, HEX); 

  display.print(" Print HEX");

  display.setTextColor(WHITE);

  display.println("Sketch has been");

  display.println("running for: ");

  display.setTextColor(MAGENTA);

  display.print(millis() / 1000);

  display.setTextColor(WHITE);

  display.print(" sec.");

}





void randomRect(bool fill){

  display.clearScreen();

  uint8_t k,c;

  for (k = 0; k < 16; k++) {

    for (c = 0; c < 32; c++) {

      uint8_t cx, cy, x, y, w, h;

      //  center

      cx = random(0,display.width());

      cy = random(0,display.height());

      //  size

      w = random(0,30 + 6);

      h = random(0,20 + 4);

      //  upper-left

      x = cx - w / 2;

      y = cy - h / 2;

      if (x < 0) x = 0;

      if (y < 0) y = 0;

      //  adjust size

      if (x + w > display.width()) w = display.width() - x;

      if (y + h > display.height()) h = display.height() - y;

      if (fill){

        display.fillRect(x, y, w, h,random(0x0010,0xFFFF));

      } 

      else {

        display.drawRect(x, y, w, h,random(0x0010,0xFFFF));

      }



    }

    display.clearScreen();

  }

}



void randomCircles(bool fill){

  display.clearScreen();

  uint8_t k,c;

  for (k = 0; k < display.height(); k++) {

    for (c = 0; c < display.height()/2; c++) {

      //  coordinates

      uint8_t x = random(0,120 + 3), y = random(0,90 + 2), r = random(0,40 + 1);

      if (x - r <  0) r = x;

      if (x + r > (display.width()-1)) r = (display.width() - 1) - x;

      if (y - r <  0) r = y;

      if (y + r > (display.height()-1)) r = (display.height() - 1) - y;

      if (fill){

        display.fillCircle(x, y, r,random(0x0010,0xFFFF));

      } 

      else {

        display.drawCircle(x, y, r,random(0x0010,0xFFFF));

      }

    }

    if (!fill)display.clearScreen();

  }

}





void randomLines(){

  display.clearScreen();

  uint8_t k,c;

  for (k = 0; k < display.height(); k++) {

    for (c = 0; c < display.height()/2; c++) {

      uint8_t x1 = random(0,display.width()), y1 = random(0,display.height()), x2 = random(0,display.width()), y2 = random(0,display.height());

      display.drawLine(x1, y1, x2, y2,random(0x0010,0xFFFF));

    }

    display.clearScreen();

  }

}





void randomPoints(){

  display.clearScreen();

  int k,c;

  for (k = 0; k < 128; k++) {

    for (c = 0; c < 1000; c++) {

      uint8_t x = random(0,display.width()), y = random(0,display.height());

      display.drawPixel(x, y,random(0x0010,0xFFFF));

    }

    display.clearScreen();

  }

}

Comments

Author

Coffeemath
Ray Burnette
  • 7 projects
  • 461 followers

Additional contributors

  • French artist, 1591-1632: fortune teller detail by Jean Valentin de Boulogne
  • Glcd hardware library for ili9163c controller ic by sumotoy
  • Gfx graphic library by Ladyada

Published on

August 15, 2014
See similar projects
you might like

Similar projects you might like

7 Segment Display

Project tutorial by Danilo Bargen

  • 4,686 views
  • 1 comment
  • 3 respects

HSVClock

Project tutorial by Mark Wilson

  • 3,215 views
  • 6 comments
  • 8 respects

Cloud Costume

Project tutorial by Monica Houston

  • 4,343 views
  • 5 comments
  • 19 respects

Analog Clock using 1Sheeld Graphical LCD

Project tutorial by Ahmed El-Hinidy

  • 2,069 views
  • 0 comments
  • 7 respects

Arduino Lie Detector

Project tutorial by Dante Roumega

  • 42,384 views
  • 31 comments
  • 109 respects

OSEPP LCD and keypad shield

Project tutorial by Joe

  • 38,409 views
  • 26 comments
  • 48 respects
Add projectSign up / Login