Hello, I'm currently trying to set variables that read the lcd.setCursor (x,y) on a 16x2 LCD setup with Arduino IDE... I need to make the program not only read if a value of (15, 0) top, right corner populates but to react to it and hold it with a 2 second delay once it hits that specific position, then continue on into infinity until it hits again and repeat.
Here's my code ( the overall code HAS to be encompassed in a while loop):
#include <LiquidCrystal.h>
// configure the liquid crystal and Arduino pin connections
// LiquidCrystal(rs, enable, d4, d5, d6, d7)
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
//global variables
int t = 500; // .5 of one second;
int col = 0;
const int speaker = 6;
void setup()
{
Serial.begin(9600);
lcd.begin(16, 2); //starting the LCD as a 16 character, 2 line display
lcd.clear();
}
void loop(){
// (x, 1) lower row
// columns (0,y) through (15, y)
beginning:
while (1) {
for (int randomCol = random (15);;){
int randomRow = random (2);
lcd.setCursor(randomCol, randomRow);
for (int readPositions = (randomCol, randomRow); readPositions == (15,0);){
tone (speaker, 2000, 100);
delay(2000);
lcd.clear();
break;
}
lcd.print("h");
delay (t);
lcd.clear();
goto beginning;
Serial.print (randomCol);
Serial.println (" Column");
Serial.print (randomRow);
Serial.println (" Row");
delay(t);
}}}
It doesn't work to read, and react to the (15,0) value generated at random() so far... how can I solve this?
Halp please?
get rid of the goto *)
activate full compiler errors/warnings in the IDE settings and the compiler will tell you, what line of code is wrong .
you don't have the column/row randoms in an array.
you hold them in separate variables.
Even if the values were in an array - you couldn't use it in this way.
Instead compare these separate variables
if (randomCol==15 && randomRow==0){
// do what ever is needed to do
*) sorry for OT: you are not old enough to use goto on an Arduino.
noiasca:
get rid of the goto *)
activate full compiler errors/warnings in the IDE settings and the compiler will tell you, what line of code is wrong .
you don't have the column/row randoms in an array.
you hold them in separate variables.
Even if the values were in an array - you couldn't use it in this way.
Instead compare these separate variables
if (randomCol==15 && randomRow==0){
// do what ever is needed to do
*) sorry for OT: you are [not old enough](http://www.pbm.com/~lindahl/real.programmers.html) to use goto on an Arduino.
Thanks for the advice, but I did eventually figure it out! And yes, the if statement was best used instead of for loop. I just kept trying to gravitating towards it, because I'm a rusty @ss noob. But I'm working on myself, so it's a process.
Also I'm not old... enough for goto? :o What is... old enough?
Here's the working code for anyone needing to see the troubleshoot:
#include <LiquidCrystal.h>
// configure the liquid crystal and Arduino pin connections
// LiquidCrystal(rs, enable, d4, d5, d6, d7)
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
//global variables
const int speaker = 6;
void setup()
{
Serial.begin(9600);
lcd.begin(16, 2); //starting the LCD as a 16 character, 2 line display
lcd.clear();
}
void loop() {
while (1)
{
int Row = random(2);
int Col = random(16);
if (Row == 0){
lcd.setCursor(Col, 0);
lcd.print("h");
if (Col == 15)
{
tone (speaker, 1000, 50);
delay(1250);
}
delay(500);
lcd.clear();
}
if (Row == 1){
lcd.setCursor(Col, 1);
lcd.print("h");
delay(500);
lcd.clear(); }
}}