Hello All,
I'm working on a project that needs a long list of variables that can be spat out in random configurations on a thermal printer. I have a working prototype using a small thermal printer and an arduino uno rev3. My challenge now is that the flash memory is so small, I max out the number of variables rather quickly.
I could really use suggestions on how best to expand this flash memory. I've found write-ups on PROGMEM options, but I don't fully understand if I can call on them randomly, or how best to approach expanding memory. I'm open to all suggestions, changing boards, adding shields if need be or some more advanced coding (I am rather new to this). I'll include the code for what I have so far.
#include <EEPROM.h>
#include <Thermal.h>
#include <avr/pgmspace.h>
#include "Adafruit_Thermal.h"
#include "SoftwareSerial.h"
#define BUTTON 13
#define TX_PIN 6 // Arduino transmit YELLOW WIRE labeled RX on printer
#define RX_PIN 5 // Arduino receive GREEN WIRE labeled TX on printer
SoftwareSerial mySerial(RX_PIN, TX_PIN); // Declare SoftwareSerial obj first
Adafruit_Thermal printer(&mySerial); // Pass addr to printer constructor
bool running = false;
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 *ideas[] ={
"Abstraction",
"Aestheticism",
"Aesthetics",
"Affect",
"Anthropocentrism",
"Art Brut",
"Art Deco",
"Art Nouveau",
"Ashton Kutcher",
"Assemblage",
"Atheism",
"Bauhaus",
"Being in The World",
"Bourgeoisie",
"Bruno Letour",
"Cartesian Dualism",
"Classicism",
"Clowns",
"Collage",
"Colonization",
"Constructivism",
"Consumerism",
"Cubism",
"Cynicism",
"DADA",
"Darkness",
"Deconstructivism",
"Derive",
"Dichotomy",
"Dinosaurs",
"Dionysian",
"Discourse",
"DIY",
"Earth",
"Emancipation",
"Empiricism",
"Excessivism",
"Existentialism",
"Feminism",
"Fetishism",
"Flatness",
"Flowers",
"Fluxus",
"Foucault",
"Futurism",
"Geese",
"Gender",
"George Orwell",
"Graffiti",
"Hate",
"Hermeneutics",
"Humanism",
"Hypermodernism",
"Idiocy",
"Jaques Derrida",
"Kafka",
"Kinetic",
"Kitsch",
"Kittens",
"Land Works",
"Linguistic Anthropology",
"Logical Positivism",
"Love",
"Lowbrow",
"Lunacy",
"Materialism",
"Metaphysics",
"Minimalism",
"Misanthropy",
"Modernism",
"Modernism",
"Modular Constructivism",
"Naiveté",
"Nazis",
"Nearness",
"Nihilism",
"Nudes",
"Object Oriented Ontology",
"Objectivism",
"Oil",
"Ontology",
"Ontology",
"Orientalism",
"Paint",
"Pessimism",
"Phenomenology",
"Photorealism",
"Plastic",
"Platonic Realism",
"Post-Impressionism",
"Postmodernism",
"Primitivism",
"Primitivism",
"Proletariat",
"Punk Rock",
"Realism",
"Realism",
"Religion",
"Rhizomes",
"Rocks",
"Rococo",
"Russia",
"Simplicity",
"Socialist Realism",
};
long ideas1;
long ideas2;
long ideas3;
int val = 0;
int run;
String stringOne = "The Intersection of " ;
String stringTwo = ", ";
String stringThree = " & ";
String stringFour = ".";
void setup()
{
BetterRandomSeed();
pinMode(BUTTON, INPUT);
mySerial.begin(19200); // Initialize SoftwareSerial
printer.begin(); // Init printer (same regardless of serial type)
run = 0;
delay(500);
}
void loop()
{
if(digitalRead(BUTTON) == HIGH) //funcitons based off of button pulling input pin LOW
{
ideas1 = BetterRandom(sizeof(ideas)/sizeof(char*));
do
{
ideas2 = BetterRandom(sizeof(ideas)/sizeof(char*));
ideas3 = BetterRandom(sizeof(ideas)/sizeof(char*));
}
while ( ideas2 == ideas1 == ideas2 == ideas3 == ideas1);
printer.justify('L');
printer.underlineOn();
printer.println("Your Future Thesis Will Be:");
printer.underlineOff();
printer.feed(2);
printer.println(stringOne + ideas[ideas1] +stringTwo + ideas[ideas2] + stringThree + ideas[ideas3] + stringFour);
printer.feed(4);
}
}
Thank you so much for any and all suggestions.