Page 203 - ARM Based Microcontroller Projects Using MBED
P. 203
8.18 PROJECT 15—EURO MILLIONAIRE LOTTERY NUMBERS 189
/*************************************************************************
Euro Millionaire Lottery Numbers
================================
This is a Euro Millionaire Lottery Numbers program. In the Euro Millions
Lottery there are two sections: The Lottery Numbers section and the Lucky
Stars section where the user is required to select numbers from each
section. In this project 5 unique random Lottery Numbers are generated
between 1 and 50 inclusive, and also 2 unique random Lucky Stars numbers
are generated between 1 and 12 inclusive. Clicking the User button
generates a set of numbers for the game and these numbers are displayed
on the PC screen.
Author: Dogan Ibrahim
Date : August 2018
File : Lottery
**************************************************************************/
#include "mbed.h"
Serial MyPC(USBTX, USBRX);
DigitalIn button(BUTTON1); // BUTTON1 is input
int LotteryNumbers[6],LuckyStarNumbers[3];
//
// Clear the screen
//
void clrscr()
{
char clrscr[] = {0x1B, '[', '2' , 'J',0};
MyPC.printf(clrscr);
}
//
// Home the cursor
//
void homescr()
{
char homescr[] = {0x1B, '[' , 'H' , 0};
MyPC.printf(homescr);
}
//
// This function generates the Lottery numbers and the Lucky Star
// numbers. The generated numbers are checked to make sure that
// they are unique (i.e. they ar not same as the ones generated in
// this set), otherwise new number is generated
//
void Generate(int Cnt, int Max_No, int LNumbers [])
{
int i, n, flag, j;
for(j = 1; j <= Cnt; j++)
FIG. 8.52 Program listing.
(Continued)