Arduino DUE - DAC0 and I2C 16x2 LCD

Hello

I work project with Arduino DUE. I want with DAC0 create sin wave and print
frequency to the 16x02 LCD.
DAC0 works great (get sin wave) until I add lcd.print to the code. Then DAC does not work properly. I dont get any wave.

help please:)

Code:

#include <LiquidCrystal_I2C.h>

#include “Waveforms.h”

#define oneHzSample 1000000/maxSamplesNum // sample for the 1Hz signal expressed in microseconds
LiquidCrystal_I2C lcd(0x27,16,2);

int wave0 =0;
int wave1 = 0;
int i = 0;
int sample;
int t_sample;
int input;
int state;

void setup() {
lcd.clear();
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(2,0);
lcd.print(“HELLO”);
delay(2000);
lcd.clear();

analogWriteResolution(12); // set the analog output resolution to 12 bit (4096 levels)
analogReadResolution(12); // set the analog input resolution to 12 bit

}

void loop() {
input=analogRead(A0);
if(input>1000)
{
state=100;

}
else
{
state=50;

}
freq();
izpis();

}

void freq()
{
// Read the the potentiometer and map the value between the maximum and the minimum sample available
// 1 Hz is the minimum freq for the complete wave
// 170 Hz is the maximum freq for the complete wave. Measured considering the loop and the analogRead() time
t_sample = map(state, 0, 4095, 0, oneHzSample);
sample = constrain(t_sample, 0, oneHzSample);

analogWrite(DAC0, waveformsTable[wave0]); // write the selected waveform on DAC0
_ analogWrite(DAC1, waveformsTable[wave1]); // write the selected waveform on DAC1_
* i++;*
* if(i == maxSamplesNum) // Reset the counter to repeat the wave*
* i = 0;*
* delayMicroseconds(sample); // Hold the sample value for the sample time*
}
void izpis()
{
* if(input>1000)*
{
* lcd.setCursor(2,0);*
* lcd.print(“Frekvenca 71 Hz”);*

}
else
{
lcd.setCursor(2,0);
* lcd.print(“Frekvenca 38 Hz”);*

}

}

LCD writes are relatively slow. Added to that is writing (the same thing) to the LCD every time through loop() will really slow execution. You could improve things by using millis() or micros() for timing sampling insead of delays. See the beginner's guide to millis(). Then you can print to the LCD berween samples thus LCD printing will have less impact on timing.

Read the how to use this forum-please read sticky to see how to post code so that the forum software does not mess it up.
Remove unnecessary white space.
Run auto format on the code before posting.