Skip to content

Instantly share code, notes, and snippets.

@uXeBoy
Created July 6, 2019 05:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uXeBoy/ceef27398cd6209b3320601ffa60171e to your computer and use it in GitHub Desktop.
Save uXeBoy/ceef27398cd6209b3320601ffa60171e to your computer and use it in GitHub Desktop.
//**************************************************************//
// Name : T6963C Interactive Adventure //
// Author : Wayne K Jones - www.warmcat.uk //
// Date : 29 Nov 2014 //
// Modified: 21 Oct 2015 //
// Version : 1.0.0 //
// Notes : Using T6963C driven LCD display and 4 buttons for //
// : a simple text based multi-choice adventure game. //
// Licence : Free to use, both in part or it's entirety, //
// However I do ask that you give credit/mention. //
//**************************************************************//
/*
Data : bits 0->7 : digital pins 2->9
Ctrl : WR : analog pin 0
Ctrl : RD : analog pin 1
Ctrl : CE : analog pin 2
Ctrl : CD : analog pin 3
Ctrl : RESET : WAS analog pin 4 but NOW tied to arduino reset
Ctrl : FS : WAS analog pin 5 but NOW tied to 5v
Buttons 1 to 4 : digital pins 10 to 13
*/
// #include <GDt6963c.h>
// #include <MemoryFree.h>
#include <TimerFreeTone.h>
#include "Strings.h"
#include "font8x8_basic.h"
// Global variables
void (*state)() = NULL;
boolean wantCD = 0; // after try to drive
boolean haveCD = 0;
boolean haveFrisbee = 0;
boolean bearHasFrisbee = 0;
boolean haveSteeringWheel = 0;
boolean carSteeringWheel = 0;
boolean haveKeys = 0;
boolean carKeys = 0;
boolean haveWinder = 0;
boolean carWinder = 0;
boolean wantEmptyCan = 0;
boolean haveEmptyCan = 0;
boolean havePetrolCan = 0;
boolean carPetrolCan = 0;
boolean haveMirror = 0;
boolean carMirror = 0;
boolean haveRope = 0;
boolean wantHook = 0; // after tried rope in well
boolean haveHook = 0;
boolean wantMouse = 0; // after met cat
boolean haveMouse = 0;
uint8_t carPartsReq = 5; // how many parts left until complete
/* // Button Stuff
const int buttonPin1 = 10;
const int buttonPin2 = 11;
const int buttonPin3 = 12;
const int buttonPin4 = A5; // USUALLY PIN 13 (doesnt work on MINI so A5)
boolean buttonState1 = 1;
boolean buttonState2 = 1;
boolean buttonState3 = 1;
boolean buttonState4 = 1;
boolean lastButtonState1 = 1;
boolean lastButtonState2 = 1;
boolean lastButtonState3 = 1;
boolean lastButtonState4 = 1;
long lastDebounce1 = 0;
long lastDebounce2 = 0;
long lastDebounce3 = 0;
long lastDebounce4 = 0;
*/ // End of Button Stuff
int sAddress;
char buffer[20]; // screen character width
char sBuffer[360]; // 20 characters per row * 18 rows = 360
uint8_t whichOption;
uint8_t button_state = 0;
unsigned long lastDebounce;
const int noteFreq[] = {0, 392, 370, 349, 330};
const byte bitMask[] = {1, 2, 4, 8, 16, 32, 64, 128};
void setup() {
DDRF &= ~B11110011; // A0, A1, A2, A3, A4, A5 = INPUT
PORTF |= B11110000; // A0, A1, A2, A3 = PULLUP
PORTF &= ~B00000011; // A4, A5 = LOW
/*
pinMode(A0, INPUT_PULLUP); // Down & Start
pinMode(A1, INPUT_PULLUP); // Up & Select
pinMode(A2, INPUT_PULLUP); // Left & B Button
pinMode(A3, INPUT_PULLUP); // Right & A Button
pinMode(A4, INPUT); // pin 5, button diode arrays
pinMode(A5, INPUT); // pin 9, button diode arrays
digitalWrite(A4, LOW); // pin 5, button diode arrays
digitalWrite(A5, LOW); // pin 9, button diode arrays
*/
DDRD |= B11011111; // 0, 1, 2, 3, 4, 6, 12 = OUTPUT
DDRC |= B11000000; // 5, 13 = OUTPUT
DDRB |= B01110000; // 8, 9, 10 = OUTPUT
DDRE |= B01000000; // 7 = OUTPUT
DDRB &= ~B10000000; // 11 = INPUT
PORTD &= ~B11011111; // 0, 1, 2, 3, 4, 6, 12 = LOW
PORTC &= ~B01000000; // 5 = LOW
PORTE &= ~B01000000; // 7 = LOW
PORTB &= ~B10000000; // 11 = LOW
PORTB |= B01110000; // 8, 9, 10 = HIGH
PORTC |= B10000000; // 13 = HIGH
/*
pinMode(0, OUTPUT); // D0
pinMode(1, OUTPUT); // D1
pinMode(2, OUTPUT); // D2
pinMode(3, OUTPUT); // D3
pinMode(4, OUTPUT); // D4
pinMode(5, OUTPUT); // D5
pinMode(6, OUTPUT); // D6
pinMode(7, OUTPUT); // D7
pinMode(8, OUTPUT); // W (Write)
pinMode(9, OUTPUT); // RS (Reset)
pinMode(10, OUTPUT); // To LCD
pinMode(11, INPUT); // From LCD
digitalWrite(0, LOW); // D0
digitalWrite(1, LOW); // D1
digitalWrite(2, LOW); // D2
digitalWrite(3, LOW); // D3
digitalWrite(4, LOW); // D4
digitalWrite(5, LOW); // D5
digitalWrite(6, LOW); // D6
digitalWrite(7, LOW); // D7
digitalWrite(8, HIGH); // W (Write)
digitalWrite(9, HIGH); // RS (Reset)
digitalWrite(10, HIGH); // To LCD
digitalWrite(11, LOW); // From LCD
analogWrite(13, 255); // LED (OCR4A)
*/
Serial.begin(9600);
// pinMode(buttonPin1, INPUT_PULLUP);
// pinMode(buttonPin2, INPUT_PULLUP);
// pinMode(buttonPin3, INPUT_PULLUP);
// pinMode(buttonPin4, INPUT_PULLUP);
// GLCD_Initalize(); // Initalize LCD
// GLCD_ClearCG(); // Clear character generator area
// GLCD_ClearGraphic(); // Clear graphic area
GLCD_ClearText(); // Clear text area
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaCreditsText[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
/*
int toX = 40;
int toY = 5;
int counter = 0;
for (int y = 0; y < 10; y++) {
for (int x = 0; x < 15; x++) {
GLCD_SetPixel(toX+x,toY+y,pgm_read_word_near(house + counter));
counter++;
}
}
toX = 175;
toY = 5;
counter = 0;
for (int y = 0; y < 10; y++) {
for (int x = 0; x < 15; x++) {
GLCD_SetPixel(toX+x,toY+y,pgm_read_word_near(house + counter));
counter++;
}
}
*/
display();
delay(4000);
GLCD_ClearText();
// GLCD_ClearGraphic();
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaIntroText[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
uint8_t buttonPressed = ButtonChoice(0);
state = AreaStart; // Set starting area
}
void loop() {
// Serial.print("freeMemory()=");
// Serial.println(freeMemory());
// Serial.print("wantHook =");
// Serial.println(wantHook);
// Serial.print("Car Parts Req: ");
// Serial.println(carPartsReq);
Serial.println((unsigned int)&state, HEX);
state(); // fetch current area
// delay(10);
}
// **********************
// ***** START AREA *****
// **********************
void AreaStart() {
// GLCD_ClearGraphic();
GLCD_ClearText();
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaStartText[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
/*You awaken surrounded by trees, it's
dark and your back aches from the damp
ground. Your heart pounds in your chest.
What should you do?
1. Scream like a girl.
2. Check your pockets.
3. Run like crazy in a random direction.
4. Look around the clearing. */
uint8_t buttonPressed = ButtonChoice(4);
GLCD_ClearText(); // GLCD_TextGoTo(0,0);
boolean buttonPressReq = 0;
switch (buttonPressed) {
case 1:
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaStartOpt1[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
/*You scream pathetically like a girl.
You stand there and piss yourself as you
hear wolves approaching from all
directions.
Press any button to continue.*/
buttonPressReq = 1;
state = AreaDead;
break;
case 2:
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaStartOpt2[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
/*Rummaging through your pockets, you find
a smashed phone, a torch, a rubber duck,
and a large brass trumpet.
You switch on the torch and throw away
the other stuff.
Press any button to continue.*/
buttonPressReq = 1;
state = AreaLitWood;
break;
case 3:
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaStartOpt3[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
/*Running like crazy, you can't see where
you are going. You hear a roar and
something fluffy hits you on the head.
In the darkness you think you can make
out a bear's face inches from your own.
You fall unconscious and sleep a while.
Press any button to continue.*/
buttonPressReq = 1;
state = AreaCave;
break;
case 4:
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaStartOpt4[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
/*It's dark, so you obviously can't see
anything. Stupid.
Press any button to continue.*/
buttonPressReq = 1;
break;
}
if (buttonPressReq == 1) {
uint8_t buttonPressed = ButtonChoice(0);
}
}
// ***************************
// ***** LIT WOODED AREA *****
// ***************************
void AreaLitWood() {
uint8_t choiceValue;
GLCD_ClearText();
if ( haveMouse == 0) {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaLitWoodText[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
/*You are in a clearing in the woods. Tire
tracks lead one way, and a path towards
a cave leads the other way.
There is a dead mouse on the ground.
What should you do?
1. Follow the tire tracks.
2. Make your way to the cave.
3. Pick up the dead mouse. */
choiceValue = 3;
} else {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaLitWoodText_noMouse[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
/*You are in a clearing in the woods. Tire
tracks lead one way, and a path towards
a cave leads the other way.
What should you do?
1. Follow the tire tracks.
2. Make your way to the cave.*/
choiceValue = 2;
}
uint8_t buttonPressed = ButtonChoice(choiceValue);
GLCD_ClearText(); // GLCD_TextGoTo(0,0);
boolean buttonPressReq = 0;
switch (buttonPressed) {
case 1:
state = AreaCar;
break;
case 2:
state = AreaCave;
break;
case 3:
if (wantMouse == 0) {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaLitWoodOpt3[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
/*Ugh, why would you want to pick that up?
You decide to leave the dead mouse where
it is. */
} else {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaLitWoodOpt3mouse[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
/*You carefully pick up the dead mouse and
pop it in your pocket. */
haveMouse = 1;
}
buttonPressReq = 1;
break;
}
if (buttonPressReq == 1) {
uint8_t buttonPressed = ButtonChoice(0);
}
}
// *********************
// ***** CAVE AREA *****
// *********************
void AreaCave() {
GLCD_ClearText();
if (bearHasFrisbee == 0) {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaCaveText[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
/*You find yourself in a cave. A bear sits
in the corner holding a steering wheel.
Bats are flapping about, and a path from
the cave leads to a wooded area.
What should you do?
1. Try taking steering wheel from bear.
2. Poke a stick at the bats.
3. Exit cave and follow path to woods. */
} else {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaCaveText_frisbee[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
/*You find yourself in a cave. A bear sits
happily in the corner holding a frisbee.
Bats are flapping about, and a path from
the cave leads to a wooded area.
What should you do?
1. Wave at the bear.
2. Poke at the bats.
3. Exit cave and follow path to woods. */
}
uint8_t buttonPressed = ButtonChoice(3);
GLCD_ClearText(); // GLCD_TextGoTo(0,0);
boolean buttonPressReq = 0;
switch (buttonPressed) {
case 1:
if (haveFrisbee == 0) {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaCaveOpt1[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
/*The bear growls at you as you approach.
Ignoring it's warning, you attempt to
snatch the steering wheel.
The bear roars and chews your face off.
Press any button to continue. */
state = AreaDead;
} else {
if (bearHasFrisbee == 1) {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaCaveOpt1_wave[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
/*The bear waves his frisbee at you.
Press any button to continue. */
} else {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaCaveOpt1_frisbee[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
/*The bear growls as you approach.
You throw the frisbee at the bear. He
catches it and passes you the steering
wheel.
Press any button to continue. */
bearHasFrisbee = 1;
haveSteeringWheel = 1;
}
}
buttonPressReq = 1;
break;
case 2:
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaCaveOpt2[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
/*You poke the bats but nothing happens
Press any button to continue */
buttonPressReq = 1;
break;
case 3:
state = AreaLitWood;
break;
}
if (buttonPressReq == 1) {
uint8_t buttonPressed = ButtonChoice(0);
}
}
// ********************
// ***** CAR AREA *****
// ********************
void AreaCar() {
GLCD_ClearText();
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaCarText[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
/*There is a rusty old car, it's a bit
beat up, but looks roadworthy and it
appears to be unlocked.
There is a pretty cottage nearby.
What should you do?
1. Follow tire tracks back to the woods.
2. Head towards the cottage.
3. Get in the car. */
uint8_t buttonPressed = ButtonChoice(3);
GLCD_ClearText(); // GLCD_TextGoTo(0,0);
boolean buttonPressReq = 0;
switch (buttonPressed) {
case 1:
state = AreaLitWood;
break;
case 2:
state = AreaCottage;
break;
case 3:
if ( carPartsReq > 0 ) {
state = AreaInsideCar;
} else {
state = AreaInsideCompleteCar;
}
break;
}
if (buttonPressReq == 1) {
uint8_t buttonPressed = ButtonChoice(0);
}
}
// ***************************
// ***** INSIDE CAR AREA *****
// ***************************
void AreaInsideCar() {
GLCD_ClearText();
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaInsideCarText[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
/*You are in driver seat. It's pretty
comfortable, but you notice that the car
isn't quite complete.
What should you do?
1. Check what parts are missing.
2. Release the handbrake.
3. Get out of the car. */
uint8_t buttonPressed = ButtonChoice(3);
GLCD_ClearText(); // GLCD_TextGoTo(0,0);
boolean buttonPressReq = 0;
switch (buttonPressed) {
case 1:
state = AreaCarParts;
break;
case 2:
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaInsideCarOpt2[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
/*Despite knowing that the car is
incomplete, you release the handbrake.
The car begins to roll, and quickly
picks up speed. Suddenly you feel
weightless as the ground vanishes and a
pretty looking valley is hundreds of
meters below you.
Press any button to continue. */
buttonPressReq = 1;
state = AreaDead;
break;
case 3:
state = AreaCar;
break;
}
if (buttonPressReq == 1) {
uint8_t buttonPressed = ButtonChoice(0);
}
}
// **************************
// ***** CAR PARTS AREA *****
// **************************
void AreaCarParts() {
GLCD_ClearText();
// Serial.print("Steering Wheel = "); Serial.println(haveSteeringWheel);
// Serial.print("Car Keys = "); Serial.println(haveKeys);
// Serial.print("Window Winder = "); Serial.println(haveWinder);
// Serial.print("Petrol = "); Serial.println(havePetrolCan);
// Serial.print("Mirror = "); Serial.println(haveMirror);
if (carPartsReq > 0) {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaCarPartsText[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
/*The following parts are missing...
1. Check pockets for parts.
2. Forget about parts for now. */
uint8_t i = 3; // GLCD_TextGoTo(0,1);
// 01234567890123456789
if (carSteeringWheel == 0) { GLCD_WriteString((char *)"A steering wheel", i); i++; }
if (carKeys == 0) { GLCD_WriteString((char *)"Car keys", i); i++; }
if (carWinder == 0) { GLCD_WriteString((char *)"Window winder", i); i++; }
if (carPetrolCan == 0) { GLCD_WriteString((char *)"Petrol", i); i++; }
if (carMirror == 0) { GLCD_WriteString((char *)"Rear-view mirror", i); i++; }
} else {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaCarPartsText_comp[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
// The car is complete!
}
}
uint8_t buttonPressed = ButtonChoice(2);
GLCD_ClearText(); // GLCD_TextGoTo(0,0);
boolean buttonPressReq = 0;
uint8_t pocketItemCount = 0;
switch (buttonPressed) {
case 1:
if (carPartsReq == 0) {
state = AreaInsideCompleteCar;
} else {
// Checking Pockets
// GLCD_TextGoTo(0,pocketItemCount+1);
if ((haveSteeringWheel==1)&&(carSteeringWheel==0)) {
GLCD_WriteString((char *)"A steering wheel", pocketItemCount+2);
carSteeringWheel=1;
carPartsReq--;
pocketItemCount++;
}
// GLCD_TextGoTo(0,pocketItemCount+1);
if ((haveKeys==1)&&(carKeys==0)) {
GLCD_WriteString((char *)"Car keys", pocketItemCount+2);
carKeys=1;
carPartsReq--;
pocketItemCount++;
}
// GLCD_TextGoTo(0,pocketItemCount+1);
if ((haveWinder==1)&&(carWinder==0)) {
GLCD_WriteString((char *)"Window winder", pocketItemCount+2);
carWinder=1;
carPartsReq--;
pocketItemCount++;
}
// GLCD_TextGoTo(0,pocketItemCount+1);
if ((havePetrolCan==1)&&(carPetrolCan==0)) {
GLCD_WriteString((char *)"Petrol", pocketItemCount+2);
carPetrolCan=1;
carPartsReq--;
pocketItemCount++;
}
// GLCD_TextGoTo(0,pocketItemCount+1);
if ((haveMirror==1)&&(carMirror==0)) {
GLCD_WriteString((char *)"Rear-view mirror", pocketItemCount+2);
carMirror=1;
carPartsReq--;
pocketItemCount++;
}
// GLCD_TextGoTo(0,0);
if (pocketItemCount > 0)
{
if (pocketItemCount > 1) {
char tempChar = (char)pocketItemCount;
// 01234567890123456789
char tempString[] = "You added Items:";
tempString[10] = tempChar + 48;
GLCD_WriteString(tempString, 0);
} else {
// 01234567890123456789
GLCD_WriteString((char *)"You added one Item:", 0);
}
GLCD_WriteString((char *)" Press any button", 16);
GLCD_WriteString((char *)" to continue.", 17);
}
else
{
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaCarPartsPockets[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
/* You rummage through your pockets but
don't find any of the required parts.
Press any button to continue. */
}
buttonPressReq = 1;
}
break;
case 2:
if (carPartsReq > 0) {
state = AreaInsideCar;
} else {
buttonPressReq = 0;
state = AreaInsideCompleteCar;
}
break;
case 3:
if (carPartsReq == 0) {
buttonPressReq = 0;
state = AreaInsideCompleteCar;
}
case 4:
if (carPartsReq == 0) {
buttonPressReq = 0;
state = AreaInsideCompleteCar;
}
}
if (buttonPressReq == 1) {
buttonPressReq = 0;
uint8_t buttonPressed = ButtonChoice(0);
}
}
// ************************************
// ***** INSIDE COMPLETE CAR AREA *****
// ************************************
void AreaInsideCompleteCar() {
GLCD_ClearText();
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaInsideCompleteCarText[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
/*You are sitting comfortably in the
driving seat. The car is complete! You
feel a sense of accomplishment as
you put your seatbelt on.
What should you do?
1. Drive the car.
2. Get out of the car. */
uint8_t buttonPressed = ButtonChoice(2);
GLCD_ClearText(); // GLCD_TextGoTo(0,0);
boolean buttonPressReq = 0;
switch (buttonPressed) {
case 1:
if (haveCD) {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaInsideCompleteCarOpt1_CD[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
state = AreaFinish;
/*You start up the car and pop your CD in.
Singing along, you drive away from the
cottage, down a few country lanes, and
then join the A66 towards Scotch corner.
Woop! You're on your way home! */
} else {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaInsideCompleteCarOpt1[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
wantCD = 1;
/*You start up the car and turn the stereo
on. The radio is just static, and there
is no CD in the slot.
There's no way you're going anywhere
unless you have some music to listen to. */
}
buttonPressReq = 1;
break;
case 2:
state = AreaCar;
break;
}
if (buttonPressReq == 1) {
uint8_t buttonPressed = ButtonChoice(0);
}
}
// ************************
// ***** COTTAGE AREA *****
// ************************
void AreaCottage() {
GLCD_ClearText();
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaCottageText[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
/*Before you is a pretty white cottage.
It looks like no one has lived here in
quite a long time.
What should you do?
1. Go back to the car.
2. Enter the cottage.
3. Visit the outhouse.
4. Walk to the garden. */
uint8_t buttonPressed = ButtonChoice(4);
GLCD_ClearText(); // GLCD_TextGoTo(0,0);
boolean buttonPressReq = 0;
switch (buttonPressed) {
case 1:
state = AreaCar;
break;
case 2:
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaCottageOpt2[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
/*The door creaks ominously as you gently
push it open.
Press any button to continue. */
buttonPressReq = 1;
state = AreaInsideCottage;
break;
case 3:
state = AreaOuthouse;
break;
case 4:
state = AreaGarden;
break;
}
if (buttonPressReq == 1) {
uint8_t buttonPressed = ButtonChoice(0);
}
}
// *******************************
// ***** INSIDE COTTAGE AREA *****
// *******************************
void AreaInsideCottage() {
GLCD_ClearText();
if (haveKeys == 0) {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaInsideCottageText[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
/*The cottage appears to be an empty
holiday home. There is a cute cat in the
corner playing with some keys, and a CD
player sits on the kitchen table.
What should you do?
1. Retrieve the keys from the cat.
2. Remove the CD from the CD player.
3. Leave the cottage. */
}
} else {
if (haveCD == 0) {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaInsideCottage_keys[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
/*The cottage appears to be an empty
holiday home. There is a cute cat in the
corner playing with a mouse, and a CD
player sits on the kitchen table.
What should you do?
1. Stroke the Cat.
2. Remove the CD from the CD player.
3. Leave the cottage. */
}
} else {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaInsideCottage_cd[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
/*The cottage appears to be an empty
holiday home. There is a cute cat in the
corner playing with a mouse, and a CD
player sits on the kitchen table.
What should you do?
1. Stroke the cat.
2. Press play on the CD player.
3. Leave the cottage. */
}
}
}
uint8_t buttonPressed = ButtonChoice(3);
GLCD_ClearText(); // GLCD_TextGoTo(0,0);
boolean buttonPressReq = 0;
switch (buttonPressed) {
case 1:
if (haveMouse == 0) {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaInsideCottageOpt1[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
// FAIL TO GET KEYS
wantMouse = 1;
} else {
if (haveKeys == 0) {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaInsideCottageOpt1_mouse[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
haveKeys = 1;
// GIVE MOUSE GET KEYS
} else {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaInsideCottageOpt1_stroke[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
// STROKE CAT
}
}
buttonPressReq = 1;
break;
case 2:
if (wantCD == 0) {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaInsideCottageOpt2[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
/*You inspect the CD player. It's plugged
in with a Elton John CD inside. A
BabyMetal CD is next to it on the table.
You think it's best not to disturb it
at the moment.
Press any button to continue. */
} else {
if (haveCD == 0) {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaInsideCottageOpt2_takeCD[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
haveCD = 1;
/*You inspect the CD player. It's plugged
in with a Elton John CD inside. A
BabyMetal CD is next to it on the table.
You take the Elton John CD and put it
in your pocket. You pop the BabyMetal CD
into the player.
Press any button to continue. */
} else {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaInsideCottageOpt2_play[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
/*You inspect the CD player. It's plugged
in with a BabyMetal CD inside. You press
play and do a little dance around the
cottage whilst singing along to 'Gimme
Chocolate!!'.
Oh yeah!
Press any button to continue. */
}
}
buttonPressReq = 1;
break;
case 3:
state = AreaCottage;
break;
}
if (buttonPressReq == 1) {
uint8_t buttonPressed = ButtonChoice(0);
}
}
// ***********************
// ***** GARDEN AREA *****
// ***********************
void AreaGarden() {
GLCD_ClearText();
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaGardenText[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
/*In the beautiful cottage garden there is
an old wooden shed, a small well and an
outhouse toilet. You can see the beach.
What should you do?
1. Walk up to the pretty cottage.
2. Look inside of the old shed.
3. Investigate the well.
4. Walk down to the beach. */
uint8_t buttonPressed = ButtonChoice(4);
GLCD_ClearText(); // GLCD_TextGoTo(0,0);
boolean buttonPressReq = 0;
switch (buttonPressed) {
case 1:
state = AreaCottage;
break;
case 2:
state = AreaShed;
break;
case 3:
state = AreaWell;
break;
case 4:
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaGardenOpt4[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
/*You take a leisurely stroll down towards
the beach. It's a nice day and there are
butterflies flirting with the flowers
growing at the sides of the path.
The beach looks like something described
in a text-based adventure as you
approach.
Press any button to continue. */
buttonPressReq = 1;
state = AreaBeach;
break;
}
if (buttonPressReq == 1) {
uint8_t buttonPressed = ButtonChoice(0);
}
}
// *********************
// ***** SHED AREA *****
// *********************
void AreaShed() {
uint8_t choiceValue;
GLCD_ClearText();
if (haveFrisbee == 0) {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaShedText[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
/*Inside the shed there is a few empty
petrol cans, a bottle marked with skull
& crossbones, and an orange frisbee.
What should you do?
1. Pick up an empty petrol can.
2. Drink the contents of the bottle.
3. Leave the shed and close the door.
4. Pick up the frisbee. */
choiceValue = 4;
} else {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaShedText_frisbee[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
/*Inside the shed there is a few empty
petrol cans and a bottle marked with
skull & crossbones.
What should you do?
1. Pick up an empty petrol can.
2. Drink the contents of the bottle.
3. Leave the shed and close the door. */
choiceValue = 3;
}
uint8_t buttonPressed = ButtonChoice(choiceValue);
GLCD_ClearText(); // GLCD_TextGoTo(0,0);
boolean buttonPressReq = 0;
switch (buttonPressed) {
case 1:
if (wantEmptyCan == 0) {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaShedOpt1[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
/*There isn't much point in an empty can,
and you can't see any petrol nearby.
You decide to just leave the cans where
they are. */
} else {
if (haveEmptyCan == 0) {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaShedOpt1_can[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
/*You pick up one of the empty cans
thinking that it will probably come in
handy. */
haveEmptyCan = 1;
} else {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaShedOpt1_got[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
/*You don't need any more empty petrol
cans. Besides, it looks like there is a
family of little mice living in one of
them. */
}
}
buttonPressReq = 1;
break;
case 2:
//
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaShedOpt2[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
/*You cheerfully pop the cork on the small
bottle and down the contents in one go.
Nothing happens.
Oh wait...
Press any button to continue. */
buttonPressReq = 1;
state = AreaDead;
break;
case 3:
state = AreaGarden;
break;
case 4:
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaShedOpt4[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
/*Everyone loves playing with frisbees!
You pick up the frisbee and stick it up
your jumper. */
buttonPressReq = 1;
haveFrisbee = 1;
break;
}
if (buttonPressReq == 1) {
uint8_t buttonPressed = ButtonChoice(0);
}
}
// *********************
// ***** WELL AREA *****
// *********************
void AreaWell() {
GLCD_ClearText();
if (haveMirror == 0) {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaWellText[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
/*Looking down the well, you see something
reflective at the bottom. The outhouse
toilet and old shed are nearby.
What should you do?
1. Retrieve item from the well.
2. Look inside the old shed.
3. Visit the outhouse.
4. Head back to the cottage. */
} else {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaWellText_mirror[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
/*Looking down the well, there is a few
shiny coins at the bottom. The outhouse
toilet and old shed are nearby.
What should you do?
1. Toss a coin in the well.
2. Look inside the old shed.
3. Visit the outhouse.
4. Head back to the cottage. */
}
uint8_t buttonPressed = ButtonChoice(4);
GLCD_ClearText(); // GLCD_TextGoTo(0,0);
boolean buttonPressReq = 0;
switch (buttonPressed) {
case 1:
if (haveMirror) {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaWellOpt1_coin[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i); }
// Toss coin
} else {
if (haveHook) {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaWellOpt1_hook[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i); }
// Toss coin
haveMirror = 1;
} else {
if (haveRope) {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaWellOpt1_rope[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i); }
// Can't hook with just rope
wantHook = 1;
} else {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaWellOpt1[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i); }
// Can't reach it
}
}
}
buttonPressReq = 1;
break;
case 2:
state = AreaShed;
break;
case 3:
state = AreaOuthouse;
break;
case 4:
state = AreaCottage;
break;
}
if (buttonPressReq == 1) {
uint8_t buttonPressed = ButtonChoice(0);
}
}
// *************************
// ***** OUTHOUSE AREA *****
// *************************
void AreaOuthouse() {
GLCD_ClearText();
if (haveHook == 1) {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaOuthouseText_hook[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
/*You are in the outhouse. Nothing else is
here but a toilet. Thanks to your recent
cleaning spree, it appears to be
spotlessly clean.
What should you do?
1. Walk back to the cottage.
2. Go to the well.
3. Use the toilet. */
} else {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaOuthouseText[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
}
/*You are in the outhouse. Nothing else is
here but a toilet. It's quite dirty and
there appears to be a large fishing hook
at the bottom of the toilet bowl.
What should you do?
1. Walk back to the cottage.
2. Go to the well.
3. Retrieve the hook from the toilet. */
uint8_t buttonPressed = ButtonChoice(3);
GLCD_ClearText(); // GLCD_TextGoTo(0,0);
boolean buttonPressReq = 0;
switch (buttonPressed) {
case 1:
state = AreaCottage;
break;
case 2:
state = AreaWell;
break;
case 3:
if (haveHook) {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaOuthouseOpt3_wee[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i); }
} else {
if (wantHook) {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaOuthouseOpt3_hook[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i); }
haveHook = 1;
} else {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaOuthouseOpt3[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i); }
}
}
buttonPressReq = 1;
break;
}
if (buttonPressReq == 1) {
uint8_t buttonPressed = ButtonChoice(0);
}
}
// **********************
// ***** BEACH AREA *****
// **********************
void AreaBeach() {
GLCD_ClearText();
if (haveWinder) {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaBeachText_snail[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
/*A boat is resting on the beach, out of
the water. You can see the path leading
up towards the cottage. You can't see
any snails anywhere.
What should you do?
1. Investigate the boat.
2. Head back up to the cottage garden.
3. Search for snails. */
}
} else {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaBeachText[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
/*A boat is resting on the beach, out of
the water. You can see the path leading
up towards the cottage. You see a snail
shell poking out of the sand.
What should you do?
1. Investigate the boat.
2. Head back up to the cottage garden.
3. Pick up the snail. */
}
}
uint8_t buttonPressed = ButtonChoice(3);
GLCD_ClearText(); // GLCD_TextGoTo(0,0);
boolean buttonPressReq = 0;
switch (buttonPressed) {
case 1:
state = AreaBoat;
break;
case 2:
state = AreaGarden;
break;
case 3:
if (haveWinder) {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaBeachOpt3_search[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
/*You walk up and down the beach for a bit
searching for sea snails.
You find one and put him in the sea. He
looks much happier now.
Press any button to continue. */
}
} else {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaBeachOpt3[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
haveWinder = 1;
/*As you bend down to pick up the snail,
you realise it isn't a snail at all!
It's the round plastic knob of a car
window winder. You pull the winder out
from under the sand, dust it off and pop
it in your pocket.
Press any button to continue. */
}
}
buttonPressReq = 1;
break;
}
if (buttonPressReq == 1) {
uint8_t buttonPressed = ButtonChoice(0);
}
}
// *********************
// ***** BOAT AREA *****
// *********************
void AreaBoat() {
GLCD_ClearText();
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaBoatText[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
/*Inside the small boat, there are a few
coils of rope and an outboard engine.
It looks seaworthy.
What should you do?
1. Start the boat up and sail away.
2. Take petrol from the engine tank.
3. Take a coil of rope.
4. Leave the boat. */
}
wantEmptyCan = 1;
uint8_t buttonPressed = ButtonChoice(4);
GLCD_ClearText(); // GLCD_TextGoTo(0,0);
boolean buttonPressReq = 0;
switch (buttonPressed) {
case 1:
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaBoatOpt1[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i); }
buttonPressReq = 1;
break;
case 2:
if (havePetrolCan) {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaBoatOpt2_dneed[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
//Dont need any more petrol
} else {
if (haveEmptyCan) {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaBoatOpt2_can[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
//Fill up empty can
havePetrolCan = 1;
} else {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaBoatOpt2[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
//Have nothing to put petrol in
}
}
buttonPressReq = 1;
break;
case 3:
if (haveRope) {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaBoatOpt3_dneed[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
/*You decide that you don't need any more rope. */
} else {
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaBoatOpt3[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
/*The rope is of a good quality, both thin
and strong. You pick up a coil and carry
it over your shoulder. */
haveRope = 1;
}
buttonPressReq = 1;
break;
case 4:
state = AreaBeach;
break;
}
if (buttonPressReq == 1) {
uint8_t buttonPressed = ButtonChoice(0);
}
}
// ************************
// ***** YOU ARE DEAD *****
// ************************
void AreaDead() {
GLCD_ClearText(); // Clear text area
// GLCD_TextGoTo(0,0); // set text coordinates
// GLCD_TextGoTo(13,3);
// 01234567890123456789
GLCD_WriteString((char *)" $ You are dead @", 3);
// GLCD_TextGoTo(0,7);
// 01234567890123456789
GLCD_WriteString((char *)" Press any button", 16);
GLCD_WriteString((char *)" to start again.", 17);
/*
int toX = 62;
int toY = 24;
int counter = 0;
for (int y = 0; y < 8; y++) {
for (int x = 0; x < 8; x++) {
GLCD_SetPixel(toX+x,toY+y,pgm_read_word_near(skull + counter));
counter++;
}
}
toX = 167;
toY = 24;
counter = 0;
for (int y = 0; y < 8; y++) {
for (int x = 0; x < 8; x++) {
GLCD_SetPixel(toX-x,toY+y,pgm_read_word_near(skull + counter));
counter++;
}
}
*/
// Erase flags for parts obtained:
wantCD = 0;
haveCD = 0;
haveFrisbee = 0;
bearHasFrisbee = 0;
haveSteeringWheel = 0;
carSteeringWheel = 0;
haveKeys = 0;
carKeys = 0;
haveWinder = 0;
carWinder = 0;
wantEmptyCan = 0;
haveEmptyCan = 0;
havePetrolCan = 0;
carPetrolCan = 0;
haveMirror = 0;
carMirror = 0;
haveRope = 0;
wantHook = 0;
haveHook = 0;
wantMouse = 0;
haveMouse = 0;
carPartsReq = 5;
display();
delay(175); // Short delay between notes
int melody[] = {220, 220, 220, 220, 262, 247, 247, 220, 220, 220, 220};
int duration[] = {300, 225, 75, 300, 225, 75, 225, 75, 225, 75, 750};
for (uint8_t thisNote = 0; thisNote < 11; thisNote++)
{
TimerFreeTone(12, melody[thisNote], duration[thisNote]);
delay(75); // Short delay between notes
}
uint8_t buttonPressed = ButtonChoice(0);
state = AreaStart;
}
// ********************* //
// ***** FINISHED! ***** //
// ********************* //
void AreaFinish() {
GLCD_ClearText();
for (uint8_t i = 0; i < 18; i++) {
strcpy_P(buffer, (char*)pgm_read_word(&(areaFinishText[i])));
// GLCD_TextGoTo(0,i);
GLCD_WriteString(buffer, i);
}
/*
int toX = 92;
int toY = 20;
int counter = 0;
for (int y = 0; y < 9; y++) {
for (int x = 0; x < 38; x++) {
GLCD_SetPixel(toX+x,toY+y,pgm_read_word_near(car + counter));
counter++;
}
}
*/
uint8_t buttonPressed = ButtonChoice(0);
}
uint8_t ButtonChoice(uint8_t numberOptions)
{
whichOption = 1;
uint8_t buttonChosen = 0;
uint8_t currentButtonState = 0;
uint8_t previousButtonState = 0;
while (buttonChosen == 0)
{
display();
previousButtonState = currentButtonState;
currentButtonState = button_state;
if ((previousButtonState == 0) && (currentButtonState != 0) && (numberOptions == 0) && ((millis() - lastDebounce) > 50))
{
TimerFreeTone(12, 440, 25);
buttonChosen = 5;
}
else if (!(previousButtonState & (B00000001 | B00000010)) && (currentButtonState & (B00000001 | B00000010)) &&
((millis() - lastDebounce) > 50)) // A_BUTTON | B_BUTTON
{
TimerFreeTone(12, 440, 25);
buttonChosen = whichOption;
}
else if (!(previousButtonState & B10000000) && (currentButtonState & B10000000) && (whichOption < numberOptions) &&
((millis() - lastDebounce) > 50)) // DOWN_BUTTON
{
whichOption++;
TimerFreeTone(12, noteFreq[whichOption], 25);
}
else if (!(previousButtonState & B01000000) && (currentButtonState & B01000000) && (whichOption > 1) &&
((millis() - lastDebounce) > 50)) // UP_BUTTON
{
whichOption--;
TimerFreeTone(12, noteFreq[whichOption], 25);
}
}
lastDebounce = millis();
return buttonChosen;
}
/*
// ******************** //
// BUTTON SHIZNIT //
// ******************** //
int ButtonChoice() {
// Serial.println("ButtonChoice Function run");
int buttonChosen = 0;
while (buttonChosen == 0) {
int buttonReading1 = digitalRead(buttonPin1);
int buttonReading2 = digitalRead(buttonPin2);
int buttonReading3 = digitalRead(buttonPin3);
int buttonReading4 = digitalRead(buttonPin4);
if (buttonReading1 != lastButtonState1) { lastDebounce1 = millis(); }
if (buttonReading2 != lastButtonState2) { lastDebounce2 = millis(); }
if (buttonReading3 != lastButtonState3) { lastDebounce3 = millis(); }
if (buttonReading4 != lastButtonState4) { lastDebounce4 = millis(); }
// BUTTON 1
if ((millis() - lastDebounce1) > 50) {
if (buttonReading1 != buttonState1) { //button really has changed state
buttonState1 = buttonReading1;
if (buttonState1 == LOW) { //only if button pressed
buttonChosen = 1;
}
}
}
// BUTTON 2
if ((millis() - lastDebounce2) > 50) {
if (buttonReading2 != buttonState2) { //button really has changed state
buttonState2 = buttonReading2;
if (buttonState2 == LOW) { //only if button pressed
buttonChosen = 2;
}
}
}
// BUTTON 3
if ((millis() - lastDebounce3) > 50) {
if (buttonReading3 != buttonState3) { //button really has changed state
buttonState3 = buttonReading3;
if (buttonState3 == LOW) { //only if button pressed
buttonChosen = 3;
}
}
}
// BUTTON 4
if ((millis() - lastDebounce4) > 50) {
if (buttonReading4 != buttonState4) { //button really has changed state
buttonState4 = buttonReading4;
if (buttonState4 == LOW) { //only if button pressed
buttonChosen = 4;
}
}
}
// Save readings for next loop
lastButtonState1 = buttonReading1;
lastButtonState2 = buttonReading2;
lastButtonState3 = buttonReading3;
lastButtonState4 = buttonReading4;
}
return buttonChosen;
}
*/
void GLCD_ClearText()
{
for (int i = 0; i < 360; i++)
{
sBuffer[i] = 0;
}
}
void GLCD_WriteString(char * string, uint8_t i)
{
sAddress = i * 20;
while(*string)
{
GLCD_WriteChar(*string++);
}
}
void GLCD_WriteChar(char charCode)
{
sBuffer[sAddress] = (charCode - 32);
sAddress++;
}
void display()
{
while (PINB & B10000000) {} // wait for VBLANK from LCD
PORTB &= ~B01000000; // To LCD
PORTB &= ~B00100000; // RS (Reset) LOW
PORTB |= B00100000; // RS (Reset) HIGH
DDRF &= ~B00000010; // set A4 to INPUT, LOW
DDRF |= B00000001; // set A5 to OUTPUT, LOW
button_state = ((~PINF) & B11110000); // Down, Up, Left, Right
paintScreen();
DDRF &= ~B00000001; // set A5 to INPUT, LOW
DDRF |= B00000010; // set A4 to OUTPUT, LOW
button_state |= ((~PINF) & B11110000) >> 4; // Start, Select, B, A
PORTB |= B01000000; // To LCD
}
void paintScreen()
{
char tempChar;
byte tempByte;
int tempAddress;
for (uint8_t r = 0; r < 18; r++) // 18 rows
{
for (uint8_t b = 0; b < 8; b++) // 8 bytes per character
{
for (uint8_t c = 0; c < 20; c++) // 20 characters per row
{
tempAddress = (r * 20) + c;
tempChar = sBuffer[tempAddress];
tempByte = font8x8_basic[tempChar][b];
if ((tempChar > 16) && (tempChar < 21)) // highlight selected option
{
if ((tempChar == 17) && (whichOption == 1)) tempByte = ~tempByte;
else if ((tempChar == 18) && (whichOption == 2)) tempByte = ~tempByte;
else if ((tempChar == 19) && (whichOption == 3)) tempByte = ~tempByte;
else if ((tempChar == 20) && (whichOption == 4)) tempByte = ~tempByte;
}
if (tempByte & bitMask[0]) PORTE |= B01000000; // pin 7
else PORTE &= ~B01000000;
if (tempByte & bitMask[1]) PORTD |= B10000000; // pin 6
else PORTD &= ~B10000000;
if (tempByte & bitMask[2]) PORTC |= B01000000; // pin 5
else PORTC &= ~B01000000;
if (tempByte & bitMask[3]) PORTD |= B00010000; // pin 4
else PORTD &= ~B00010000;
if (tempByte & bitMask[4]) PORTD |= B00000001; // pin 3
else PORTD &= ~B00000001;
if (tempByte & bitMask[5]) PORTD |= B00000010; // pin 2
else PORTD &= ~B00000010;
if (tempByte & bitMask[6]) PORTD |= B00001000; // pin 1
else PORTD &= ~B00001000;
if (tempByte & bitMask[7]) PORTD |= B00000100; // pin 0
else PORTD &= ~B00000100;
PORTB &= ~B00010000; // W (Write) LOW
PORTB |= B00010000; // W (Write) HIGH
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment