Hi,
I've nearly finished my plant watering project, but I'm not able to solve the last problem I'm experiencing.
I would like to place a text in a smaller font than the other one for the output values. When I upload the code on my Arduino Uno, it runs well for some miliseconds, then the "Plant Redeemer" text switches back from standard small to "FreeMono9pt7b". If I don't use "FreeMono9pt7b", all text is small, but I only want the headline to show up in small font. Where is my mistake? :o
#include <Adafruit_GFX.h> // Include core graphics library for the display
#include <Adafruit_SSD1306.h> // Include Adafruit_SSD1306 library to drive the display
Adafruit_SSD1306 display(128, 64); // Create display
#include <Fonts/FreeMono9pt7b.h> // Add a custom font
int Relay0 = 10;
int Relay1 = 11;
int Relay2 = 12;
int Olive;
int Papyrus;
int Bonsai;
int limit0 = 330;
int limit1 = 300;
int limit2 = 430;
#define soilSensor_Olive A0
#define soilSensor_Papyrus A1
#define soilSensor_Bonsai A2
// 'Plant_Redeemer', 16x20px
const unsigned char PlantRedeemer [] PROGMEM = {
0x06, 0x00, 0x07, 0x80, 0x07, 0x80, 0x07, 0xc0, 0x07, 0xc0, 0x03, 0xc6, 0xfb, 0xdf, 0x7d, 0xbe,
0x3c, 0x3c, 0x1c, 0x30, 0x00, 0x00, 0x01, 0x80, 0x01, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80,
0x00, 0x80, 0x00, 0x00, 0x07, 0xf0, 0x0f, 0xf0
};
void setup()
{
Serial.begin(9600);
pinMode (10,OUTPUT); //Set pin 10 as output for the relay
pinMode (11,OUTPUT); //Set pin 11 as output for the relay
pinMode (12,OUTPUT); //Set pin 12 as output for the relay
pinMode(A0,INPUT); //Set pin A0 as analog input for a capacitive soil moisture sensor #1
pinMode(A1,INPUT); //Set pin A1 as analog input for a capacitive soil moisture sensor #2
pinMode(A2,INPUT); //Set pin A2 as analog input for a capacitive soil moisture sensor #3
//OLED********************************
delay(100); // This delay is needed to let the display to initialize
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Initialize display with the I2C address of 0x3C
display.clearDisplay(); // Clear the buffer
display.setTextColor(WHITE); // Set color of the text
display.setRotation(0); // Set orientation. Goes from 0, 1, 2 or 3
display.setTextWrap(false); // By default, long lines of text are set to automatically “wrap” back to the leftmost column.
// To override this behavior (so text will run off the right side of the display - useful for
// scrolling marquee effects), use setTextWrap(false). The normal wrapping behavior is restored
// with setTextWrap(true).
display.dim(0); //Set brightness (0 is maximun and 1 is a little dim)
/*display.drawBitmap(1,1,PlantRedeemer, 16, 20, WHITE);
display.setTextSize(1);
display.setCursor(22, 2);
display.print("Plant");
display.setCursor(22, 15);
display.print("Redeemer");*/
////OLED********************************
}
void loop()
{
int Olive = analogRead(soilSensor_Olive);
int Papyrus = analogRead(soilSensor_Papyrus);
int Bonsai = analogRead(soilSensor_Bonsai);
Serial.print("Feuchtigkeitswert Olive:");
Serial.println(Olive);
delay(200);
Serial.print("Feuchtigkeitswert Papyrus:");
Serial.println(Papyrus);
delay(200);
Serial.print("Feuchtigkeitswert Bonsai:");
Serial.println(Bonsai);
delay(200);
//OLED********************************
display.clearDisplay();
display.drawBitmap(1,1,PlantRedeemer, 16, 20, WHITE);
display.setTextSize(1);
display.setCursor(22, 2);
display.print("Plant");
display.setCursor(22, 15);
display.print("Redeemer");
display.setTextSize(0);
display.setFont(&FreeMono9pt7b);
display.setCursor(0, 34);
display.print("Olive: ");
display.println(Olive);
display.setCursor(0, 48);
display.print("Papyrus:");
display.println(Papyrus);
display.setCursor(0, 62);
display.print("Bonsai: ");
display.println(Bonsai);
display.display();
////OLED*******************************
if (Olive<limit0)
{
digitalWrite(10,LOW);
}
else
{
digitalWrite(10,HIGH);
}
delay(400);
//***********************************************************
if (Papyrus<limit1)
{
digitalWrite(11,LOW);
}
else
{
digitalWrite(11,HIGH);
}
delay(400);
//***********************************************************
if (Bonsai<limit2)
{
digitalWrite(12,LOW);
}
else
{
digitalWrite(12,HIGH);
}
delay(400);
}