When you get a no signal message just don't update the LCD
If I do that, the LCD is blank at those moments... I don't want that to happen...
You must be pushing data to the LCD then as they don't update unless you send something to it. Remove this code and the LCD will keep displaying the last update
else
lcd.clear();
lcd.print("NO SIGNAL - B1");
Done that, but the LCD is blank when I don't have reception...
So, after my logic, I have done this: Defined a variable.
int oldtempb1;
oldtempb1=buf[i]; // this is set right after reception code.
// and then, instead of NO SIGNAL...
lcd.print(oldtempb1);
This return me some numbers, but not the actual temperature. Where is the problem?
Adrian.
This return me some numbers, but not the actual temperature. Where is the problem?
In the code you didn't post.
The value in buf[0] is what? I thought it was the letter 'B'. Why do you think that making a copy of the letter "B" is useful? How will the copy of the letter 'B' ever be different from the letter 'B'?
Yes. You are right ... Buf[0] buf[1] buf[2] are "B1 " , I needed to change the condition, because on LCD appears something like this, for example: "B1 - 23,50 C"
So now, after this code:
for (i = 3; i < buflen; i++)
{
lcd.write(buf[i]);
This show's me only the temperature. wich is right and correct.
NOW i have to convert buf [ i ] - (only the number part) back to a float... so I can display this float during the NO SIGNAL moments.
I am not sure if I make myself clear.
Thanks.
NOW i have to convert buf [ i ] - (only the number part) back to a float.
Why? You have the float that you converted to a string. Why do you need to convert the string back to a float?
Is this snippet on the senders or on the receivers? If it is on the receiver, and you don't have the original float on the receiver, then converting the string BACK TO a float doesn't make sense. Converting the string TO a float does.
If buf is NULL terminated, you can start the string to float conversion at other than the start of the array by using
float valInStg = atof(&buf[3]);
PaulS:
Is this snippet on the senders or on the receivers? If it is on the receiver, and you don't have the original float on the receiver, then converting the string BACK TO a float doesn't make sense.
...
Yeap, is on the receiver, where I don't have the original float.
Ok, if conversion back does not make sense, then how can I store this value, for later use (on the receiver), when I don't have reception.
Thanks.
Ok, if conversion back does not make sense
If you convert a float to a string, you can convert the string back to the float.
If you have just the string, you can convert the string to a float.
I showed how in reply 26.
It works like a charm!
Needed two float variables to achieve my goal.
I'l post my "final" code for the receiver, maybe someone will use it:
#include <OneWire.h>
#include <LiquidCrystal.h>
#include <DallasTemperature.h>
#include <VirtualWire.h>
#define ONE_WIRE_BUS 8
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int i;
float oldtmpc1;
float memoldtmpc1;
float oldtmpb1;
float memoldtmpb1;
byte signalbar[8] = {
B00000000,
B00000001,
B00000011,
B00000111,
B00001111,
B00011111,
B00011111,
B00011111,
};
void setup() {
// Serial.begin(9600);
sensors.begin();
lcd.begin(16,2);
lcd.createChar(0, signalbar);
lcd.clear();
pinMode(3, OUTPUT);
analogWrite(3, 0);
Serial.begin(9600);
vw_set_ptt_inverted(true);
vw_set_rx_pin(13); //Sets pin D13 as the RX Pin
vw_setup(2000); // Bits per sec
vw_rx_start(); // Start the receiver PLL running
}
void loop() {
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if( vw_get_message(buf, &buflen) )
{
if (buf[0]=='B')
{
if (buf[1]=='1')
{
float oldtmpb1 = atof(&buf[3]);
memoldtmpb1 = oldtmpb1;
lcd.setCursor(0, 0);
lcd.print("BEDROOM 1:");
lcd.setCursor(3,1);
for (i = 3; i < buflen; i++)
{
lcd.write(buf[i]);
}
lcd.print((char)223);
lcd.print("C ");
lcd.write(byte(0));
delay(2000);
lcd.clear();
}
}
else
lcd.clear();
lcd.print("BEDROOM 1:");
lcd.setCursor(3,1);
lcd.print(" ");
lcd.print(memoldtmpb1);
lcd.print((char)223);
lcd.print("C");
delay(2000);
lcd.clear();
}
if( vw_get_message(buf, &buflen) )
{
if (buf[0]=='C')
{
if (buf[1]=='1')
{
float oldtmpc1 = atof(&buf[3]);
memoldtmpc1 = oldtmpc1;
lcd.clear();
lcd.print(" BEDROOM 2:");
lcd.setCursor(3,1);
for (i = 3; i < buflen; i++)
{
lcd.write(buf[i]);
}
lcd.print((char)223);
lcd.print("C ");
lcd.write(byte(0));
delay(3000);
lcd.clear();
}
}
else
lcd.clear();
lcd.print(" BEDROOM 2: ");
lcd.setCursor(3,1);
lcd.print(" ");
lcd.print(memoldtmpc1);
lcd.print((char)223);
lcd.print("C");
delay(2000);
lcd.clear();
}
}
Thanks again PaulS. Your code sugestions always worked!
Best regards,
Adrian