Hi all,
I'm currently working on my very first "real" Arduino project!
I recently made a spud gun with an electronic ignition, and I would like to use the Arduino to take care of the controls.
I connected the Arduino to a 16x1 LCD and to a transistor that drives a small fan.
The idea is: the display constantly displays the word "standby" unless the button is pressed, in which case the fan starts running for a couple of seconds.
In the future, another button and transistor circuit will be added to switch on the ignition.
Although the code and circuit work at the moment, I don't find them particularly elegant.
Especially the fact that the button press only gets detected when the code loop starts bothers me, since if I were to insert some long routines in the ELSE-statement, I would have to wait for them to finish before another button press is detected...
Any ideas on how to improve this?
Thanks!
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int loopCount=0;
int dispDeel=2;
int buttonState=0;
const int transPin=6;
const int buttonPin=7;
void setup(){
lcd.begin(16, 2);
pinMode(transPin, OUTPUT); // The pin that switches the transistor off or on
pinMode(buttonPin, INPUT); // The pin that detects the button press
lcd.setCursor(0, 0); // Puts cursor on leftmost position
lcd.print("Standby "); // Shows the word STANDBY after starting up
}
void loop(){
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) { // If the button is pressed
for (int countE=0; countE < 3; countE++) { // This loops the ventilation sequence for three times (increase number for longer ventlation)
digitalWrite(transPin, HIGH); // Turn on the fan
dispDeel=2;
lcd.setCursor(0, 0);
lcd.print("Ventiler"); // Puts the first 8 characters of the word "ventileren" on the screen
lcd.setCursor(0, 1); // This is because it's a 16x1 fan; this puts text on the right half of the LCD
lcd.print("en ");
delay(400);
for (int loopCount = 0; loopCount < 3; loopCount++) { // A small loop to display a sequence of 3 flashing dots
lcd.setCursor(dispDeel, 1);
lcd.print(".");
delay(900);
dispDeel++;
}
}
lcd.setCursor(0, 0);
lcd.print("Standby "); // Puts the word STANDBY on the screen after the ventlation sequence has finished
lcd.setCursor(0, 1);
lcd.print(" "); // Clears the right half of the screen
}
else {
digitalWrite(transPin, LOW); // This makes sure the fan is off when the button is not pressed
}
}
