So, this is what i have come up with so far:
This code works, and does what i want:
//Code for loading screen made by: mrmeval
//TEST med toggle
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
const int ledlcdPin = A0; //LEDpin i UNO
const int ledvideoPin = A1;
const int buttonlcdPin = 11; //Buttonpin in i UNO
const int buttonvideoPin = 10; //Buttonpin in i UNO
int ledState = HIGH;
int buttonState;
int lastButtonState = LOW;
unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
const unsigned long debounceDelay = 50; // the debounce time; increase if the output flickers
byte block[8] =
{
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B00000
};
void setup() {
// set up the LCD's number of rows and columns:
lcd.createChar(7,block);
lcd.begin(16, 2);
//lcd.setCursor(0,7);
delay(10);
// scroll 24 positions (string length) to the left
// to move it offscreen left:
lcd.clear();
lcd.print(" MK-Swe GS-V1 Startar");
for (int positionCounter = 0; positionCounter < 23; positionCounter++) {
// scroll one position left:
lcd.scrollDisplayLeft();
delay(380);
}
lcd.home();
lcd.setCursor(0,1);
for (int x=0; x < 16 ; x++){
delay(300);
lcd.write(7);}
pinMode(ledlcdPin, OUTPUT);
pinMode(ledvideoPin, OUTPUT);
pinMode(buttonlcdPin, INPUT);
pinMode(buttonvideoPin, INPUT); }
void loop() {
lcd.setCursor(0,0);
lcd.print(" GroundStation ");
lcd.setCursor(0,1);
lcd.print("TESTTESTTEST SWE");
int currentButtonState = digitalRead(buttonlcdPin);
if (currentButtonState != lastButtonState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay &&
currentButtonState != buttonState) {
//Nytt värde från knapp
buttonState = currentButtonState;
if (buttonState == LOW) //Pressed
{
//New state is pressed
ledState = !ledState;
digitalWrite(ledlcdPin, ledState);
lcd.setCursor(0,0);
lcd.print(" TESTING ");
delay(2000);
}
}
lastButtonState = currentButtonState;
}
But when i try to add the same type of code for the second button it doesn't work..
//Code for loading screen made by: mrmeval
//TEST med toggle
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
const int ledlcdPin = A0; //LEDpin i UNO
const int ledvideoPin = A1;
const int buttonlcdPin = 11; //Buttonpin in i UNO
const int buttonvideoPin = 10; //Buttonpin in i UNO
int ledlcdState = HIGH;
int ledvideoState = HIGH;
int buttonlcdState;
int buttonvideoState;
int lastButtonState = LOW;
unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
const unsigned long debounceDelay = 50; // the debounce time; increase if the output flickers
byte block[8] =
{
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B00000
};
void setup() {
// set up the LCD's number of rows and columns:
lcd.createChar(7,block);
lcd.begin(16, 2);
//lcd.setCursor(0,7);
delay(10);
// scroll 24 positions (string length) to the left
// to move it offscreen left:
lcd.clear();
lcd.print(" MK-Swe GS-V1 Startar");
for (int positionCounter = 0; positionCounter < 23; positionCounter++) {
// scroll one position left:
lcd.scrollDisplayLeft();
delay(380);
}
lcd.home();
lcd.setCursor(0,1);
for (int x=0; x < 16 ; x++){
delay(300);
lcd.write(7);}
pinMode(ledlcdPin, OUTPUT);
pinMode(ledvideoPin, OUTPUT);
pinMode(buttonlcdPin, INPUT);
pinMode(buttonvideoPin, INPUT); }
void loop() {
lcd.setCursor(0,0);
lcd.print(" GroundStation ");
lcd.setCursor(0,1);
lcd.print("TESTTESTTEST SWE");
int currentButtonlcdState = digitalRead(buttonlcdPin);
if (currentButtonlcdState != lastButtonState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay &&
currentButtonlcdState != buttonlcdState) {
//Nytt värde från knapp
buttonlcdState = currentButtonlcdState;
if (buttonlcdState == LOW) //Pressed
{
//New state is pressed
ledlcdState = !ledlcdState;
digitalWrite(ledlcdPin, ledlcdState);
lcd.setCursor(0,0);
lcd.print(" TESTAR ");
delay(2000);
}
}
lastButtonState = currentButtonlcdState;
int currentButtonvideoState = digitalRead(buttonvideoPin);
if (currentButtonvideoState != lastButtonState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay &&
currentButtonvideoState != buttonvideoState) {
//Nytt värde från knapp
buttonvideoState = currentButtonvideoState;
if (buttonvideoState == LOW) //Pressed
{
//New state is pressed
ledvideoState = !ledvideoState;
digitalWrite(ledvideoPin, ledvideoState);
lcd.setCursor(0,0);
lcd.print(" TESTAR2 ");
delay(2000);
}
}
lastButtonState = currentButtonvideoState;
}
As you see, i want to have it like this:
When nothing is pressed display some text.
When button 1 is pressed display "starting/loading LCD" for 2 seconds and toggle on LED1
When button 2 is pressed display "starting/loading Video" for 2 seconds and toggle on LED2
and when either one of the buttons is pressed a second time, toggle that corresponding LED off.
Can someone please explain what i am doing wrong..!