So I tried the suggestion I entered the code where I thought it should go? It verified and uploads to the UNO no issue. It does not seem to keep the state of the switch or I messed up something(more likely). I set up a serial print, it seems to display a one, if I press the switch it displays nothing, when I release the button it displays a box then back to 1. I added the serial print to see what was on the buttonState pin. I had lots of errors initially. When they say syntax is key are they ever right :).
When connected to this pin it showed "1" when button not pressed, and "nothing" when pressed, and a box when released? The Switch is a normally open switch. The attached data image shows a snapshot of the switch switching states if that helps.
The switch is a momentary push button, it works I metered it, connected one lead to the +5 Volt rail and the other lead to D3 originally. I actually measured the 5 volts only when the switch was pressed, prior to placing it in the header.
Then I thought I remembered something weird about D3(?) pin so I connected to D6 changed the sketch and it still seems to only change states when the switch is held in the depress position. It is now a 1 or 0 which is an improvement but it does not seem to hold the state, and the "dancing" lights rock on. Even if I hold the switch on for several seconds(20+) the lights still "dance".
This time I have tried to upload the code, any suggestions are truly appreciated.
#define msg7RESET 11 // reset Pin 11
#define msg7Strobe 10 // Strobe Pin 10
#define msg7DCout A0 // DC out from MSG7
const int ModeButton = 6; // the pin the pushbutton is connected to
const int LEDpins[7] = {2,4,5,7,8,12,13}; // there are 7 freq bands.
boolean buttonState = 0; // current state of the button
boolean lastButtonState = 0; // previous state of the button
void setup()
{
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
for (int x=0; x<7; x++)
{
pinMode(LEDpins[x], OUTPUT);
pinMode(msg7RESET, OUTPUT);
pinMode(msg7Strobe, OUTPUT);
// initialize the ModeButton as a input with internal pullup enabled
pinMode(ModeButton, INPUT_PULLUP);
Serial.begin(9600);
}
}
void loop()
{
static unsigned long timer = 0; // no idea what this does
unsigned long interval = 50; // check switch 20 times per second
if (millis() - timer >= interval)
timer = millis();
// read the pushbutton input pin:
buttonState = digitalRead(ModeButton);
// compare the buttonState to its previous state
if (buttonState != lastButtonState)
{
if (buttonState == HIGH)
// if the current state is HIGH then the toggle on all relays:
digitalWrite(LEDpins[2,4,5,7,8,12,13], HIGH); // toggle the output set all relays to ON
}
digitalWrite(msg7RESET, HIGH); // reset the MSGEQ7's counter
delay(5); //delay 5 uSeconds
digitalWrite(msg7RESET, LOW); //Sets the reset pin to LOW
for (int x = 0; x < 7; x++)
{
digitalWrite(msg7Strobe, LOW); // output each DC value for each freq band
delayMicroseconds(35); // to allow the output to settle (35)
int spectrumRead = analogRead(msg7DCout);
int PWMvalue = map(spectrumRead, 0, 1024, 0, 255); // scale analogRead's value to Write's 255 max
if (PWMvalue < 50)
PWMvalue = PWMvalue / 2; // bit of a noise filter, so the LEDs turn off at low levels
analogWrite(LEDpins[x], PWMvalue);
digitalWrite(msg7Strobe, HIGH);
}
Serial.println(buttonState);
// save the current state as the last state,for next time through the loop
lastButtonState = buttonState;
}
Loving and Learning the Arduino (At least trying)
Thanks in advance
