Help needed for making a LCD roulette.

Hi forum!

I'm having some trouble finding a way to make a roulette on an LCD. The thing i need help with is a way to get a code that will make it cycle through some fields on the LCD display and making it slow down and in the end stop at one field.

If there is need for more information, just ask!

Thanks in advance. -Cisrer

Some details would be useful, like which display you're using, some of the code you've written...

Hi!

I'm using a LCM1602 IIC display.

i havn't written any code as of yet and the thing i need to get going is some code that will make it slow down and stop at one point, the thing i have done so far with the display is making a dice on it and make it say what you rolled, and then added another dice to it and making it so it also is adding them. I intend to use that code from them to get the random number out of it for the roulette.

-Cister

That's not a graphical LCD, is it? How do you plan displaying the wheel?

The thing i need help with is a way to get a code that will make it cycle through some fields on the LCD display and making it slow down and in the end stop at one field.

Pronouns, like it, are useless unless they clearly refer to some noun. None of your its refer to anything. With requirements like this, it's no wonder you can't write the code to implement them.

Would you like to try again?

The way i plan to make the wheel is i want to use the last 60 fields as the "wheel" so i have 60 numbers it can choose between and then on the top line it will say the number it landed on. I want to make the other 60 fields to have "O" in them and then make it look like it is cycleing through it all by replacing it with a "X" when it get to that field, and then change it back to and "O" when it changes to the next field.

-Cister

OK, for now, I'd forget about the slowing down part, and just concentrate on getting the display to look like you want.

For that part i will be using my code from the dices i have made with it and here is the code for it:

/*-----( Import needed libraries )-----*/ 
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>  // F Malpartida's NewLiquidCrystal library
//Download: https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads
// Move original LiquidCrystal library elsewhere, copy this in it's place

/*-----( Declare Constants )-----*/
#define I2C_ADDR    0x27  // Define I2C Address for the PCF8574T 
//---(Following are the PCF8574 pin assignments to LCD connections )----
// This are different than earlier/different I2C LCD displays
#define BACKLIGHT_PIN  3
#define En_pin  2
#define Rw_pin  1
#define Rs_pin  0
#define D4_pin  4
#define D5_pin  5
#define D6_pin  6
#define D7_pin  7

#define  LED_OFF  1
#define  LED_ON  0
const int buttonPin = 2;
   int buttonState = 0;
LiquidCrystal_I2C  lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
// Project 15 - Creating an Electronic Die
void setup()
{
   Serial.begin(9600);

  
  lcd.begin (20,4);  // initialize the lcd 
// Switch on the backlight
  lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
  lcd.setBacklight(LED_ON);

randomSeed(analogRead(0)); // seed the random number generator
for ( int z = 1 ; z < 7 ; z++ ) // LEDs on pins 1-6 are output
{
pinMode(z, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
}
}


void loop()
{
int ok = 0;



    buttonState = digitalRead(buttonPin);
    while (buttonState == HIGH) {
    buttonState = digitalRead(buttonPin);
    Serial.println(buttonState);
    ok = 1;
    delay (50);
  }
  
  if (ok == 1) { 
   
  int rr;  
  int r;
  r = random(1, 7); // get a random number from 1 to 6
  rr = random(1, 7);
 
    
// Print our characters on the LCD
  lcd.backlight();  //Backlight ON if under program control
  lcd.setCursor(1,0); //Start at character 4 on line 0
  lcd.print("You rolled:");
  lcd.print(r);
  lcd.print ("+");
  lcd.print(rr);
  lcd.print ("=");
  lcd.print(r+rr);
  lcd.print("  ");
  
  switch (r) {
    case 1:
    lcd.setCursor(4,1);
    lcd.print("   ");
    lcd.setCursor(4,2);
    lcd.print(" o ");
    lcd.setCursor(4,3);
    lcd.print("   ");
      break;
      case 2:
    lcd.setCursor(4,1);
    lcd.print("  o");
    lcd.setCursor(4,2);
    lcd.print("   ");
    lcd.setCursor(4,3);
    lcd.print("o  ");
      break;
      case 3:
  lcd.setCursor(4,1);
  lcd.print("  o");
  lcd.setCursor(4,2);
  lcd.print(" o ");
  lcd.setCursor(4,3);
  lcd.print("o  ");
     break;
     case 4:
  lcd.setCursor(4,1);
  lcd.print("o o");
  lcd.setCursor(4,2);
  lcd.print("   ");
  lcd.setCursor(4,3);
  lcd.print("o o");
  break;
  case 5:
  lcd.setCursor(4,1);
  lcd.print("o o");
  lcd.setCursor(4,2);
  lcd.print(" o ");
  lcd.setCursor(4,3);
  lcd.print("o o");
  break;
  case 6:
  lcd.setCursor(4,1);
  lcd.print("o o");
  lcd.setCursor(4,2);
  lcd.print("o o");
  lcd.setCursor(4,3);
  lcd.print("o o");
  break;
  }
  switch (rr) {
    case 1:
    lcd.setCursor(13,1);
    lcd.print("   ");
    lcd.setCursor(13,2);
    lcd.print(" o ");
    lcd.setCursor(13,3);
    lcd.print("   ");
      break;
      case 2:
    lcd.setCursor(13,1);
    lcd.print("  o");
    lcd.setCursor(13,2);
    lcd.print("   ");
    lcd.setCursor(13,3);
    lcd.print("o  ");
      break;
      case 3:
  lcd.setCursor(13,1);
  lcd.print("  o");
  lcd.setCursor(13,2);
  lcd.print(" o ");
  lcd.setCursor(13,3);
  lcd.print("o  ");
     break;
     case 4:
  lcd.setCursor(13,1);
  lcd.print("o o");
  lcd.setCursor(13,2);
  lcd.print("   ");
  lcd.setCursor(13,3);
  lcd.print("o o");
  break;
  case 5:
  lcd.setCursor(13,1);
  lcd.print("o o");
  lcd.setCursor(13,2);
  lcd.print(" o ");
  lcd.setCursor(13,3);
  lcd.print("o o");
  break;
  case 6:
  lcd.setCursor(13,1);
  lcd.print("o o");
  lcd.setCursor(13,2);
  lcd.print("o o");
  lcd.setCursor(13,3);
  lcd.print("o o");
  break;
  }
 }
}

I will take some from it and put it in the new one and just change the “lcd.print()” to match it with what i wrote earlier.

-Cister

Slightly OT, but have you noticed that

  case 1:
    lcd.setCursor(4,1);
    lcd.print("   ");
    lcd.setCursor(4,2);
    lcd.print(" o ");
    lcd.setCursor(4,3);
    lcd.print("   ");
      break;

looks an awful lot like

    case 1:
    lcd.setCursor(13,1);
    lcd.print("   ");
    lcd.setCursor(13,2);
    lcd.print(" o ");
    lcd.setCursor(13,3);
    lcd.print("   ");
      break;

?

Yes i have and it's supossed to do so, since there are two dices and i make it display what the dice rolled

Yes i have

So why did you write the same code twice?

I wrote the same code to make it display two dices and it is a project here at my school that i have been assigned to.

-Cister

But you could have written the code just once with a very simple change:

void displayDie (byte column, byte val)
{
  switch (val) 
  {
    case 1:
      lcd.setCursor(column,1);
      lcd.print("   ");
      lcd.setCursor(column,2);
      lcd.print(" o ");
      lcd.setCursor(column,3);
      lcd.print("   ");
    break;

etc.

I didn't know i that code there (I'm new at this)

And thanks for that i will use that in the future!

But what can i do to make a code that will do the "slow down" effect?

-Cister

Use a variable to store the number of milliseconds you want to delay between each display. Then increase the value of that variable a little bit each time you display.

Would you be able to give an example?

-Cister

const int MAX_DELAY = 500; // longest time to show any die side, tweak to suit

byte rollDie(const byte column)
{
int displayDelay = 0; // how long to initially display each side
byte delayInc = 1; // rate of slowdown, tweak to suit
byte value = 1; // temporary holder for die side, this should actually be randomized

while(displayDelay < MAX_DELAY)
  {
  displayDie(column, value);
  delay(displayDelay);
  value++; // next die side
  if(value > 6) // only six sides to a die
    { value = 1; }
  displayDelay += delayInc; // slow down next roll
  delayInc += 1; // increase the rate of slowdown, tweak to suit
  }

return value;
}