Thermal Print inside various if statements

Hello, I am trying to get this termal printer to print info based on whether the if statement condition is valid or not. So in this code if each if statement is valid i want it to print both the magnesium and zinc stuff from each if statement but its only printing one. I think it is because they are both being called at the exact same time but im not sure. Can someone please help..

Lol i know this sounds confusing but to be plain and simple i just want it to print both texts shown in the code below one after the other (assuming both if statements are activated).

    if (buttonPushCounter1 == 22 or buttonPushCounter == 22){   //dispense pills after last question of survey is answered
if (question3Yes == 1){
            if (Stepper1 == 0){
            delay(300);
            myStepper1.step(stepsPerRevolution/8);
            Stepper1 = 1;
                         Thermal.println("You Lack Magnesium In your Diet.");
             Thermal.write(10); //Sends the LF to the printer, advances the paper
             Thermal.write(10);
             Thermal.print("Magnesium is important for many processes in the body including regulating muscle and nerve     function, blood sugar levels,   blood pressure making protien,  bone and dna.  "); 
             Thermal.write(10);
             Thermal.write(10);
             Thermal.print("Food Sources With Magnesium     Include:");
             Thermal.write(10);
             Thermal.print("-Whole Grains"); 
             Thermal.write(10);
             Thermal.print("-Green Leafy Vegetables");
             Thermal.write(10);
             Thermal.print("-Nuts");
             Thermal.write(10);
             Thermal.write(10);
             Thermal.write(10);
             Thermal.write(10);
             do { } while (1>0);
            }
            delay(300);
            if (Stepper4 == 0){
            delay(300);
            myStepper4.step(stepsPerRevolution/8);
                         Thermal.write(10); //Sends the LF to the printer, advances the paper
             Thermal.write(10);
             Thermal.print("Zinc is a mineral that helps    keep our immune system healthy, protein synthesis, normal cell  replacment & wound healing."); 
             Thermal.write(10);
             Thermal.write(10);
             Thermal.print("Food Sources With Zinc Include:");
             Thermal.write(10);
             Thermal.print("-Red Meat"); 
             Thermal.write(10);
             Thermal.print("-Poultry");
             Thermal.write(10);
             Thermal.print("-Beans");
             Thermal.write(10);
             Thermal.print("-Shellfish");
             Thermal.write(10);
             Thermal.print("-Dairy");
             Thermal.write(10);
             Thermal.print("-Salmon");
             Thermal.write(10);
             Thermal.write(10);
             Thermal.write(10);
             Thermal.write(10);
             do { } while (1>0);}
            Stepper4 = 1;   //store value telling us that stepper has been rotated once
                                     Thermal.println("You lack zinc in your diet.");


            }
           question3Yes = 0;
do { } while (1>0);

At the end of the stuff printing in the first if block there, you tell the Arduino to lock itself up and never ever do anything else unless it gets reset or 1 somehow becomes less than or equal to 0. That might explain why it’s not doing anything else.

Why would you lock it up right there?

In the example code I found for the thermal printer it had me do that. What would be a better substitute?

That's the problem with being a hack and paste coder. Those example codes are there to show you how to use the different functions of that particular library or device. They're almost never written in a way that makes them easy to expand or do anything else with. So use it like it's meant to, learn how to use the functions that work with your thermal printer and then write your own code to do it.

If you don't understand an example then you shouldn't be using it. If it has lines in it and you don't know what they are for, then go study up and figure that out first.

What would be a better substitute? How about nothing. You don't want to lock the board up. They probably did that in the example to keep it from spamming the same thing out over and over. They probably just wanted it to run once and lock up. Unless locking the code up is what you want to do, then you need to take away the functions that make the printer work and leave the rest of that code behind.

Totally offensive post removed and OP banned a week for his effort.

HI,
When the OP comes back..
Look at
switch.. case instead of a lot of if statements.

https://www.arduino.cc/reference/en/language/structure/control-structure/switchcase/

Tom.. :slight_smile:

Delta_G:
If you don't understand an example then you shouldn't be using it. If it has lines in it and you don't know what they are for, then go study up and figure that out first.

As much as I agree with that, I'm afraid our beloved Arduinos wouldn't have ever existed if everyone followed that logic :).

"CTR+C and CTR+V, and a programmer is thee" (translated) became the motto of our local Arduino dealer

ondsinet:
As much as I agree with that, I'm afraid our beloved Arduinos wouldn't have ever existed if everyone followed that logic :).

I didn't say you can never use it. Just that you need to do a little study first. And that is valid. For example, look at all the threads where someone has tried to use an example and has no clue how it works. They NEVER get very far.

I give you an alternative view. The Arduino and all of this only exists because a few of us are willing to go do that reading and learning to try to understand those examples and sit on this forum trying to fix code for all the lazy sobs that refuse to. If it weren't for the few who do actually put in the effort to learn, then none of this would exist because all the n00bs would crash out on their first attempt when they tried to make up their own syntax based on some half-assed example.