Home ArduinoArduino Tutorials Arduino and LCD4484 – random character location

Arduino and LCD4484 – random character location

Another example using the LCD 4484s shield, this time I wanted a character on the display in a random location. This example allows us to look at generating random numbers. The first part in the stup() is important as this explains setting a random seed, in the example below we simply display a character at a random location on the display.

Code

#include “LCD4884.h”

void setup()
{
//initialise and clear
Serial.begin(9600);
// if analog input pin 0 is unconnected, random analog
// noise will cause the call to randomSeed() to generate
// different seed numbers each time the sketch runs.
// randomSeed() will then shuffle the random function.
randomSeed(analogRead(0));
lcd.LCD_init();
lcd.LCD_clear();
}

void loop()
{
long randomX, randomY;
//random number between 0 and 84
randomX = random(0,84);
//random number between 0 and 4
randomY = random(0,4);
//clear the LCD
lcd.LCD_clear();
//pause for 1 second
delay(1000);
//move to LCD position
lcd.LCD_set_XY(randomX,randomY);
//write a character to LCD
lcd.LCD_prop_write_char(‘a’, MENU_NORMAL);
//1 second delay
delay(1000);
}

 

 

Links

Download Link

Amazon US link – SainSmart Graphic LCD4884 Shield for Arduino

Amazon UK link – ATmega2560 + Graphic LCD4884 Shield for Arduino

You may also like