Characters Special

I can’t get my custom character to work. What can I do to fix this?
this is my code…

#include <LiquidCrystal.h>


byte warning[8] =
{
 B00100,
 B01010,
 B10101,
 B10101,
 B10001,
 B10101,
 B10001,
 B11111
};


LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int button_pin = 6;
int trigger_pin = 7;
int echo_pin = 9;
int buzzer_pin = 10;
int time;
int distance;

void setup () {
 Serial.begin(9600);
 lcd.begin(16, 2);
 lcd.createChar(warning, 8);
 pinMode(button_pin, INPUT_PULLUP);
 pinMode(trigger_pin, OUTPUT);
 pinMode(echo_pin, INPUT);
 pinMode(buzzer_pin, OUTPUT);
 lcd.print("  ...ARMING...");
 delay(5000);
 lcd.clear();
 lcd.setCursor(4,0);
 lcd.write(8);
 lcd.setCursor(5,0);
 lcd.print("WARNING");
 lcd.setCursor(5,1);
 lcd.write(8);
 lcd.setCursor(6,1);
 lcd.print("ARMED");
}

void loop () {
 digitalWrite(trigger_pin, HIGH);
 delayMicroseconds(10);
 digitalWrite(trigger_pin, LOW);
 time = pulseIn(echo_pin, HIGH);
 distance = (time * 0.034) / 2;
 if (distance >= 10) {
   lcd.clear();
   lcd.setCursor(0,0);
   lcd.print("NICHOLAS IT IS");
   lcd.setCursor(0,1);
   lcd.print("TIME TO WAKE UP!");
   do {
     digitalWrite(buzzer_pin, HIGH);
   } while (digitalRead(button_pin) == HIGH);
   } else {
   //nothing
 }
 if (digitalRead(button_pin) == LOW) {
   digitalWrite(buzzer_pin, LOW);
   lcd.clear();
   lcd.setCursor(0,0);
   lcd.print("  !!!WARNING!!!");
   lcd.setCursor(0,1);
   lcd.print("   !!!ARMED!!!");
 }
}

You have provided no information that lets us help you. Does not work is a worthless description of a problem. What does the code actually do? How is that different from what you want it to do?

@Nicholas_Pfeiffer

TOPIC SPLIT
DO NOT HIJACK / NECRO POST !

Could you take a few moments to Learn How To Use The Forum.
Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

The parameters to this method
lcd.createChar(warning, 8);are wrong.
Here is the Arduino reference page
https://www.arduino.cc/en/Reference/LiquidCrystalCreateChar

Another thing to keep in mind is that there is a "feature" (I call it a bug) in the createChar() code in the LIquidCrystal library.
The issue is that the code puts the LCD into CGRAM mode to send the custom character bytes to the LCD but then leaves it in CGRAM mode. It does not put the LCD back into DDRAM mode before returning.
This means that any further attempts to write characters to the display will write the data to the CGRAM an not to the display, which is essentially corrupting the CGRAM with garbage custom characters.

You have two options

  • work around it by doing a clear() or setCursor() after calling createChar()
  • use the hd44780 library and hd44780_pinIO class which does not have this issue.

--- bill