Hi All,
Having some probs with making 2 sketch's work as one!, both work great as separate code.
Here are the codes:
//***ssb audio filter button TEST100***
#include <Wire.h>
#include <LiquidCrystal.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address to 0x27 for a 20 chars and 4 line display
const int switchPin0 = 2; // set up a constant for the switchPin
int switchState = 0; // variable to hold the value of the switchPin
int prevSwitchState = 0; // variable to hold previous value of the switchpin
int buttonPushCounter = 0; // counter for the number of button presses
void setup() {
lcd.begin(20, 4); // set up the number of columns and rows on the LCD
pinMode(switchPin0,INPUT); // set up the switch pin as an input
digitalWrite(switchPin0, HIGH); // turn on pullup resistor
//Setup Filter Outputs
pinMode(A0, OUTPUT); //Initiates off pin
pinMode(A1, OUTPUT); //Initiates 1.5Khz pin
pinMode(A2, OUTPUT); //Initiates 2.0Khz pin
pinMode(A3, OUTPUT); //Initiates 2.5Khz pin
}
// pasted new code from here on
void loop()
{
switchState = digitalRead(switchPin0); //check the status of the switc
if (switchState != prevSwitchState) //compare the switchState to its previous state
{
if (switchState == LOW) //If the switch is pressed, count the press
{
buttonPushCounter ++;
buttonPushCounter %= 4;
}
lcd.clear(); //clean up the screen before printin
}
// Now, do something with the count
switch (buttonPushCounter)
{
case 0:
lcd.setCursor(0, 0);
lcd.print("Off");
digitalWrite(A0, HIGH); //Output on
digitalWrite(A1, LOW); //Output off
digitalWrite(A2, LOW); //Output off
digitalWrite(A3, LOW); //Output off
break;
case 1:
lcd.setCursor(0, 0);
lcd.print("1.5Khz");
digitalWrite(A0, LOW); //Output off
digitalWrite(A1, HIGH); //Output on
digitalWrite(A2, LOW); //Output off
digitalWrite(A3, LOW); //Output off
break;
case 2:
lcd.setCursor(0, 0);
lcd.print("2.0Khz");
digitalWrite(A0, LOW); //Output off
digitalWrite(A1, LOW); //Output off
digitalWrite(A2, HIGH); //Output on
digitalWrite(A3, LOW); //Output off
break;
case 3:
lcd.setCursor(0, 0);
lcd.print("2.5Khz");
digitalWrite(A0, LOW); //Output off
digitalWrite(A1, LOW); //Output off
digitalWrite(A2, LOW); //Output off
digitalWrite(A3, HIGH); //Output on
break;
}
prevSwitchState = switchState; // save the current switch state as the last state
}
//*** RF Att button ***
#include <Wire.h>
#include <LiquidCrystal.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address to 0x27 for a 20 chars and 4 line display
const int switchPin1 = 3; // set up a constant for the switchPin
int switchState = 0; // variable to hold the value of the switchPin
int prevSwitchState = 0; // variable to hold previous value of the switchpin
int buttonPushCounter = 0; // counter for the number of button presses
void setup() {
lcd.begin(20, 4); // set up the number of columns and rows on the LCD
pinMode(switchPin1,INPUT); // set up the switch pin as an input
digitalWrite(switchPin1, HIGH); // turn on pullup resistor
//Setup rf att Outputs
pinMode(8, OUTPUT); //Initiates Off pin
pinMode(9, OUTPUT); //Initiates -10dB pin
pinMode(10, OUTPUT); //Initiates -20dB pin
pinMode(11, OUTPUT); //Initiates -30dB pin
pinMode(12, OUTPUT); //Initiates +10dB pin
}
void loop()
{
switchState = digitalRead(switchPin1); //check the status of the switch
if (switchState != prevSwitchState) //compare the switchState to its previous state
{
if (switchState == LOW) //If the switch is pressed, count the press
{
buttonPushCounter ++;
buttonPushCounter %= 5;
}
lcd.clear(); //clean up the screen before printin
}
switch (buttonPushCounter)
{
case 0:
lcd.setCursor(7, 0);
lcd.print("off");
digitalWrite(8, LOW); //Output off
digitalWrite(9, LOW); //Output off
digitalWrite(10, LOW); //Output off
digitalWrite(11, LOW); //Output off
digitalWrite(12, LOW); //Output off
break;
case 1:
lcd.setCursor(7, 0);
lcd.print("-10dB");
digitalWrite(8, LOW); //Output off
digitalWrite(9, HIGH); //Output on
digitalWrite(10, LOW); //Output off
digitalWrite(11, LOW); //Output off
digitalWrite(12, LOW); //Output off
break;
case 2:
lcd.setCursor(7, 0);
lcd.print("-20dB");
digitalWrite(8, LOW); //Output off
digitalWrite(9, LOW); //Output off
digitalWrite(10, HIGH); //Output on
digitalWrite(11, LOW); //Output off
digitalWrite(12, LOW); //Output off
break;
case 3:
lcd.setCursor(7, 0);
lcd.print("-30dB");
digitalWrite(8, LOW); //Output off
digitalWrite(9, LOW); //Output off
digitalWrite(10, LOW); //Output off
digitalWrite(11, HIGH); //Output on
digitalWrite(12, LOW); //Output off
break;
case 4:
lcd.setCursor(7, 0);
lcd.print("+10dB");
digitalWrite(8, LOW); //Output off
digitalWrite(9, LOW); //Output off
digitalWrite(10, LOW); //Output off
digitalWrite(11, LOW); //Output off
digitalWrite(12, HIGH); //Output on
break;
}
prevSwitchState = switchState; // save the current switch state as the last state
}
As i said before they both work as i want, i got my I2C lcd working, had a few probs but sorted now.
What i get confused with is how to get 2 buttons and 2 case to work together.
I need some help please.
Regards
Howard