# m5stack EuroMillions APP help

Hello.

I'm desenvolving an APP for EuroMillions Lottery in my m5stack and I have some troubles with it and I hope someone will help me. I sort n times a number between 1 and 50 (the Euromillions Lottery range of numbers). Every time a number is sorted, an array with 50 elements is incremented at the number sorted position. If 5 is sorted, then MatrixNumber[5]=MatrixNumber[5]+1. After n times I will seek the MatrixNumber[] and search for the biggest number there and the corresponding position where I found it and save the position in another array (FinalNumber[]). After that I zeroe the position so that it only be only one maximum values for all the array. (are you lost? I hope not). After all is done I get an array with 5 numbers (the most sorted by function "random(50)+1". I do the ssame stuff for the "Stars" part of the sorting. Problem ONE: I can't SORT the array from lesser to bigger. I've done everything and it just don't sort. Problem TWO: In "option" I use a number that can be "-2" to "+2". That number will be added the the "sorted number" comparing his value. For example, variable "Option1" value will be added if a number is sorted between 1 and 6 and "Option2" value will be added to numkber sorted if the number is between 7 and 12, ... and so on (1..6,7..12,13..18,... are the lines on the lottery form). If I change the number to any row (row 1 to 8) beside value "00", the sorting is giving me almost always the same numbers. If I put the rows to position value of "00" then it's random again. Very weird. I copied the source code in pastebin because it's kind of big and I want to share the code anyway (but not with weird stuff on it).

``````https://pastebin.com/LBpKVPcv
``````

Can anyone help?

(deleted)

Oki

``````#include <M5Stack.h>
#include <EEPROM.h>

int FinalNumber[51];
int FinalStar[13];
int MatrixNumber[51];
int MatrixStar[13];
int TempV;
int TempM;
int TempN;
int TempP;
int NumberPos;
int Temp;
int Loopi;
int i,j;
int IndexPos;
int oldBatteryLevel=1000;
int newBatteryLevel=0;
signed char Option1=1;
signed char Option2=1;
signed char Option3=1;
signed char Option4=1;
signed char Option5=1;
signed char Option6=1;
signed char Option7=1;
signed char Option8=1;
int ExitMe=0;
int NTemp1,NTemp2;

void swapInt(int a, int b)
{
int c = a;
a = b;
b = c;
}

{
if (Option1==1) Option1=-2;  if (Option1==2) Option1=-1;  if (Option1==3) Option1=0; if (Option1==4) Option1=1; if (Option1==5) Option1=2;
if (Option2==1) Option2=-2;  if (Option2==2) Option2=-1;  if (Option2==3) Option2=0; if (Option2==4) Option2=1; if (Option2==5) Option2=2;
if (Option3==1) Option3=-2;  if (Option3==2) Option3=-1;  if (Option3==3) Option3=0; if (Option3==4) Option3=1; if (Option3==5) Option3=2;
if (Option4==1) Option4=-2;  if (Option4==2) Option4=-1;  if (Option4==3) Option4=0; if (Option4==4) Option4=1; if (Option4==5) Option4=2;
if (Option5==1) Option5=-2;  if (Option5==2) Option5=-1;  if (Option5==3) Option5=0; if (Option5==4) Option5=1; if (Option5==5) Option5=2;
if (Option6==1) Option6=-2;  if (Option6==2) Option6=-1;  if (Option6==3) Option6=0; if (Option6==4) Option6=1; if (Option6==5) Option6=2;
if (Option7==1) Option7=-2;  if (Option7==2) Option7=-1;  if (Option7==3) Option7=0; if (Option7==4) Option7=1; if (Option7==5) Option7=2;
if (Option8==1) Option8=-2;  if (Option8==2) Option8=-1;  if (Option8==3) Option8=0; if (Option8==4) Option8=1; if (Option8==5) Option8=2;
}

void WriteEprom()
{
if (Option1==-2) EEPROM.write(0, 1); if (Option1==-1) EEPROM.write(0, 2); if (Option1==0) EEPROM.write(0, 3); if (Option1==1) EEPROM.write(0, 4); if (Option1==2) EEPROM.write(0, 5);
if (Option2==-2) EEPROM.write(1, 1); if (Option2==-1) EEPROM.write(1, 2); if (Option2==0) EEPROM.write(1, 3); if (Option2==1) EEPROM.write(1, 4); if (Option2==2) EEPROM.write(1, 5);
if (Option3==-2) EEPROM.write(2, 1); if (Option3==-1) EEPROM.write(2, 2); if (Option3==0) EEPROM.write(2, 3); if (Option3==1) EEPROM.write(2, 4); if (Option3==2) EEPROM.write(2, 5);
if (Option4==-2) EEPROM.write(3, 1); if (Option4==-1) EEPROM.write(3, 2); if (Option4==0) EEPROM.write(3, 3); if (Option4==1) EEPROM.write(3, 4); if (Option4==2) EEPROM.write(3, 5);
if (Option5==-2) EEPROM.write(4, 1); if (Option5==-1) EEPROM.write(4, 2); if (Option5==0) EEPROM.write(4, 3); if (Option5==1) EEPROM.write(4, 4); if (Option5==2) EEPROM.write(4, 5);
if (Option6==-2) EEPROM.write(5, 1); if (Option6==-1) EEPROM.write(5, 2); if (Option6==0) EEPROM.write(5, 3); if (Option6==1) EEPROM.write(5, 4); if (Option6==2) EEPROM.write(5, 5);
if (Option7==-2) EEPROM.write(6, 1); if (Option7==-1) EEPROM.write(6, 2); if (Option7==0) EEPROM.write(6, 3); if (Option7==1) EEPROM.write(6, 4); if (Option7==2) EEPROM.write(6, 5);
if (Option8==-2) EEPROM.write(7, 1); if (Option8==-1) EEPROM.write(7, 2); if (Option8==0) EEPROM.write(7, 3); if (Option8==1) EEPROM.write(7, 4); if (Option8==2) EEPROM.write(7, 5);
EEPROM.commit();
}

void ClearEprom()
{
EEPROM.write(0, 0);
EEPROM.write(1, 0);
EEPROM.write(2, 0);
EEPROM.write(3, 0);
EEPROM.write(4, 0);
EEPROM.write(5, 0);
EEPROM.write(6, 0);
EEPROM.write(7, 0);
}

int8_t getBatteryLevel()
{
Wire.beginTransmission(0x75);
Wire.write(0x78);
if (Wire.endTransmission(false) == 0
&& Wire.requestFrom(0x75, 1)) {
case 0xE0: return 25;
case 0xC0: return 50;
case 0x80: return 75;
case 0x00: return 100;
default: return 0;
}
}
return -1;
}

void displayBattery()
{
// Draw Battery
oldBatteryLevel=1000;
M5.Lcd.drawRect(295, 4, 5, 7, WHITE);
M5.Lcd.drawRect(300, 0, 20, 14, WHITE);
}

void displayLogo()
{
M5.Lcd.setTextColor(YELLOW);
M5.Lcd.setTextFont(1);
M5.Lcd.setTextSize(1);
M5.Lcd.setCursor( 0, 20);   M5.Lcd.print(" __           __  __   _   _   _                     ");
M5.Lcd.setCursor( 0, 30);   M5.Lcd.print("|__|    _  _ |  \\/  | (_) | | | |_    ___   ___   ___");
M5.Lcd.setCursor( 0, 40);   M5.Lcd.print("|_| | ||_|| || |\\/| | | | | | | | \\  / _ \\ / -_) (_-<");
M5.Lcd.setCursor( 0, 50);   M5.Lcd.print("|__||_||\\ |_||_|  |_| |_| |_| |_||_| \\___/ \\___| /__/");
}

void displayBatteryLevel()
{
newBatteryLevel=getBatteryLevel();
// M5.Lcd.setTextColor(YELLOW);
// M5.Lcd.setTextFont(1);
// M5.Lcd.setTextSize(2);
// M5.Lcd.setCursor( 0, 0);   M5.Lcd.print("   ");
// M5.Lcd.setCursor( 0, 0);   M5.Lcd.print(getBatteryLevel());

if (oldBatteryLevel!=newBatteryLevel)
{
M5.Lcd.fillRect(303, 2, 12, 11, BLACK);
M5.Lcd.drawRect(300, 0, 20, 14, WHITE);
if (newBatteryLevel>=100) M5.Lcd.fillRect(303, 2, 3, 11, GREEN);
if (newBatteryLevel>=75)  M5.Lcd.fillRect(307, 2, 3, 11, GREEN);
if (newBatteryLevel>=50)  M5.Lcd.fillRect(310, 2, 3, 11, GREEN);
if (newBatteryLevel>=25)  M5.Lcd.fillRect(313, 2, 4, 11, GREEN);
oldBatteryLevel=newBatteryLevel;
}
}

void getEuroMillionsNumbers()
{
M5.update();
M5.Lcd.setTextColor(WHITE);
M5.Lcd.setTextFont(2);
M5.Lcd.setTextSize(3);
M5.Lcd.fillRect(0, 80, 320, 100, BLACK);
delay(500);

for (int i=1;i<=50; i++) MatrixNumber[i]=1;
for (int k=1; k<25000; k++)
{
NTemp1=random(50)+1;
if (NTemp1>=1 && NTemp1<=6)
{
NTemp2=NTemp1+Option1;
if (NTemp2==-1) NTemp2=49;
if (NTemp2==0)  NTemp2=50;
}
if (NTemp1>=13 && NTemp1<=18) NTemp2=NTemp1+Option3;
if (NTemp1>=19 && NTemp1<=24) NTemp2=NTemp1+Option4;
if (NTemp1>=25 && NTemp1<=30) NTemp2=NTemp1+Option5;
if (NTemp1>=31 && NTemp1<=36) NTemp2=NTemp1+Option6;
if (NTemp1>=37 && NTemp1<=42) NTemp2=NTemp1+Option7;
if (NTemp1>=43 && NTemp1<=48) NTemp2=NTemp1+Option8;
if (NTemp1>=49 && NTemp1<=50) NTemp2=NTemp1;
MatrixNumber[NTemp2]++;
}

NumberPos=1;
while (NumberPos<=5)
{
TempN=0;
TempP=1;
for (i=1; i<=50; i++)
{
if (MatrixNumber[i]>TempN) { TempN=MatrixNumber[i]; TempP=i; }
}
if (TempN==0) TempP=1;
for (i=1; i<=50; i++)
{
if (MatrixNumber[i]==TempN) MatrixNumber[i]=0;
}
FinalNumber[NumberPos]=TempP;
NumberPos++;
}

for (i=1; i<=4; i++)
{
for (j=2; j<=5; j++)  if (FinalNumber[i]>FinalNumber[j]) swapInt(FinalNumber[i],FinalNumber[j]);
}

for (int i=1;i<=12; i++) MatrixStar[i]=1;
for (int k=1; k<10000; k++)
{
MatrixStar[random(12)+1]++;
}
TempV=0;  TempM=0;
for (IndexPos=1; IndexPos<=2; IndexPos++)
{
for (Loopi=1; Loopi<=12; Loopi++)
{
if (MatrixStar[Loopi]>TempV) { TempV=MatrixStar[Loopi]; TempM=Loopi;  }
}
FinalStar[IndexPos]=TempM;
MatrixStar[TempM]=0;
TempV=0;
}

if (FinalStar[1]>FinalStar[2]) swapInt(FinalStar[1],FinalStar[2]);

M5.Lcd.setTextColor(WHITE);
M5.Lcd.setTextFont(2);
M5.Lcd.setTextSize(3);
M5.Lcd.setCursor(  0, 80);   M5.Lcd.print(String(FinalNumber[1]));
M5.Lcd.setCursor( 64, 80);   M5.Lcd.print(String(FinalNumber[2]));
M5.Lcd.setCursor(128, 80);   M5.Lcd.print(String(FinalNumber[3]));
M5.Lcd.setCursor(192, 80);   M5.Lcd.print(String(FinalNumber[4]));
M5.Lcd.setCursor(256, 80);   M5.Lcd.print(String(FinalNumber[5]));

M5.Lcd.setCursor(  0, 130);   M5.Lcd.print(String(FinalStar[1]));
M5.Lcd.setCursor( 64, 130);   M5.Lcd.print(String(FinalStar[2]));

M5.Lcd.setTextColor(GREEN);
M5.Lcd.setTextFont(1);
M5.Lcd.setTextSize(2);

M5.Lcd.fillRect(   0, 210, 320, 30, BLUE);
M5.Lcd.drawRect(   0, 210, 105, 30, WHITE);
M5.Lcd.setCursor(  0+2+(14*(7/2)),217);  M5.Lcd.print("?");
M5.Lcd.drawRect( 106, 210, 105, 30, WHITE);
M5.Lcd.setCursor(106+2+(14*(7/6)),217);  M5.Lcd.print("Options");
M5.Lcd.drawRect( 212, 210, 105, 30, WHITE);
M5.Lcd.setCursor(212+2+(14*(7/3)),217);  M5.Lcd.print("Sort");
exit;
}
``````

That’s my code part 1/4. (because it exeeds 9000 chars)

Hello

``````void clsEuroMillionsOptions()
{
M5.Lcd.setTextColor(BLACK);
M5.Lcd.setCursor(  1*(13*0)-1,  40);   M5.Lcd.print(">");  M5.Lcd.setCursor(  1*(13*4)-1,  40);  M5.Lcd.print("<");
M5.Lcd.setCursor(  1*(13*0)-1,  60);   M5.Lcd.print(">");  M5.Lcd.setCursor(  1*(13*4)-1,  60);  M5.Lcd.print("<");
M5.Lcd.setCursor(  1*(13*0)-1,  80);   M5.Lcd.print(">");  M5.Lcd.setCursor(  1*(13*4)-1,  80);  M5.Lcd.print("<");
M5.Lcd.setCursor(  1*(13*0)-1, 100);   M5.Lcd.print(">");  M5.Lcd.setCursor(  1*(13*4)-1, 100);  M5.Lcd.print("<");
M5.Lcd.setCursor(  1*(13*0)-1, 120);   M5.Lcd.print(">");  M5.Lcd.setCursor(  1*(13*4)-1, 120);  M5.Lcd.print("<");
M5.Lcd.setCursor(  1*(13*0)-1, 140);   M5.Lcd.print(">");  M5.Lcd.setCursor(  1*(13*4)-1, 140);  M5.Lcd.print("<");
M5.Lcd.setCursor(  1*(13*0)-1, 160);   M5.Lcd.print(">");  M5.Lcd.setCursor(  1*(13*4)-1, 160);  M5.Lcd.print("<");
M5.Lcd.setCursor(  1*(13*0)-1, 180);   M5.Lcd.print(">");  M5.Lcd.setCursor(  1*(13*4)-1, 180);  M5.Lcd.print("<");
M5.Lcd.setCursor(  1*(13*6)-1,  40);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*8)-1,  40);  M5.Lcd.print("]");
M5.Lcd.setCursor(  1*(13*10)-4, 40);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*12)-3, 40);  M5.Lcd.print("]");
M5.Lcd.setCursor(  1*(13*14)-10,40);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*16)-9, 40);  M5.Lcd.print("]");
M5.Lcd.setCursor(  1*(13*18)-11,40);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*20)-12,40);  M5.Lcd.print("]");
M5.Lcd.setCursor(  1*(13*22)-16,40);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*24)-14,40);  M5.Lcd.print("]");
M5.Lcd.setCursor(  1*(13*6)-1,  60);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*8)-1,  60);  M5.Lcd.print("]");
M5.Lcd.setCursor(  1*(13*10)-4, 60);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*12)-3, 60);  M5.Lcd.print("]");
M5.Lcd.setCursor(  1*(13*14)-10,60);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*16)-9, 60);  M5.Lcd.print("]");
M5.Lcd.setCursor(  1*(13*18)-11,60);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*20)-12,60);  M5.Lcd.print("]");
M5.Lcd.setCursor(  1*(13*22)-16,60);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*24)-14,60);  M5.Lcd.print("]");
M5.Lcd.setCursor(  1*(13*6)-1,  80);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*8)-1,  80);  M5.Lcd.print("]");
M5.Lcd.setCursor(  1*(13*10)-4, 80);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*12)-3, 80);  M5.Lcd.print("]");
M5.Lcd.setCursor(  1*(13*14)-10,80);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*16)-9, 80);  M5.Lcd.print("]");
M5.Lcd.setCursor(  1*(13*18)-11,80);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*20)-12,80);  M5.Lcd.print("]");
M5.Lcd.setCursor(  1*(13*22)-16,80);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*24)-14,80);  M5.Lcd.print("]");
M5.Lcd.setCursor(  1*(13*6)-1,  100);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*8)-1,  100);  M5.Lcd.print("]");
M5.Lcd.setCursor(  1*(13*10)-4, 100);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*12)-3, 100);  M5.Lcd.print("]");
M5.Lcd.setCursor(  1*(13*14)-10,100);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*16)-9, 100);  M5.Lcd.print("]");
M5.Lcd.setCursor(  1*(13*18)-11,100);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*20)-12,100);  M5.Lcd.print("]");
M5.Lcd.setCursor(  1*(13*22)-16,100);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*24)-14,100);  M5.Lcd.print("]");
M5.Lcd.setCursor(  1*(13*6)-1,  120);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*8)-1,  120);  M5.Lcd.print("]");
M5.Lcd.setCursor(  1*(13*10)-4, 120);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*12)-3, 120);  M5.Lcd.print("]");
M5.Lcd.setCursor(  1*(13*14)-10,120);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*16)-9, 120);  M5.Lcd.print("]");
M5.Lcd.setCursor(  1*(13*18)-11,120);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*20)-12,120);  M5.Lcd.print("]");
M5.Lcd.setCursor(  1*(13*22)-16,120);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*24)-14,120);  M5.Lcd.print("]");
M5.Lcd.setCursor(  1*(13*6)-1,  140);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*8)-1,  140);  M5.Lcd.print("]");
M5.Lcd.setCursor(  1*(13*10)-4, 140);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*12)-3, 140);  M5.Lcd.print("]");
M5.Lcd.setCursor(  1*(13*14)-10,140);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*16)-9, 140);  M5.Lcd.print("]");
M5.Lcd.setCursor(  1*(13*18)-11,140);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*20)-12,140);  M5.Lcd.print("]");
M5.Lcd.setCursor(  1*(13*22)-16,140);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*24)-14,140);  M5.Lcd.print("]");
M5.Lcd.setCursor(  1*(13*6)-1,  160);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*8)-1,  160);  M5.Lcd.print("]");
M5.Lcd.setCursor(  1*(13*10)-4, 160);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*12)-3, 160);  M5.Lcd.print("]");
M5.Lcd.setCursor(  1*(13*14)-10,160);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*16)-9, 160);  M5.Lcd.print("]");
M5.Lcd.setCursor(  1*(13*18)-11,160);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*20)-12,160);  M5.Lcd.print("]");
M5.Lcd.setCursor(  1*(13*22)-16,160);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*24)-14,160);  M5.Lcd.print("]");
M5.Lcd.setCursor(  1*(13*6)-1,  180);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*8)-1,  180);  M5.Lcd.print("]");
M5.Lcd.setCursor(  1*(13*10)-4, 180);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*12)-3, 180);  M5.Lcd.print("]");
M5.Lcd.setCursor(  1*(13*14)-10,180);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*16)-9, 180);  M5.Lcd.print("]");
M5.Lcd.setCursor(  1*(13*18)-11,180);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*20)-12,180);  M5.Lcd.print("]");
M5.Lcd.setCursor(  1*(13*22)-16,180);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*24)-14,180);  M5.Lcd.print("]");
}

void drawEuroMillionsOptions()
{
M5.Lcd.setTextColor(YELLOW);
M5.Lcd.setTextFont(1);
M5.Lcd.setTextSize(3);
M5.Lcd.setCursor(  0,  0);   M5.Lcd.print(" > O P T I O N < ");
M5.Lcd.setTextColor(WHITE);
M5.Lcd.setTextFont(1);
M5.Lcd.setTextSize(2);
M5.Lcd.setCursor(  0,  40);   M5.Lcd.print("  1    -2  -1  00  +1  +2");
M5.Lcd.setCursor(  0,  60);   M5.Lcd.print("  2    -2  -1  00  +1  +2");
M5.Lcd.setCursor(  0,  80);   M5.Lcd.print("  3    -2  -1  00  +1  +2");
M5.Lcd.setCursor(  0, 100);   M5.Lcd.print("  4    -2  -1  00  +1  +2");
M5.Lcd.setCursor(  0, 120);   M5.Lcd.print("  5    -2  -1  00  +1  +2");
M5.Lcd.setCursor(  0, 140);   M5.Lcd.print("  6    -2  -1  00  +1  +2");
M5.Lcd.setCursor(  0, 160);   M5.Lcd.print("  7    -2  -1  00  +1  +2");
M5.Lcd.setCursor(  0, 180);   M5.Lcd.print("  8    -2  -1  00  +1  +2");
displayBattery();
displayBatteryLevel();
}
``````

That’s my code 2/4

Thank you

Hello

``````void redrawEuroMillionsOptions()
{
clsEuroMillionsOptions();
M5.Lcd.setTextColor(YELLOW);
if (Option1==-2) { M5.Lcd.setCursor(  1*(13*6)-1,  40);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*8)-1,  40);  M5.Lcd.print("]"); }
if (Option1==-1) { M5.Lcd.setCursor(  1*(13*10)-4, 40);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*12)-3, 40);  M5.Lcd.print("]"); }
if (Option1==0) { M5.Lcd.setCursor(  1*(13*14)-10,40);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*16)-9, 40);  M5.Lcd.print("]"); }
if (Option1==1) { M5.Lcd.setCursor(  1*(13*18)-11,40);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*20)-12,40);  M5.Lcd.print("]"); }
if (Option1==2) { M5.Lcd.setCursor(  1*(13*22)-16,40);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*24)-14,40);  M5.Lcd.print("]"); }
if (Option2==-2) { M5.Lcd.setCursor(  1*(13*6)-1,  60);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*8)-1,  60);  M5.Lcd.print("]"); }
if (Option2==-1) { M5.Lcd.setCursor(  1*(13*10)-4, 60);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*12)-3, 60);  M5.Lcd.print("]"); }
if (Option2==0) { M5.Lcd.setCursor(  1*(13*14)-10,60);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*16)-9, 60);  M5.Lcd.print("]"); }
if (Option2==1) { M5.Lcd.setCursor(  1*(13*18)-11,60);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*20)-12,60);  M5.Lcd.print("]"); }
if (Option2==2) { M5.Lcd.setCursor(  1*(13*22)-16,60);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*24)-14,60);  M5.Lcd.print("]"); }
if (Option3==-2) { M5.Lcd.setCursor(  1*(13*6)-1,  80);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*8)-1,  80);  M5.Lcd.print("]"); }
if (Option3==-1) { M5.Lcd.setCursor(  1*(13*10)-4, 80);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*12)-3, 80);  M5.Lcd.print("]"); }
if (Option3==0) { M5.Lcd.setCursor(  1*(13*14)-10,80);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*16)-9, 80);  M5.Lcd.print("]"); }
if (Option3==1) { M5.Lcd.setCursor(  1*(13*18)-11,80);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*20)-12,80);  M5.Lcd.print("]"); }
if (Option3==2) { M5.Lcd.setCursor(  1*(13*22)-16,80);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*24)-14,80);  M5.Lcd.print("]"); }
if (Option4==-2) { M5.Lcd.setCursor(  1*(13*6)-1,  100);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*8)-1,  100);  M5.Lcd.print("]"); }
if (Option4==-1) { M5.Lcd.setCursor(  1*(13*10)-4, 100);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*12)-3, 100);  M5.Lcd.print("]"); }
if (Option4==0) { M5.Lcd.setCursor(  1*(13*14)-10,100);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*16)-9, 100);  M5.Lcd.print("]"); }
if (Option4==1) { M5.Lcd.setCursor(  1*(13*18)-11,100);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*20)-12,100);  M5.Lcd.print("]"); }
if (Option4==2) { M5.Lcd.setCursor(  1*(13*22)-16,100);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*24)-14,100);  M5.Lcd.print("]"); }
if (Option5==-2) { M5.Lcd.setCursor(  1*(13*6)-1,  120);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*8)-1,  120);  M5.Lcd.print("]"); }
if (Option5==-1) { M5.Lcd.setCursor(  1*(13*10)-4, 120);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*12)-3, 120);  M5.Lcd.print("]"); }
if (Option5==0) { M5.Lcd.setCursor(  1*(13*14)-10,120);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*16)-9, 120);  M5.Lcd.print("]"); }
if (Option5==1) { M5.Lcd.setCursor(  1*(13*18)-11,120);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*20)-12,120);  M5.Lcd.print("]"); }
if (Option5==2) { M5.Lcd.setCursor(  1*(13*22)-16,120);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*24)-14,120);  M5.Lcd.print("]"); }
if (Option6==-2) { M5.Lcd.setCursor(  1*(13*6)-1,  140);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*8)-1,  140);  M5.Lcd.print("]"); }
if (Option6==-1) { M5.Lcd.setCursor(  1*(13*10)-4, 140);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*12)-3, 140);  M5.Lcd.print("]"); }
if (Option6==0) { M5.Lcd.setCursor(  1*(13*14)-10,140);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*16)-9, 140);  M5.Lcd.print("]"); }
if (Option6==1) { M5.Lcd.setCursor(  1*(13*18)-11,140);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*20)-12,140);  M5.Lcd.print("]"); }
if (Option6==2) { M5.Lcd.setCursor(  1*(13*22)-16,140);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*24)-14,140);  M5.Lcd.print("]"); }
if (Option7==-2) { M5.Lcd.setCursor(  1*(13*6)-1,  160);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*8)-1,  160);  M5.Lcd.print("]"); }
if (Option7==-1) { M5.Lcd.setCursor(  1*(13*10)-4, 160);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*12)-3, 160);  M5.Lcd.print("]"); }
if (Option7==0) { M5.Lcd.setCursor(  1*(13*14)-10,160);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*16)-9, 160);  M5.Lcd.print("]"); }
if (Option7==1) { M5.Lcd.setCursor(  1*(13*18)-11,160);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*20)-12,160);  M5.Lcd.print("]"); }
if (Option7==2) { M5.Lcd.setCursor(  1*(13*22)-16,160);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*24)-14,160);  M5.Lcd.print("]"); }
if (Option8==-2) { M5.Lcd.setCursor(  1*(13*6)-1,  180);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*8)-1,  180);  M5.Lcd.print("]"); }
if (Option8==-1) { M5.Lcd.setCursor(  1*(13*10)-4, 180);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*12)-3, 180);  M5.Lcd.print("]"); }
if (Option8==0) { M5.Lcd.setCursor(  1*(13*14)-10,180);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*16)-9, 180);  M5.Lcd.print("]"); }
if (Option8==1) { M5.Lcd.setCursor(  1*(13*18)-11,180);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*20)-12,180);  M5.Lcd.print("]"); }
if (Option8==2) { M5.Lcd.setCursor(  1*(13*22)-16,180);  M5.Lcd.print("[");  M5.Lcd.setCursor(  1*(13*24)-14,180);  M5.Lcd.print("]"); }
M5.Lcd.setTextColor(GREEN);
M5.Lcd.setTextFont(1);
M5.Lcd.setTextSize(2);
if (IndexPos<9)
{
M5.Lcd.fillRect(   0, 210, 320, 30, BLUE);
M5.Lcd.drawRect(   0, 210, 105, 30, WHITE);
M5.Lcd.fillTriangle(0+5+(13*(5)), 220, 0+5+(13*(3)), 225, 0+5+(13*(5)), 230, GREEN);
M5.Lcd.drawRect( 106, 210, 105, 30, WHITE);
M5.Lcd.fillTriangle(106+5+(13*(3)), 220, 106+5+(13*(4)), 230, 106+5+(13*(5)), 220, GREEN);
M5.Lcd.drawRect( 212, 210, 105, 30, WHITE);
M5.Lcd.fillTriangle(212+5+(13*(3)), 220, 212+5+(13*(5)), 225, 212+5+(13*(3)), 230, GREEN);
}
``````

That’s my code 3/4

Thank you

Hello

`````` if (MenuLine==9)
{
M5.Lcd.fillRect(   0, 210, 320, 30, BLUE);
M5.Lcd.drawRect(   0, 210, 105, 30, WHITE);
M5.Lcd.setCursor(  0+5+(13*(3)),217);  M5.Lcd.print(" ");
M5.Lcd.drawRect( 106, 210, 105, 30, WHITE);
//  M5.Lcd.setCursor(106+5+(13*(3)),217);  M5.Lcd.print("V");
M5.Lcd.fillTriangle(106+5+(13*(3)), 220, 106+5+(13*(4)), 230, 106+5+(13*(5)), 220, GREEN);
M5.Lcd.drawRect( 212, 210, 105, 30, WHITE);
M5.Lcd.setCursor(212+5+(13*(2)),217);  M5.Lcd.print("Exit");
}
displayBatteryLevel();
}

void getEuroMillionsOptions()
{
while(1)
{
if (M5.BtnB.wasPressed())
{
redrawEuroMillionsOptions();
}
{
if (MenuLine==1) Option1--; if (Option1==-3) Option1=-2;
if (MenuLine==2) Option2--; if (Option2==-3) Option2=-2;
if (MenuLine==3) Option3--; if (Option3==-3) Option3=-2;
if (MenuLine==4) Option4--; if (Option4==-3) Option4=-2;
if (MenuLine==5) Option5--; if (Option5==-3) Option5=-2;
if (MenuLine==6) Option6--; if (Option6==-3) Option6=-2;
if (MenuLine==7) Option7--; if (Option7==-3) Option7=-2;
if (MenuLine==8) Option8--; if (Option8==-3) Option8=-2;
redrawEuroMillionsOptions();
}

{
if (MenuLine==1) Option1++; if (Option1==3) Option1=2;
if (MenuLine==2) Option2++; if (Option2==3) Option2=2;
if (MenuLine==3) Option3++; if (Option3==3) Option3=2;
if (MenuLine==4) Option4++; if (Option4==3) Option4=2;
if (MenuLine==5) Option5++; if (Option5==3) Option5=2;
if (MenuLine==6) Option6++; if (Option6==3) Option6=2;
if (MenuLine==7) Option7++; if (Option7==3) Option7=2;
if (MenuLine==8) Option8++; if (Option8==3) Option8=2;
redrawEuroMillionsOptions();
}

{
redrawEuroMillionsOptions();
}

{
WriteEprom();
M5.Lcd.fillRect(   0, 0, 320, 240, BLACK);
displayBattery();
displayBatteryLevel();
displayLogo();
getEuroMillionsNumbers();
delay(100);
break;
}
displayBatteryLevel();
M5.update();
}
}

void setup()
{
M5.begin();
Wire.begin();
EEPROM.begin(16);
//ClearEprom(); // Use this the first time program is uploaded for initial Eprom values.
delay(100);
displayBattery();
displayBatteryLevel();
displayLogo();
getEuroMillionsNumbers();
}

void loop()
{

if (M5.BtnC.wasPressed())
{
M5.Lcd.fillRect(   0, 0, 320, 240, BLACK);
displayBattery();
displayBatteryLevel();
displayLogo();
getEuroMillionsNumbers();
delay(100);
}

if (M5.BtnB.wasPressed())
{
M5.Lcd.fillRect(   0, 0, 320, 240, BLACK);
displayBattery();
displayBatteryLevel();
drawEuroMillionsOptions();
redrawEuroMillionsOptions();
getEuroMillionsOptions();
delay(100);
}
displayBatteryLevel();
M5.update();
}
``````

That’s my code 4/4

I hope someone will help because the anomalies are weird.
At least can anyone explain WHY the program do such weird things?
Thank you

(deleted)

Hello.

The code is not optimized. I had it more optimized with Select Case intead of lots of IFs and some variable indexing but I was getting errors from the m5stack. I've done the same kind of stuff in Arduino UNO and all worked fine. Have you looked at the "bubble sort"? I can't make it work with m5stack. I always used Bubble Sort when needed in a lot of languages and it's the first time I see that weird anomaly! The simple -> "if a>b then swap a,b" is not working. I tried with a sub, I tried without a sub, all the same. WEIRD. I don't think that you can immagine the weirdness of the stuff UNLESS you own a m5stack and put this source code on it. ANYWAY... I like ANY comment that can make me evolve and be a better programmer or at least a logic thinker. Thanks spycatcher2k . I hope you will spot the weird behavior of the code or spot logic errors on the code.