I'm currently working on a stroboscope project right now, which features a Duty and Delay cycle.
The compiling works already and everything, but my problem is, that the LCD shows random characters instead of the variables.
I mean, the other thing of the code as lcd.write(); work fine, but when I try do display the variables, which are updated every 500ms, my display shows ASCII characters. I've read that it can be that the arduino is sending the ASCII numbers instead of the characters I want to display, but how can I fix it?
Here is the code, I also marked the region where the printing of the variables happens:
#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int period = 500 ;
unsigned long time_now = 0;
#define mosfet 13
#define pot A0
#define pot1 A1
int wait = 0;
int wait1 = 1;
void setup() {
pinMode(5,OUTPUT);
pinMode(A0,INPUT);
pinMode(A1,INPUT);
Serial.begin(250000);
lcd.begin(16, 2);
lcd.setCursor(2, 0);
lcd.write("Initializing"), lcd.setCursor(4, 1), lcd.write("system ");
delay(333);
lcd.write("Initializing"), lcd.setCursor(4, 1), lcd.write("system. ");
delay(333);
lcd.write("Initializing"), lcd.setCursor(4, 1), lcd.write("system.. ");
delay(333);
lcd.write("Initializing"), lcd.setCursor(4, 1), lcd.write("system... ");
delay(333);
lcd.write("Initializing"), lcd.setCursor(4, 1), lcd.write("system ");
delay(333);
lcd.write("Initializing"), lcd.setCursor(4, 1), lcd.write("system. ");
delay(333);
lcd.write("Initializing"), lcd.setCursor(4, 1), lcd.write("system.. ");
delay(333);
lcd.write("Initializing"), lcd.setCursor(4, 1), lcd.write("system... ");
delay(333);
lcd.write("Loading"), lcd.setCursor(3, 1), lcd.write("Oscillator. ");
delay(333);
lcd.write("Loading"), lcd.setCursor(3, 1), lcd.write("Oscillator.. ");
delay(333);
lcd.write("Loading"), lcd.setCursor(1, 1), lcd.write("MOSFET system... ");
delay(667);
lcd.write("Loading"), lcd.setCursor(2, 1), lcd.write("Serial Debug ");
delay(333);
lcd.write("Loading"), lcd.setCursor(2, 1), lcd.write("Serial Debug. ");
delay(333);
lcd.write("Loading"), lcd.setCursor(2, 1), lcd.write("Serial Debug.. ");
delay(50);
lcd.write("Loading"), lcd.setCursor(1, 1), lcd.write("PWM Modulator... ");
delay(283);
lcd.write("Loading"), lcd.setCursor(1, 1), lcd.write("PWM Modulator ");
delay(333);
lcd.clear();
lcd.setCursor(4, 0), lcd.write("Loading "), lcd.setCursor(3, 1), lcd.write("complete! ");
delay(1200);
lcd.clear();
delay(1000);
lcd.setCursor(2, 1), lcd.write("Starting OS ");
delay(1500);
lcd.clear();
}
void loop() {
while(analogRead(A2) < 550) {
lcd.setCursor(4, 0);
lcd.write("Battery low! ");
lcd.setCursor(2, 1);
lcd.write("Please charge! ");
}
int pRead = analogRead(pot); //begin each loop by reading the position of the pot
int pRead1 = analogRead(pot1);
wait = map(pRead,0,1000,1,200); //map the analog read to a value between 1mS to 200ms
wait1 = map(pRead1,0,1000,1,200);
if(millis() > time_now + period){
time_now = millis();
}
lcd.setCursor(0, 0);
lcd.write("Freq: "), lcd.setCursor(7, 0), lcd.write(wait), lcd.setCursor(12, 0), lcd.write("ms ");
lcd.setCursor(0, 1);
lcd.write("Duty: "), lcd.setCursor(7, 1), lcd.write(wait1), lcd.setCursor(12, 1), lcd.write("ms ");
digitalWrite(mosfet,HIGH); //flash the MOSFET
delay(wait1); //wait for the Duty time
digitalWrite(mosfet,LOW); //shut off the MOSFET
delay(wait); //wait for the Delay time
}