Wednesday, May 28, 2014

Crystal Ball

Step 1: Materials
  • Arduino Uno
  • Breadboard
  • Jumper wires
  • Petentiometer
  • Tilt Switch
  • Crystal Ball Monitor/Sensor
Step 2: Physical Building
  • First I attached the Crystal Ball Monitor to the breadboard and attached it all to ground and power.
  • Then I attached all the appropriate wires to make the sensor turn on.
  • I inserted the tilt switch and the potentiometer to power as well
  • Then I moved on to the code
Step 3: Code

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

const int switchPin = 6;
int switchState = 0;
int prevSwitchState = 0;
int reply;

void setup() {
  lcd.begin(16, 2);
  pinMode(switchPin, INPUT);
  lcd.print("Ask the");
 
  lcd.setCursor(0, 1);
  lcd.print("Crystal Ball!");
}

void loop() {
  switchState = digitalRead(switchPin);
 
  if (switchState != prevSwitchState) {
    if (switchState == LOW) {
      reply = random(8);
     
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("The ball says:");
      lcd.setCursor(0, 1);
     
      switch(reply){
        case 0:
        lcd.print("Yes");
        break;
        case 1:
        lcd.print("Most likely");
        break;
        case 2:
        lcd.print("Hell no");
        break;
        case 3:
        lcd.print("Ask again..");
        break;
        case 4:
        lcd.print("Certainly");
        break;
        case 5:
        lcd.print("Nope");
        break;
        case 6:
        lcd.print("Looks good");
        break;
        case 7:
        lcd.print("Sorry not sorry");
        break;
      }
    }
  }
 
  prevSwitchState = switchState;
}


Reflection

This program frustrated me because I had a hard time understanding what the petentiometer was and what it did. Also I found and error in my code that was causing the screen not to work. This project was a fortune telling device. Kind of like a magic 8-ball, with sassy responses and all. I enjoyed experimenting with the Crystal Ball Sensor.

No comments:

Post a Comment