How do i code this correctly?

I have a thermal printer, also a force resistant sensor

using the coding from the library i thought it would go something like this

if (fsrReading < 10) {
  printer.justify('L');  
  printer.println("print word");

  }  else if (fsrReading > 10) {
     printer.justify('L');  
  printer.println("print word2");
        }

It’s probably going to be completely wrong as i’m new to all this.

if (fsrReading < 10) {
  printer.justify('L');  
  printer.println("print word");

  }  else if (fsrReading > 10) {

What happens if fsrReading is exactly 10?

using the coding from the library i thought it would go something like this

And? What happened?

I didn’t think of that, i have no idea.

if (fsrReading < 10) {
  printer.justify('L');  
  printer.println("print word");

  }  else if (fsrReading > 9) {

Would that work better?

In response to the second question

printertest.cpp: In function ‘void setup()’:
printertest.pde:-1: error: ‘fsrVoltage’ was not declared in this scope

I get that error when i put the code in… the full code is as follows

#if ARDUINO >= 100
 #include "SoftwareSerial.h"
#else
 #include "NewSoftSerial.h"
#endif
#include "Thermal.h"
#include "adalogo.cpp"
#include "adaqrcode.cpp"

int printer_RX_Pin = 2;  // this is the green wire
int printer_TX_Pin = 3;  // this is the yellow wire
int fsrAnalogPin = 0; // FSR is connected to analog 0

Thermal printer(printer_RX_Pin, printer_TX_Pin);



void setup(){
  Serial.begin(9600);
  

  printer.begin();

 if (fsrReading < 10) {
  printer.justify('L');  
  printer.println("print word");

  }  else if (fsrReading < 200) {
     printer.justify('L');  
  printer.println("print word2");
        }

  printer.sleep(); //Tell printer to sleep. MUST call wake before printing again, even if reset
  printer.wake(); //Wake printer.
  
  printer.setDefault(); //set printer to defaults. ****WILL FEED SEVERAL LINES WHEN CALLED***
}

void loop(){
  
  
}

Would that work better?

if(fsrReading > 10)
{
  // It is...
}
else
{
   // It is not...
}

printertest.cpp: In function 'void setup()': printertest.pde:-1: error: 'fsrVoltage' was not declared in this scope

So, where is fsrVoltage (or fsrReading, for that matter) declared and valued?

If i knew i don't think i'd be in this predicament, like i said i'm completely new, i thought it'd work the same way as some other coding languages do but clearly not.

I think i copied the wrong error, this is the error i'm getting, there is no voltage just reading

printertest2.cpp: In function 'void setup()':
printertest2:30: error: 'fsrReading' was not declared in this scope

But as i said, i don't know where to declare or value it.

i thought it'd work the same way as some other coding languages do but clearly not.

What other languages allow you to make up variables on the fly?

What other languages allow you to assume that a variable like fsrReading will be bound, without explicitly saying so, to the state of some piece of hardware?

You need to declare fsrReading as a global int. As such, it will be valued automatically, with a value appropriate for it's type (0 in the case of ints).

In setup() or loop(), where you use fsrReading, you need to assign it a value:

fsrReading = analogRead(fsrPin);

Make sure that you declare and value (the default won't work) fsrPin (it's where you connect the fsr).

Thank got it printing again, thank you! I'm new to this, i didn't realise it had to be declared at the top.