Hi,
I would like to use a capacitative touch sensor to power a message on an LCD.
Step one: Wired and tested LCD screen
Result: working as expected
Step 2: add in capacitative touch
Result: software works, using Serial.print() I can see that one message is being called depending on if I am touching the sensor or not.
Problem: The LCD display does not work as expected. It is very glitchy, displays only "protect me" and I must change the contrast on the screen during it's operation. Eventually I see no message. When it initialises it prints on the LCD screen "32(unidentified charactersProtect me"
What is happening?
#include <LiquidCrystal.h> // includes the LiquidCrystal Library
#include <CapacitiveSensor.h>
// pin 13 sends electrical energy
// pin 11 senses senses a change
CapacitiveSensor capSensor = CapacitiveSensor(13, 11);
// threshold for turning A SAYING ON
int threshold = 1000;
LiquidCrystal lcd(1, 2, 4, 5, 6, 7); // Creates an LC object. Parameters: (rs, enable, d4, d5, d6, d7)
void setup() {
Serial.begin(9600);
lcd.begin(16,2); // Initializes the interface to the LCD screen, and specifies the dimensions (width and height) of the display }
}
//-----sayings------//
void tender() {
lcd.print("It is in your");
delay(2000);
lcd.clear();
// lcd.print("self interest");
// delay(1500);
// lcd.clear();
//
// lcd.print("to be");
// delay(1500);
// lcd.clear();
//
// lcd.print("very tender.");
// delay(3000);
// lcd.clear();
};
void want(){
lcd.print("Protect me");
delay(2000);
lcd.clear();
//
// lcd.print("from what");
// delay(1500);
// lcd.clear();
//
// lcd.print("I want.");
// delay(1500);
// lcd.clear();
};
void loop() {
//tender();
//want();
long sensorValue = capSensor.capacitiveSensor(30);
if (sensorValue > threshold) {
tender();
Serial.println("printing tender as the sensor value is ");
Serial.println(sensorValue);
}
else {
want();
Serial.print("printing want as the sensor value is ");
Serial.println(sensorValue);
}
}
