A good while ago, I made The Little Box of Poems. This is a box that prints a random poem every time you push a big red button. Inside is an Arduino microcontroller and a thermal till roll printer, and it inspired Carrie Ann Philbin’s Little Box of Geek. (I also made a Raspberry Pi-powered version too.)
As it’s Christmas, I’ve decided to make a seasonal version. This one prints really bad, random Christmas cracker jokes:
Here’s how to wire it up:
And here’s the Arduino code – it’s based on the Poem code, so the variables have rather odd names. If you want to find out how to add bitmap graphics, like my Christmas tree, Adafruit have a guide here. I used Photoshop and Processing to make mine.
/* Little Box of Christmas by Giles Booth http://www.suppertime.co.uk/blogmywiki @blogmywiki not for commercial use if you modify this code for edcuational or charitable use please credit Giles Booth and/or @blogmywiki in printouts */ const int buttonPin = 2; // the number of the pushbutton pin - doesn't change int currState = 0; // set variables to hold the state of the button int prevState = 0; #include "SoftwareSerial.h" #include "Adafruit_Thermal.h" // you need to download this and put it in your Arduino library #include "tree.h" // Christmas tree picture #include <avr/pgmspace.h> // I have no idea what this does int buttonState = 0; // variable for reading the button status int printer_RX_Pin = 5; // This is the green printer wire int printer_TX_Pin = 6; // This is the yellow printer wire Adafruit_Thermal printer(printer_RX_Pin, printer_TX_Pin); void setup() { pinMode(buttonPin, INPUT); Serial.begin(19200); // this is the baud rate of your printer - may vary pinMode(7, OUTPUT); digitalWrite(7, LOW); printer.begin(); randomSeed(analogRead(0)); } void loop(){ // read the state of the button: currState = digitalRead(buttonPin); if (currState != prevState) // if something has changed, do something { if (currState == HIGH) { printPoem(); } else { // if you want something to happen when the button is released, put it here // such as a beep, or a display saying 'your poem is on its way' } prevState = currState; } } void printPoem(){ // put greetings here char* myTitles[]={"Merry Christmas!","Happy Christmas!","Season's Greetings!","Joyeux Noel!","feliz navidad!","God jul!"}; // put 1st lines of joke in here // they must all be on the same line, in double quotes, separated by commas // use \n for a new line and \" to escape a quotation mark char* myPoems[]={"What does Santa suffer from\nif he gets stuck in a chimney?", "What kind of motorbike does\nSanta ride?", "Who delivers presents\nto cats?", "What never eats\nat Christmas?", "What's brown and sneaks\nround the kitchen?","What do you get if you eat\nChristmas decorations?"}; // put punchlines here in order char* myAuthors[]={"Claustrophobia!","A Holly Davidson!","Santa Paws!","Turkeys - they're\nusually stuffed!","Mince spies!","Tinselitis!"}; int poemChoice = random(7); // choose a random poem number between 0 and 6 printer.boldOn(); printer.feed(1); printer.println(myPoems[poemChoice]); printer.boldOff(); printer.justify('R'); printer.println(myAuthors[poemChoice]); printer.justify('L'); printer.doubleHeightOn(); printer.println(myTitles[poemChoice]); printer.doubleHeightOff(); printer.printBitmap(tree_width, tree_height, tree_data); // print Blog My Wiki logo printer.boldOn(); printer.println("The Little Box of Christmas"); printer.boldOff(); printer.setSize('S'); // Setting the size adds a linefeed printer.println("www.suppertime.co.uk/blogmywiki"); printer.println("@blogmywiki"); printer.feed(3); delay(2000); // 2 second pause to help prevent multiple presses }