I cannot understand what is wrong with my code (probably because I am a newbie) and I was wondering whether there is someone who could help me with making it WORK. I get the same
error each time: 'draw' was not declared in this scope. Maybe it has something to do with global variables. ![]()
//Include the graphics library.
#include "U8glib.h"
#include <Wire.h>
//Initialize display.
U8GLIB_SSD1306_128X32 u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_DEV_0);
void setup(void)
{
//Set font.
u8g.setFont(u8g_font_unifont);
Serial.begin(9600);
}
void loop(void)
{
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage1 = sensorValue * (5.0 / 1023.0);
// print out the value you read:
Serial.println((float) voltage1);
// read the input on analog pin 0:
int sensorValue2 = analogRead(A1);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage2 = sensorValue2 * (5.0 / 1023.0);
// print out the value you read:
Serial.println((float) voltage2);
float val0 = analogRead(A3);
float mv = ( val0 / 1024.0) * 5000;
float tmp1 = mv / 10;
float farh = (tmp1 * 9) / 5 + 32;
Serial.print("TEMPRATURE = ");
Serial.print((float) tmp1);
Serial.print("*C");
Serial.println();
delay(1000);
/* uncomment this to get temperature in farenhite
Serial.print("TEMPRATURE = ");
Serial.print(farh);
Serial.print("*F");
Serial.println();
*/
float val5 = analogRead(A4);
float mv5 = ( val5 / 1024.0) * 5000;
float tmp2 = mv5 / 10;
float farh5 = (tmp2 * 9) / 5 + 32;
Serial.print("TEMPRATURE = ");
Serial.print((float) tmp2);
Serial.print("*C");
Serial.println();
delay(1000);
/* uncomment this to get temperature in farenhite
Serial.print("TEMPRATURE = ");
Serial.print(farh);
Serial.print("*F");
Serial.println();
*/
float val6 = analogRead(A5);
float mv6 = ( val6 / 1024.0) * 5000;
float tmp3 = mv6 / 10;
float farh6 = (tmp3 * 9) / 5 + 32;
Serial.print("TEMPRATURE = ");
Serial.print((float) tmp3);
Serial.print("*C");
Serial.println();
delay(1000);
u8g.firstPage();
do {
draw();
} while (u8g.nextPage());
//Delay before repeating the loop.
delay(50);
}
void draw(void)
{
//Write text. (x, y, text)
// u8g.drawStr(0, 0, "U 1" + ((float) voltage1));
u8g.drawStr(0, 10, "U 2" + ((float) voltage2));
u8g.drawStr(0, 20, "T 1" + (tmp1));
u8g.drawStr(0, 30, "T 2" + (tmp2));
u8g.drawStr(0, 40, "T 3" + (tmp3));
}