Hi! I'm modifying the crystal ball code for the Monopoly Chance and Community chest cards. I wanted to add a button so the user can switch between chance or community chest.
I came up with this code, and it compiled. But when I ran it on the arduino, it's stuck on the
"monopoly" screen.
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
//int counter = 1;
//int buttonPin = 13;
// set up a constant for the tilt switchPin
const int switchPin = 6;
// variable to hold the value of the switchPin
int switchState = 0;
// variable to hold previous value of the switchpin
int prevSwitchState = 0;
// a variable to choose which reply from the crystal ball
int reply;
void setup() {
// pinMode(buttonPin, INPUT);
// set up the number of columns and rows on the LCD
lcd.begin(16, 2);
Serial.begin (9600);
// set up the switch pin as an input
pinMode(switchPin, INPUT);
// Print a message to the LCD.
//lcd.print("Ask the");
Serial.print ("MONOPOLY");
// set the cursor to column 0, line 1
// line 1 is the second row, since counting begins with 0
}
void loop() {
//Handle input
digitalRead(buttonPin);
if(buttonPin == HIGH && counter==1)
{
counter=2; // chance
//Reset count if over max mode number
if(counter == 2)
lcd.setCursor (0,0);
Serial.print ("CHANCE");
{
counter = 1; //community chest
lcd.setCursor (0,0);
Serial.print ("COMMUNITY CHEST");
}
}
//Change mode
if(counter == 1) // COMMUNITY CHEST
{
// compare the switchState to its previous state
if (switchState != prevSwitchState) {
// if the state has changed from HIGH to LOW
// you know that the ball has been tilted from
// one direction to the other
if (switchState == LOW) {
// randomly chose a reply
reply = random(11);
// clean up the screen before printing a new reply
lcd.clear();
// set the cursor to column 0, line 0
lcd.setCursor(0, 0);
// print some text
//lcd.print("the ball says:");
// move the cursor to the second
Serial.print ("Shake me");
// choose a saying to print baed on the value in reply
switch (reply) {
case 0:
lcd.setCursor(0,0);
//lcd.print("Yes");
Serial.print ("Pass GO- ");
lcd.setCursor(0,1);
Serial.print ("Collect $200!");
delay (500);
break;
case 1:
lcd.setCursor(0,0);
//lcd.print("Yes");
Serial.print ("Doctor's fees- ");
lcd.setCursor(0,1);
Serial.print ("Pay $50.");
delay(500);
break;
case 2:
lcd.setCursor(0,0);
//lcd.print("Yes");
Serial.print ("Get out of");
lcd.setCursor(0,1);
Serial.print ("Jail Free!");
delay(500);
break;
case 3:
lcd.setCursor(0,0);
//lcd.print("Yes");
Serial.print ("Go directly to");
lcd.setCursor(0,1);
Serial.print ("Jail.");
delay (500);
break;
case 4:
lcd.setCursor(0,0);
//lcd.print("Yes");
Serial.print ("Xmas fund ");
lcd.setCursor(0,1);
Serial.print ("matures. Get $50");
delay(500);
break;
case 5:
lcd.setCursor(0,0);
//lcd.print("Yes");
Serial.print ("It's your Bday!");
lcd.setCursor(0,1);
Serial.print ("Get $50/player.");
delay(500);
break;
case 6:
lcd.setCursor(0,0);
//lcd.print("Yes");
Serial.print ("Pay hospital fee");
lcd.setCursor(0,1);
Serial.print ("of $100..");
delay(500);
break;
case 7:
lcd.setCursor(0,0);
//lcd.print("Yes");
Serial.print ("Receive $25 ");
lcd.setCursor(0,1);
Serial.print ("consultancy fee.");
delay(500);
break;
case 8:
lcd.setCursor(0,0);
//lcd.print("Yes");
Serial.print ("YOU INHERIT");
lcd.setCursor(0,1);
Serial.print ("$100!!");
delay(500);
break;
case 9:
lcd.setCursor(0,0);
//lcd.print("Yes");
Serial.print ("Pay school fees");
lcd.setCursor(0,1);
Serial.print ("of $100.");
delay(500);
break;
case 10:
lcd.setCursor(0,0);
//lcd.print("Yes");
Serial.print ("Your stocks sell");
lcd.setCursor(0,1);
Serial.print ("you get $50.");
delay(500);
break;
}
}
}
// save the current switch state as the last state
prevSwitchState = switchState;
}
//else (counter == 2);// COMMUNITY CHEST
{
// compare the switchState to its previous state
if (switchState != prevSwitchState) {
// if the state has changed from HIGH to LOW
// you know that the ball has been tilted from
// one direction to the other
if (switchState == LOW) {
// randomly chose a reply
reply = random(11);
// clean up the screen before printing a new reply
lcd.clear();
// set the cursor to column 0, line 0
lcd.setCursor(0, 0);
// print some text
//lcd.print("the ball says:");
// move the cursor to the second
Serial.print ("Shake me");
// choose a saying to print baed on the value in reply
switch (reply) {
case 0:
lcd.setCursor(0,0);
//lcd.print("Yes");
Serial.print ("Advance to GO.");
lcd.setCursor(0,1);
Serial.print ("Collect $200");
break;
case 1:
lcd.setCursor(0,0);
//lcd.print("Yes");
Serial.print ("Advance yo ");
lcd.setCursor(0,1);
Serial.print ("Illinois Ave.");
delay(500);
break;
case 2:
lcd.setCursor(0,0);
//lcd.print("Yes");
Serial.print ("Advance to St.");
lcd.setCursor(0,1);
Serial.print ("Charles Place.");
delay(500);
break;
case 3:
lcd.setCursor(0,0);
//lcd.print("Yes");
Serial.print ("Advance to nearest");
lcd.setCursor(0,1);
Serial.print ("utility.");
delay(500);
break;
case 4:
lcd.setCursor(0,0);
//lcd.print("Yes");
Serial.print ("Get out of Jail");
lcd.setCursor(0,1);
Serial.print ("Free!");
delay(500);
break;
case 5:
lcd.setCursor(0,0);
//lcd.print("Yes");
Serial.print ("Go back 3");
lcd.setCursor(0,1);
Serial.print ("spaces.");
delay(500);
break;
case 6:
lcd.setCursor(0,0);
//lcd.print("Yes");
Serial.print ("Pay poor tax of");
lcd.setCursor(0,1);
Serial.print ("$15.");
delay(500);
break;
case 7:
lcd.setCursor(0,0);
//lcd.print("Yes");
Serial.print ("Take a walk on ");
lcd.setCursor(0,1);
Serial.print ("Boardwalk.");
delay(500);
break;
case 8:
lcd.setCursor(0,0);
//lcd.print("Yes");
Serial.print ("Win a contest");
lcd.setCursor(0,1);
Serial.print ("Collect $100!!");
delay(500);
break;
case 9:
lcd.setCursor(0,0);
//lcd.print("Yes");
Serial.print ("Pay each player");
lcd.setCursor(0,1);
Serial.print ("$50.");
delay(500);
break;
case 10:
lcd.setCursor(0,0);
//lcd.print("Yes");
Serial.print ("Bank pays you ");
lcd.setCursor(0,1);
Serial.print ("dividend of $50");
delay(500);
break;
}
}
}
}
// save the current switch state as the last state
prevSwitchState = switchState;
}
Any suggestions? ![]()
Thank you so much for the help guys!