Thermal Printing messages from an LCD menu options yes or no questions

I neglected my Arduino classes now I’m feeling the burn. I’m a product design student in need of your help.

I’ll start off with describing my project.
I want to raise awareness of mental health stigmatisation and offer some advice to the device’s user. The device will allow the user to answer simple yes or no questions which are displayed on a 16x2 LCD with two simple push buttons. for their choices, the device will print different information on receipt style slips.

An example being ‘are you male aged 18-35’ if yes ‘would you consider yourself depressed’, the device would then print a slip explaining that mental illness is normal and where to find help. If no the device will ask if the user knows someone is this demographic’ then from this it will print of a slip that explains the effects of mental health stigma as well as explaining how to spot depression and strike up a conversation with the person. I want to have around 4 different slips for four sets of people who interact with the design.

I have the thermal printer up and running which took me a good while, what I want to know is how do initially set up the LCD with these yes or no questions with push buttons (Q1yes Q2yes print version one slip, Q1yes Q2no Q3 yes print slip version two etc…) then once i have that sorted how do I connect this with my thermal printer set up. Once they have answered the questions the slip should print straight away with another button, this isnt that important but it would helpful

I need your advice badly, I apologise for my noobery

cunt3.jpg

cunt2.jpg

I have the basic code set up for the thermal printer. Initially I want I want to add a piece of code that allows the user to answer yes or no questions displayed on a 16x2 LCD. After each question is answer I want the printer to print a certain piece of text wither the user answered yes or no, then moves onto question two... for about 5 questions, so that in the end the user gets a customised print out from how they answer the questions.

yes and no buttons are pins 8 and 9, LCD is set up as normal

any help is much appreciated. I'm probably missing some obvious stuff but I cant see it myself.

#include "Adafruit_Thermal.h"
#include "SoftwareSerial.h"

#define TX_PIN 6 // Arduino transmit  YELLOW WIRE  labeled RX on printer
#define RX_PIN 5 // Arduino receive   GREEN WIRE   labeled TX on printer

#include "LiquidCrystal.h"




SoftwareSerial mySerial(RX_PIN, TX_PIN); // Declare SoftwareSerial obj first
Adafruit_Thermal printer(&mySerial);     // Pass addr to printer constructor
// Then see setup() function regarding serial & printer begin() calls.


void setup() {


  pinMode(7, OUTPUT); digitalWrite(7, LOW);
  mySerial.begin(9600);   
  printer.begin();        

  //print at start
  printer.justify('L');
  printer.setSize('M');
  printer.println(F("Mental Health Awareness\n"));
  printer.justify('L');
  printer.setSize('S');
  printer.println(F("Mental illness effects one in\nfour people at anyone time.\nMany of those who are suffering choose not to seek help or talk about their condition in fear\nof being stigmatised, why be\nlablled as weird or dangerous\nwhen you can keep your\ncondition to yourself. In order to progress society we must\ncollectively stop the\nstigmatisation of those with\nmental health issues.\n\n"));

  //LCD asks question, if answered yes then print this
  printer.justify('L');
  printer.setSize('M');
  printer.println(F("Keirkegaard - Regret\n"));
  printer.justify('L');
  printer.setSize('S');
  printer.println(F("Marry, and you will regret it;\ndont marry, you will also\nregret it; marry or dont marry, you will regret it either way.\nLaugh at the worlds foolishness,\nyou will regret it; weep over\nit, you will regret that too;\nlaugh at the worlds foolishness or weep over it, you will regret\nboth. Believe a woman, you will regret it; believe her not, you will also regret it Hang\nyourself, you will regret it; do\nnot hang yourself, and you will regret that too; hang yourself\nor dont hang yourself, youll\nregret it either way; whether\nyou hang yourself or do not hang\nyourself, you will regret both. This, gentlemen, is the essence of all philosophy.\n\n"));

 //LCD asks question, if answered no then print this
  printer.justify('L');
  printer.setSize('M');
  printer.println(F("no example\n"));
  printer.justify('L');
  printer.setSize('S');
  printer.println(F("no example\n\n"));

  //next question asked on LCD
  //if yes print this... if no print this... for example


  
  printer.feed(2);

  printer.sleep();      // Tell printer to sleep
  delay(3000L);         // Sleep for 3 seconds
  printer.wake();       // MUST wake() before printing again, even if reset
  printer.setDefault(); // Restore printer to defaults
}

void loop() {
}

Setup some functions that display each individual screen or printout to tidy things up and make them more structured. Keep the setup() method for initialisation code only. Add a global variable to keep track of which screen you are currently in. Inside the loop() method add the button detection code (there are lots of examples for reading buttons, debouncing etc.).

Once you have a button press event, you will know which screen you are in. Call the appropriate printing function and then decide which screen comes next and display it. Set the global variable to the new screen.

You currently don't have any LCD or button code at all.

Thanks for your advice man it very helpful, design has change slightly but what you said resonates still, I have the buttons working and printing specific code depending which button is press. with your given advice I will now add the LCD. cheers

#include "Adafruit_Thermal.h"
#include "SoftwareSerial.h"

#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

  

int buttonState = 0; //variable for reading pushbuttonstate
const int buttonPin1 = 8; //number of pushbutton pin
const int buttonPin2 = 9; //number of pushbutton pin
const int buttonPin3 = 10; //number of pushbutton pin
const int buttonPin4 = 11; //number of pushbutton pin


void setup() {
  pinMode(7, OUTPUT); digitalWrite(7, LOW);
  pinMode(8, INPUT); 
  pinMode(9, INPUT);
  pinMode(10,INPUT);
  pinMode(11,INPUT);
  mySerial.begin(9600);   
  printer.begin();  

  //always print at start
  printer.justify('L');
  printer.setSize('L');
  printer.println(F("Mk 1 - Prototype"));
  printer.feed(1);
  printer.justify('L');
  printer.setSize('S');
  printer.println(F("Depression effects 1 in 4 people\nat anyone time. 70% of those\nsuffering choose not to seek\nhelp due to stigma.\n\nThis device aims to raise\nawarness of social stigma and\neducate the user on issues\nsurrounding depression."));
  printer.feed(1);
  printer.println(F("--------------------------------"));
  printer.feed(1);

  printer.justify('L');
  printer.setSize('S');
  printer.println(F("From the options below select\none or more demographics which\nbest describe you, then press\nthe corrosponding push button."));
  printer.feed(1);
  printer.justify('L');
  printer.setSize('S');
  printer.println(F("1 - I want more information on\nhow to define depression.\n\n2 - I would consider myself to\nbe depressed.\n\n3 - I am not depressed but I\nbelive I know someone who is.\n\n4 - I want to more on the affect\nsocial stigma has on both\nsoceity and sufferers of\ndepression."));
  printer.feed(1);
  printer.println(F("--------------------------------"));
  printer.feed(1);

  printer.sleep();      // Tell printer to sleep
 // delay(3000L);         // Sleep for 3 seconds
 // printer.wake();       // MUST wake() before printing again, even if reset
 // printer.setDefault(); // Restore printer to defaults

}
  void loop() {
  buttonState = digitalRead(buttonPin1);
  if (buttonState == HIGH){

printer.justify('L');
  printer.setSize('L');
  printer.println(F("Defining\nDepression"));
  printer.feed(1);
  printer.justify('L');
  printer.setSize('S');
  printer.println(F("depression definition plus some numbers and facts"));
  printer.feed(1);
  printer.println(F("-------------------------------"));
  printer.feed(1);
  

  }
buttonState = digitalRead(buttonPin2);
  if (buttonState == HIGH){

  printer.justify('L');
  printer.setSize('L');
  printer.println(F("Depressed"));
  printer.feed(1);
  printer.justify('L');
  printer.setSize('S');
  printer.println(F("Attempt to normalise the\ncondition to the person,\nconvince them its better\nto seek help than stay quiet,\ninformation on finding help."));
  printer.feed(1);
  printer.println(F("-------------------------------"));
  printer.feed(1);

  }
  buttonState = digitalRead(buttonPin3);
  if (buttonState == HIGH){

  printer.justify('L');
  printer.setSize('L');
  printer.println(F("Helping\nOthers"));
  printer.feed(1);
  printer.justify('L');
  printer.setSize('S');
  printer.println(F("Information on how to spot\ndepression and approach\nsufferers."));
  printer.feed(1);
  printer.println(F("-------------------------------"));
  printer.feed(1);
 
  }
  buttonState = digitalRead(buttonPin4);
  if (buttonState == HIGH){

  printer.justify('L');
  printer.setSize('L');
  printer.println(F("Social Stigma"));
  printer.feed(1);
  printer.justify('L');
  printer.setSize('S');
  printer.println(F("Some facts on social stigma, an attempt to make people conscious\nof its detremental effects on\nboth the person and society"));
  printer.feed(1);
  printer.println(F("-------------------------------"));
  printer.feed(1);
 
  }
  
}

You can make use of a struct to store a question an where to go next.

struct QUESTION
{
  char *text; // text to display
  int yes; // number of next questipn if answered yes
  int no; // number of next question if answered no
};

QUESTION questions[] =
{
  {"are you sick", 1, 0},
  {"do you have a headache", 2, 3},
  ...,
  ...,
  {"last question of a sequence, -1, -1},
};

void loop()
{
  static int currentQuestion = O;

  if (currentQuestion == -1)
  {
    // print result
    ...
    ...
    // start with first question again
    currentQuestion = 0;
  }

  Serial.println(questions[currentQuestion]);

  
  switch(Serial.read())
  {
    case 'y';
      currentQuestion = questions[currentQuestion].yes;
      break;
    case 'n';
      currentQuestion = questions[currentQuestion].no;
      break;   
  }

}

The code shows how to cycle through questions based on the answers.

Modify to suite your needs.

Typed on a cellphone so not compiled nor (obviously) tested.