Chipkit Magic-8 Ball

In this example we will create a Magic 8-ball using an Chipkit Uno and an LCD keypad shield, when one of the buttons is pressed a random message will be displayed.

The Magic 8 Ball is a toy used for fortune-telling or seeking advice, developed in the 1950s and manufactured by Mattel. It is often used in fiction, often for humor related to its giving very accurate, very inaccurate, or otherwise statistically improbable answers.

You can read more about the Magic-8 ball at https://en.wikipedia.org/wiki/Magic_8-Ball

Parts

Chipkit Uno
LCD keypad Shield (mine was made by SainSmart)

Code

[codesyntax lang=”cpp”]

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

String phrases[] = {"It is certain", "Certainly", "Without a doubt", "You may rely on it", "As I see it, yes", "Most likely", "Outlook good", "Yes", "My reply is no", "Very doubtful", "No", "No chance", "No way", "Cannot predictt",
"I doubt it", "Ask again", "Not sure"};
String output;
int numberofphrases = 17;  //match this with the number of phrases
int key  = 0;

void setup() 
{
  // set up the LCD's number of columns and rows:
  randomSeed(analogRead(5)); 
  lcd.begin(16, 2);
  lcd.print("MAGIC 8 BALL");
}

void loop() 
{
  lcd.setCursor(0, 0);
  key = analogRead(0); 
  if(key < 1000)
  {
    lcd.clear();
    output = phrases[random(numberofphrases)]; //Chooses phrase
    lcd.print(output);
  }
  delay(300);
}

[/codesyntax]

 

Links
LCD Board Keypad Shield Blue Backlight for Arduino

Related posts

Chipkit Max32 and ADXL335 accelerometer example

Chipkit Max32 and LSM303 Accelerometer example

Chipkit Max32 and LSM303 Magnetometer example

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Read More