Hello,
I'm trying to create a syllogism tester, using an LCD, a potentiometer, and a button. This requires multiple loops that check for the potentiometer position, then check if the button has been pressed. If the buttons has been pressed, it moves onto the next loop that does the same checks, but if it hasn't been pressed, it loops back around to continue checking the potentiometer's position.
One bit of code I've written allows for me to twist the potentiometer and switch between "ALL," "NO," or "SOME" being displayed on the LCD. However, that code does nothing when the button is pressed.
Another bit of code I wrote displays nothing on the LCD, no matter what position the pot is in, but will display "TEST PASSED" when I press the button.
To be clear from the beginning: I believe that, more than anything, this is an issue of figuring out how looping subroutines are made in Arduino's code.
Here is the code which will display text based on the pot's position, but will not move out of that code when a button is pressed:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
const int buttonPin = 10;
const int potPin = A0;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
pinMode(buttonPin, INPUT);
pinMode(potPin, INPUT);
lcd.noAutoscroll();
int buttonState = 0;
}
void loop() {
int buttonState = digitalRead(buttonPin);
for(; buttonState == LOW;)
{
int sensorValue = analogRead(A0);
if (sensorValue < 330)
{
lcd.print("ALL");
}
if ((sensorValue > 330) && (sensorValue < 660))
{
lcd.print("SOME");
}
if (sensorValue > 660)
{
lcd.print("NO");
}
}
lcd.clear();
lcd.print("TEST PASSED");
Here is some code that displays nothing until I press the button, at which point it shows "TEST PASSED.":
#include <LiquidCrystal.h>
int buttonPin = 10;
int potPin = A0;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
pinMode(buttonPin, OUTPUT);
pinMode(potPin, INPUT);
lcd.noAutoscroll();
}
void loop() {
for(;digitalRead(buttonPin) == LOW;);
{
int sensorValue = analogRead(A0);
if (sensorValue < 330)
{
lcd.setCursor(0,0);
lcd.print("ALL ");
}
if ((sensorValue > 330) && (sensorValue < 660))
{
lcd.setCursor(0,0);
lcd.print("SOME");
}
if (sensorValue > 660)
{
lcd.setCursor(0,0);
lcd.print("NO ");
}
}
lcd.clear();
lcd.print("TEST PASSED");
}
I'm pretty sure I'm not using the FOR statement correctly, but I do not know what commands to use to make it display text based on the pot position, check for button press, repeat until the button is pressed.