I am currently trying to create a question tree via the crystal ball library (part of the restrictions of the assignment).
What I want to do is have users click yes/no buttons to answer the questions which leads them to the next series of questions. (I have google-fu this already, but I still can't get it to work right). I had it working to level B yesterday then I tried to reconfigure the push buttons and ... well ... Here I am.
ex: Basic Greeting --> yes/no prompt --->Yes go to A
A) yes/no prompt ---> if yes go to B if no go to C
B) Yes/ no prompt --> If yes go to D if no return to start
C Yes/no prompt --> if yes go to E if no return to start
D) Yes/ no prompt --> if yes (FINAL MESSAGE 1) if no return to start
E) Yes/ no prompt --> If NO (final message 2) if yes return to start
Here is the basic code I have so far
Attempt 1:
#include <LiquidCrystal.h> //liquid library code
// Required hardware I/O connections
const byte LCD_D7 = 2; // connect D7 of the LCD to 2
const byte LCD_D6 = 3; // connect D6 of the LCD to ~3
const byte LCD_D5 = 4; // connect D5 of the LCD to 4
const byte LCD_D4 = 5; // connect D4 of the LCD to ~5
const byte LCD_E = 11; // connect E of the LCD to ~11
const byte LCD_RS = 12; // connect RS of the LCD to 12
const byte yesPin = 13;
const byte noPin = 8;
// LiquidCrystal(rs, enable, d4, d5, d6, d7)
LiquidCrystal Lcd(LCD_RS, LCD_E, LCD_D4, LCD_D5, LCD_D6, LCD_D7);
// Global constants
const byte LCD_WIDTH = 16;
const byte LCD_HEIGHT = 2;
// Global variables
byte YesPin = 1;
byte prev_pin_val = 0;
byte NoPin = 1;
byte reply = 0;// varies from 0 to 7
byte prev_nopin_val = 0;
void setup() {
// put your setup code here, to run once:
Lcd.begin(LCD_WIDTH, LCD_HEIGHT);
pinMode(yesPin, INPUT);
pinMode(noPin, INPUT);
// intro message
Lcd.setCursor(0, 0);
Lcd.print("Welcome to");
Lcd.setCursor(0, 1);
Lcd.print("Fish Bank");
delay(1000);
Lcd.clear();
Lcd.setCursor(0, 0);
Lcd.print("Do you want");
Lcd.setCursor(0, 1);
Lcd.print("YOUR fish?");
delay(2000);
Lcd.clear();
Lcd.print(" Click Yes or No");
}
void loop() {
YesPin = digitalRead(yesPin);
// put your main code here, to run repeatedly:
if ((yesPin != prev_pin_val) && (YesPin == HIGH)) {
reply = random (0); // goes to case 0
Lcd.clear();
Lcd.setCursor(0, 0);
Lcd.print("Begin");
Lcd.setCursor(0, 1);
Lcd.print ("verification");
Lcd.clear();
delay(500);
Lcd.setCursor (0,1);
switch (reply) {
case 0:
if ((YesPin != reply) && (YesPin == HIGH)){
Lcd.setCursor(0, 0);
Lcd.print("Begin");
Lcd.setCursor(0, 1);
Lcd.print ("verification");
Lcd.clear();
delay(500);
Lcd.setCursor(0,0);
Lcd.print("Are you Human?");
Lcd.setCursor (0, 1);
Lcd.print ("Yes ..... No");
void loop();
if ((YesPin != reply) && (YesPin == HIGH)) {
reply = random (1);
Lcd.clear ();
Lcd.print ("verifying");
delay (2000);
Lcd.setCursor (0, 0);
Lcd.print ("01101000");
Lcd.setCursor (0, 1);
Lcd.print ("01100001");
Lcd.clear();
Lcd.print ("verified");
delay(1100);
Lcd.setCursor(0, 0);
Lcd.print ("Do you wish");
Lcd.setCursor (0, 1);
Lcd.print ("to continue?");
void loop();
switch (reply) {
case 1:
Lcd. setCursor(0, 0);
Lcd.print("Are you a penguin?");
Lcd.setCursor(0, 1);
Lcd.print ("Yes... No");
}
}
break;
}
}
// No value **************************** to be worked on next
}
second revised attempt on my break (this one does not get past the "welcome" portion in the void setup:
#include <LiquidCrystal.h> //liquid library code
// Required hardware I/O connections
const byte LCD_D7 = 2; // connect D7 of the LCD to 2
const byte LCD_D6 = 3; // connect D6 of the LCD to ~3
const byte LCD_D5 = 4; // connect D5 of the LCD to 4
const byte LCD_D4 = 5; // connect D4 of the LCD to ~5
const byte LCD_E = 11; // connect E of the LCD to ~11
const byte LCD_RS = 12; // connect RS of the LCD to 12
const int yesPin = 13; //13 as the yes pin
// LiquidCrystal(rs, enable, d4, d5, d6, d7)
LiquidCrystal Lcd(LCD_RS, LCD_E, LCD_D4, LCD_D5, LCD_D6, LCD_D7);
// Global constants
const byte LCD_WIDTH = 16;
const byte LCD_HEIGHT = 2;
// Global variables
int buttonState = 0;
int staticButton = 0;
void setup() {
Lcd.begin(LCD_WIDTH, LCD_HEIGHT); //start lcd dimensions
pinMode(yesPin, INPUT); //pin for yes input
//begin intro message
Lcd.setCursor(0, 0);
Lcd.print("Welcome to your");
Lcd.setCursor(0, 1);
Lcd.print("fish Bank");
delay(1000);
Lcd.clear();
Lcd.setCursor(0, 0);
Lcd.print("Do you want");
Lcd.setCursor(0, 1);
Lcd.print("YOUR fish?");
delay(2000);
Lcd.clear();
Lcd.print(" Click Yes or No");
}
void loop() {
buttonState == digitalRead(yesPin); //will read off of yesPin
if ((buttonState != staticButton) && (buttonState == HIGH)) { //should read as a button push
Lcd.clear();
Lcd.setCursor(0, 0);
Lcd.print("verification?");
Lcd.setCursor (0, 1);
Lcd.print ("needed");
delay(1000);
Lcd.setCursor(0, 1);
Lcd.print ("Are you Human?");
delay (2000);
Lcd.print ("yes or no?");
Lcd.clear();
if ((buttonState != staticButton) && (buttonState == LOW)) {
Lcd.clear();
Lcd.setCursor (0, 0);
Lcd.print ("verifying");
delay(2000);
Lcd.print ("verified");
Lcd.setCursor (0, 0);
Lcd.print ("Do you use");
Lcd.setCursor (0, 1);
Lcd.print ("fish dip?");
delay (2000);
Lcd.print ("Yes or no?");
Lcd.clear();
attached is the hardware set up (i took out the no button for the time being):
I"ll be trying again after work So I will let you know if I have any breakthroughs myself. Sorry for the novice level questioning!