BRILLIANT!!!
It works wonderfully!
I guess my problem was I didn't know how to use multiple "If, Else" statements.
Thank you!
You have helped a newbie expand his mind!
Also, I don't mind silver platters!
This is the final result:
// constants won't change. They're used here to
// set pin numbers:
const int BUTTONpin = 12; // the number of the pushbutton pin
const int SWITCHpin = 7; // the number of the pushSWITCH pin
// Variables will change:
int BUTTONstate; // the current BUTTONreading from the input pin
int lastBUTTONstate = LOW; // the previous BUTTONreading from the input pin
long lastBUTTONDebounceTime = 0; // the last time the output pin was toggled
int SWITCHstate; // the current SWITCHreading from the input pin
int lastSWITCHstate = LOW; // the previous SWITCHreading from the input pin
long lastSWITCHDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 100; // the debounce time; increase if the output flickers
void setup() {
pinMode(BUTTONpin, INPUT);
pinMode(SWITCHpin, INPUT);
}
void loop()
{
getSWITCHreading();
getBUTTONreading();
//SWITCHstate is the current state of the SWITCH
//BUTTONstate is the current state of the BUTTON
if(SWITCHstate==1) //if SWITCH is pressed
{
if(BUTTONstate == 1) //if BUTTON is pressed
{
analogWrite(9, 255);
}
else //if BUTTON not pressed
{
analogWrite(9, 50);
}
}
else //SWITCHstate=LOW
{
if(BUTTONstate == 1) //if BUTTON is pressed
{
analogWrite(9, 255);
}
else //if BUTTON not pressed
{
analogWrite(9, 0);
}
}
}
void getSWITCHreading()
{
// read the state of the switch into a local variable:
int SWITCHreading = digitalRead(SWITCHpin);
// check to see if you just pressed the SWITCH
// (i.e. the input went from LOW to HIGH), and you've waited
// long enough since the last press to ignore any noise:
// If the switch changed, due to noise or pressing:
if (SWITCHreading != lastSWITCHstate) {
// reset the debouncing timer
lastSWITCHDebounceTime = millis();
}
if ((millis() - lastSWITCHDebounceTime) > debounceDelay) {
// whatever the SWITCHreading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:
SWITCHstate = SWITCHreading;
}
// save the SWITCHreading. Next time through the loop,
// it'll be the lastSWITCHstate:
lastSWITCHstate = SWITCHreading;
}
void getBUTTONreading()
{
// read the state of the switch into a local variable:
int BUTTONreading = digitalRead(BUTTONpin);
// check to see if you just pressed the button
// (i.e. the input went from LOW to HIGH), and you've waited
// long enough since the last press to ignore any noise:
// If the switch changed, due to noise or pressing:
if (BUTTONreading != lastBUTTONstate) {
// reset the debouncing timer
lastBUTTONDebounceTime = millis();
}
if ((millis() - lastBUTTONDebounceTime) > debounceDelay) {
// whatever the BUTTONreading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:
BUTTONstate = BUTTONreading;
}
// save the BUTTONreading. Next time through the loop,
// it'll be the lastBUTTONstate:
lastBUTTONstate = BUTTONreading;
}