Okay,
So, I have spent a bunch of time trying to understand how I can implement the code that you showed me when I realized the issue it was probably going to create.
When the data is coming in, it comes in with these types of formats based on pressure units at a rate of 3 times per second.
Its always 21 characters.
" 9.08, PSI"
" 0.1, inH2O"
" 0.01, inHg"
" 10.5, kpa"
" 0.000, Bar"
" 1., mBar"
So basically as it sits (and if you'll take a peak at the code), It reads each byte (as long as there are more than 20 bytes available in the buffer, assigns it to a variable, and then prints only the ones that I want so that it fits nicely on the 16x2 SerLCD I am using.
Right now, it works perfectly without any flaw.
The code could be so simplified I'm sure, however it made it easy to picture what was going to happen for the output.
The reason I am asking about the converting bytes to a string value is because I want to be able to compare the numerical value of the pressure, say 10.00 psi to a stored number of say 8. This way I can have it print something else out like "high pressure alarm" or whatever.
Forgive me needing my hand held through this, I am trying, but some of the syntax isn't exactly clicking with me. Check out my code, I
m sure it's very easy to implement.
Thanks again folks.
Aaron
int ib1 = 0;
int ib2 = 0;
int ib3 = 0;
int ib4 = 0;
int ib5 = 0;
int ib6 = 0;
int ib7 = 0;
int ib8 = 0;
int ib9 = 0;
int ib10 = 0; // half of these varaiables are the "int" type for when I was recently messing with trying to get the adding bytes to string thing working.
char ib11 = 0;
char ib12 = 0;
char ib13 = 0;
char ib14 = 0;
char ib15 = 0;
char ib16 = 0;
char ib17 = 0;
char ib18 = 0;
char ib19 = 0;
char ib20 = 0;
char ib21 = 0;
char ib22 = 0;
void setup()
{
Serial.begin(9600);
Serial.print(0x7C, BYTE); //special character
Serial.print(0x12, BYTE); //reset character
delay(50);
Serial.print(0x7C, BYTE); //backlight ON
delay(10);
Serial.print(128, BYTE);
delay(500);
Serial.print(0x7C, BYTE); //backlight ON
delay(10);
Serial.print(157, BYTE);
delay(500);
Serial.print(0xFE, BYTE); //command flag
delay(10);
Serial.print(0x01, BYTE); //clear command.
delay(1000);
}
void loop(){
checkincoming();
delay(10);
setposition();
delay(10);
setposition();
printing();
}
void setposition(){
Serial.print(0xFE, BYTE); //command flag
delay(10);
Serial.print(128, BYTE); //position
delay(10);
}
void checkalarm() {
// This check alarm section is only in here as a start, I obviously haven't finished it and dont even have the program calling to it anyway.
if (highal < ib8) {
Serial.print(0xFE, BYTE); //command flag
delay(10);
Serial.print(192, BYTE); //position
delay(10);
Serial.println(" High Alarm!");
}
else {
Serial.print(0xFE, BYTE); //command flag
delay(10);
Serial.print(192, BYTE); //position
delay(10);
Serial.println(" ");
}
}
void printing() {
Serial.print(ib1, BYTE);
Serial.print(ib6, BYTE);
Serial.print(ib7, BYTE);
Serial.print(ib8, BYTE);
Serial.print(ib9, BYTE);
Serial.print(ib10, BYTE);
Serial.print(ib12, BYTE);
Serial.print(ib17, BYTE);
Serial.print(ib18, BYTE);
Serial.print(ib19, BYTE);
Serial.print(ib20, BYTE);
Serial.print(ib21, BYTE);
Serial.flush();
delay(10);
}
void checkincoming(){
if (Serial.available() > 20){
delay(10);
ib1 = Serial.read();
ib2 = Serial.read();
ib3 = Serial.read();
ib4 = Serial.read();
ib5 = Serial.read();
ib6 = Serial.read();
ib7 = Serial.read();
ib8 = Serial.read();
ib9 = Serial.read();
ib10 = Serial.read();
ib11 = Serial.read();
ib12 = Serial.read();
ib13 = Serial.read();
ib14 = Serial.read();
ib15 = Serial.read();
ib16 = Serial.read();
ib17 = Serial.read();
ib18 = Serial.read();
ib19 = Serial.read();
ib20 = Serial.read();
ib21 = Serial.read();
ib22 = Serial.read();
delay(10);
}
else
{
checkincoming();
}
}