Alright so everything is working great. I added in command line for 3 buttons to control a point system, and to call the names up. However when my friend and i went in to add a bunch of actors names at a certian point the program started glitching out. For example it seemed like every name i added past this point it would erase a line of my serial print.
Here's the code
#include <EEPROM.h>
#define BUTTON 4
#define rbutton 5
#define bbutton 3
int red_old = 0;
int red_new = 0;
int red_button = 0;
int blue_old = 0;
int blue_new = 0;
int blue_button = 0;
template <class T> int EEPROM_writeAnything(int ee, const T& value)
{
const byte* p = (const byte*)(const void*)&value;
int i;
for (i = 0; i < sizeof(value); i++)
EEPROM.write(ee++, *p++);
return i;
}
template <class T> int EEPROM_readAnything(int ee, T& value)
{
byte* p = (byte*)(void*)&value;
int i;
for (i = 0; i < sizeof(value); i++)
*p++ = EEPROM.read(ee++);
return i;
}
void BetterRandomSeed( void )
{
unsigned long __seed;
EEPROM_readAnything( 0, __seed );
srandom( __seed );
}
long BetterRandom( void )
{
long __seed;
__seed = random();
EEPROM_writeAnything( 0, __seed );
return( __seed );
}
long BetterRandom( long howbig )
{
if ( howbig == 0 )
{
return 0;
}
return( BetterRandom() % howbig );
}
long BetterRandom( long howsmall, long howbig )
{
if ( howsmall >= howbig )
{
return howsmall;
}
long diff = howbig - howsmall;
return( BetterRandom(diff) + howsmall );
}
char *actors[]={
"Brad Pitt",
"Edward Nortan",
"Ashton Kutcher",
"Demi Moore",
"Reese Witherspoon",
"Will Smith",
"Johnny Depp",
"Tom Hanks",
"George Clooney",
"Will Ferrell",
"Nicolas Cage",
"Leonardo DiCaprio",
"Russell Crowe",
"Tom Cruise",
"Jim Carrey",
"Chris Pine",
"Nicole Kidman",
"Jude Law",
"Julia Roberts",
"Kiefer Sutherland",
"Will Arnett",
"Michael C. Hall",
"Danny Devito",
"Pierce Brosnan",
"Daniel Craig",
"Sean Bean",
"Russell Crowe",
"Christian Bale",
"Bruce Willis",
"John Cusack",
"Samuel L. Jackson",
"Zooey Deschanel",
"Joseph Gordon-Levitt",
"Josh Hartnett",
"Steve Carell",
"Mike Myers",
"Dennis Quaid",
"Billy Bob Thornton",
"Brendan Fraser",
"Jason Statham",
"Eddie Murphy",
"Adam Sandler",
"Leonardo Dicaprio",
"Shia Labeouf",
"Matt Damon",
"Ben Affleck",
"Chris Cooper",
"Ryan Phillipe",
"Kristen Bell",
"Kristen Stewart",
"Timothy Olyphant",
"George Clooney",
"Jake Gyllenhaal",
"Clive Owen",
"Jody Foster",
"Matthew Mcconaughey",
"Jamie Foxx",
"Heath Ledger",
"Tina Fey",
"Keanu Reeves",
"Jack Nicholson",
"Mark Wahlberg",
"Justin Long",
"Vince Vaughn",
"Michael Douglas",
"Brittany Murphy",
"Viggo Mortensen",
"Val Kilmer",
"Steve Buscemi",
"William H. Macy",
"channing Tatum",
"Jackie Chan",
"Jet Lee",
"Mila Kunis",
"Jason Segel",
"Russell Brand",
"Jonah Hill",
"Casey Affleck",
"Morgan Freeman",
"Clint Eastwood",
"Simon Pegg",
"Andy Sandberg",
"isla Fisher",
"Harrison Ford",
"Jeff Goldblum",
"Eli Roth",
"Colin Farrell",
"Ralph Fiennes",
"Tommy Lee Jones",
"Ewan McGregor",
"Scarlett Johansson",
"Robert Downey jr",
"Terrence Howard",
"Jeff Bridges",
"Don Cheadle",
"Hayden Christensen",
"Michael Cera",
"Ellen Page",
"Michael J. Fox",
"Christopher Lloyd",
"Amy Smart",
"Anna Faris",
"Keira Knightley",
"Jennifer Garner",
"Orlando Bloom",
"Naomi Watts",
"Jack Black",
"Mel Gibson",
};
long actor1;
long actor2;
int val = 0;
void setup()
{
Serial.begin( 9600 );
BetterRandomSeed();
Serial.println( "Six Degrees of Seperation" );
}
void loop()
{
val = digitalRead(BUTTON);
if (val == HIGH)
{
actor1 = BetterRandom(sizeof(actors)/sizeof(char*));
do
{
actor2 = BetterRandom(sizeof(actors)/sizeof(char*));
}
while ( actor2 == actor1 );
Serial.println();
Serial.println(actors[actor1]);
Serial.println();
Serial.println(actors[actor2]);
Serial.println("______________________");
delay(1000);
Serial.println();
Serial.println("Who Won?");
Serial.println();
delay(500);
Serial.println("Red");
Serial.println(red_old);
Serial.println("Blue");
Serial.println(blue_old);
Serial.println("_______________");
delay( 500 );
}
red_button = digitalRead(rbutton);
if (red_button == HIGH)
{
Serial.println("Red");
red_new = (red_old + 1);
Serial.println(red_new);
red_old = (red_new);
Serial.println("Blue");
Serial.println(blue_old);
delay(500);
}
blue_button = digitalRead(bbutton);
if (blue_button == HIGH)
{
Serial.println("Red");
Serial.println(red_old);
Serial.println("Blue");
blue_new = (blue_old + 1);
Serial.println(blue_new);
blue_old = (blue_new);
delay(500);
}
}
So if i add any more names after Mel Gibson that's when things start getting weird. Perhaps there is a limit on how many names i can use or perhaps some other crazy weird thing.
Any help would like always be super appreciated.