else if (val0 = 0)
I doubt you meant that. An assignment statement evaluates to the assigned value. '0' will never be true. '==' perhaps?
else if (val0 = 0)
I doubt you meant that. An assignment statement evaluates to the assigned value. '0' will never be true. '==' perhaps?
gfvalvo, true that == is what should be there. thanks
You also have two variables named 'val0'. One global, one local. It may not be your problem, but it's really poor coding style.
Yes, i spotted that, this is due to that different option we run across so at some stage things get mixed up
#include "U8glib.h"
#include <OneWire.h>
#include <DallasTemperature.h>
int anPin0 = A0;
int anPin1 = A1;
int val0 = 0;
int val1 = 0;
int oldvalue = 0;
byte hysteresis = 1;
// Create a Onewire Referenca and assign it to pin 10 on your Arduino
OneWire oneWire(10);
// declare as sensor referenec by passing oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// declare your device address
// YOUR ADDRESS GOES HERE!!!!
DeviceAddress tempSensor = {0x28, 0xFF, 0x2B, 0x45, 0x4C, 0x04, 0x00, 0x10};
// A Variable to hold the temperature you retrieve
float tempC;
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_DEV_0 | U8G_I2C_OPT_NO_ACK | U8G_I2C_OPT_FAST); // Fast I2C / TWI
void draw(void) {
// graphic commands to redraw the complete screen should be placed here
// Water Temp Left Head
u8g.setFont(u8g_font_10x20);
u8g.setPrintPos(0, 35);
u8g.print("TEMP:");
u8g.setPrintPos(50, 35);
u8g.print(val0);
u8g.setPrintPos(105, 35);
u8g.setFont(u8g_font_5x8);
u8g.print("Left");
if (val1 > 100)
{
u8g.drawCircle(83, 22, 1.5);
u8g.setFont(u8g_font_10x20);
u8g.setPrintPos(85, 35);
u8g.print("C");
}
else if (val1 > 10)
{
u8g.drawCircle(73, 22, 1.5);
u8g.setFont(u8g_font_10x20);
u8g.setPrintPos(75, 35);
u8g.print("C");
}
else if (val1 < 10)
{
u8g.drawCircle(63, 22, 1.5);
u8g.setFont(u8g_font_10x20);
u8g.setPrintPos(65, 35);
u8g.print("C");
}
// Water Temp Right Head
u8g.setFont(u8g_font_10x20);
u8g.setPrintPos(0, 60);
u8g.print("TEMP:");
u8g.setPrintPos(50, 60);
u8g.print(val0);
u8g.setPrintPos(105, 60);
u8g.setFont(u8g_font_5x8);
u8g.print("Right");
if (val1 > 100)
{
u8g.drawCircle(83, 47, 1.5);
u8g.setFont(u8g_font_10x20);
u8g.setPrintPos(85, 60);
u8g.print("C");
}
else if (val1 > 10)
{
u8g.drawCircle(73, 47, 1.5);
u8g.setFont(u8g_font_10x20);
u8g.setPrintPos(75, 60);
u8g.print("C");
}
else if (val1 < 10)
{
u8g.drawCircle(63, 47, 1.5);
u8g.setFont(u8g_font_10x20);
u8g.setPrintPos(65, 60);
u8g.print("C");
}
// Eng Oil Pressure
u8g.setFont(u8g_font_10x20);
u8g.setPrintPos(0, 15);
u8g.print("OIL:");
u8g.setPrintPos(50, 15);
u8g.print(val1); // change when you add pressure sensor
if (val1 > 100)
{
u8g.setPrintPos(83, 8);
u8g.setFont(u8g_font_5x8);
u8g.print("Psi");
}
else if (val1 > 10)
{
u8g.setPrintPos(73, 8);
u8g.setFont(u8g_font_5x8);
u8g.print("Psi");
}
else if (val1 < 10)
{
u8g.setPrintPos(63, 8);
u8g.setFont(u8g_font_5x8);
u8g.print("Psi");
}
}
void setup(void) {
// start serial port
Serial.begin(9600);
// set the resolution to 9 bit - Valid values are 9, 10, or 11 bit.
sensors.setResolution(tempSensor, 9);
// confirm that we set that resolution by asking the DS18B20 to repeat it back
Serial.print("Sensor Resolution: ");
Serial.println(sensors.getResolution(tempSensor), DEC);
Serial.println();
// flip screen, if required
// u8g.setRot180();
}
void loop(void)
{
// Tell the Sensor to Measure and Remember the Temperature it Measured
sensors.requestTemperaturesByAddress(tempSensor); // Send the command to get temperatures
// Get the temperature that you told the sensor to measure
tempC = sensors.getTempC(tempSensor);
// Serial.print("Temp C: ");
// Serial.print(tempC,4); // The four just increases the resolution that is printed
// Serial.print(" Temp F: ");
// The Dallas Temperature Control Libray has a conversion function... we'll use it
// Serial.println(DallasTemperature::toFahrenheit(tempC),4);
// delay(1000);
val0 = analogRead(anPin0);
val1 = analogRead(anPin0);
Serial.print(val0);
Serial.print(" ");
Serial.println(val1);
val0 = map(val0, 0, 1023, 0, 120);
val1 = map(val1, 0, 1023, 0, 150);
if (oldvalue != val0)
{
if (val0 > oldvalue + hysteresis or val0 < oldvalue - hysteresis)
{
(oldvalue = (val0 - 1));
updateOled();
}
else if (val0 == 0)
{
oldvalue = 0;
updateOled();
}
}
delay(100);
}
void updateOled(void)
{ // picture loop
u8g.firstPage();
do {
draw();
} while ( u8g.nextPage() );
}