I'm completely new to Arduino and I've been reading a lot but I'm starting to get stuck. I am trying to program an UNO to control an el wire sequencer. I also have an analog keypad and sound detector to control multiple actions. The goal is to turn it on and have all channels light up. Then, with the push of a button, switch between other modes. i.e. flashing, sound reactive, back to all on, etc. I got as far as turning on and changing to another mode. I couldn't figure out how to switch back. That is the first code. The second code is the start of another approach but it's not functional. I could use some guidance before I get discouraged.
const int Key_pin = A0;
const int Gate_pin = A1;
const int Envl_pin = A2;
const int Audio_pin = A3;
int Key_read;
int Previous_Key;
int Value;
String Key_id;
String Vol_id;
void setup() {
Serial.begin(9600);
pinMode(2, OUTPUT); // channel A
pinMode(3, OUTPUT); // channel B
pinMode(4, OUTPUT); // channel C
pinMode(5, OUTPUT); // channel D
pinMode(6, OUTPUT); // channel E
pinMode(7, OUTPUT); // channel F
pinMode(8, OUTPUT); // channel G
pinMode(9, OUTPUT); // channel H
pinMode(10, OUTPUT); // Escudo Status LED
pinMode(13, OUTPUT); // Arduino Status LED
pinMode(A0, INPUT); // Button
pinMode(A1, INPUT); // Gate
pinMode(A2, INPUT); // Envelope
pinMode(A3, INPUT); // Audio
}
void loop()
{
Value = analogRead(Envl_pin);
if (not Value <= 9)
if (Value >= 10 and Value <= 19) Vol_id = "Low";
if (Value >= 20 and Value <= 29) Vol_id = "Moderate";
if (Value >= 30) Vol_id = "High";
if (Value >= 10) {
Serial.print(Value);
Serial.println(" - The volume is " + Vol_id);
delay(100);
}
{
Key_read = analogRead(Key_pin);
if (not Key_read < 600)
if (Key_read < 299) Key_id = "Blue";
if (Key_read > 300 and Key_read < 349) Key_id = "Yellow", mode2();
if (Key_read > 400 and Key_read < 449) Key_id = "Green";
if (Key_read > 450 and Key_read < 499) Key_id = "Grey";
if (Key_read > 500 and Key_read < 549) Key_id = "Red";
if (Key_read != Previous_Key and Key_read < 600) {
Serial.print(Key_read);
Serial.println(" - " + Key_id + " key pressed");
Previous_Key = Key_read;
delay(1000);
}
{
digitalWrite(2, HIGH); // turn on channel A
digitalWrite(3, HIGH); // turn on channel B
digitalWrite(4, HIGH); // turn on channel C
digitalWrite(5, HIGH); // turn on channel D
digitalWrite(6, HIGH); // turn on channel E
digitalWrite(7, HIGH); // turn on channel F
digitalWrite(8, HIGH); // turn on channel G
digitalWrite(9, HIGH); // turn on channel H
}
}
}
void mode2()
{
int x;
for (int x = 2; x <= 9; x++)
{
digitalWrite(x, HIGH); // turn the EL channel on
delay(100); // wait for 1/10 second
digitalWrite(x, LOW); // turn the EL channel off
}
for (int x = 9; x >= 2; x--)
{
digitalWrite(x, HIGH); // turn the EL channel on
delay(100); // wait for 1/10 second
digitalWrite(x, LOW); // turn the EL channel off
}
mode2();
}
const int Key_pin = A0;
const int Gate_pin = A1;
const int Envl_pin = A2;
const int Audio_pin = A3;
int Key_read;
int Previous_Key;
int Value;
int Mode_1;
int Mode_2;
String Key_id;
String Vol_id;
void setup() {
Serial.begin(9600);
pinMode(2, OUTPUT); // channel A
pinMode(3, OUTPUT); // channel B
pinMode(4, OUTPUT); // channel C
pinMode(5, OUTPUT); // channel D
pinMode(6, OUTPUT); // channel E
pinMode(7, OUTPUT); // channel F
pinMode(8, OUTPUT); // channel G
pinMode(9, OUTPUT); // channel H
pinMode(10, OUTPUT); // Escudo Status LED
pinMode(13, OUTPUT); // Arduino Status LED
pinMode(A0, INPUT); // Button
pinMode(A1, INPUT); // Gate
pinMode(A2, INPUT); // Envelope
pinMode(A3, INPUT); // Audio
}
void loop()
{
Keypad();
Sound_detect();
Mode_1();
Mode_2();
}
void Keypad()
{
Key_read = analogRead(Key_pin);
if (not Key_read < 600)
if (Key_read < 299) Key_id = "Blue";
if (Key_read > 300 and Key_read < 349) Key_id = "Yellow", Mode_2();
if (Key_read > 400 and Key_read < 449) Key_id = "Green";
if (Key_read > 450 and Key_read < 499) Key_id = "Grey", Mode_1();
if (Key_read > 500 and Key_read < 549) Key_id = "Red";
if (Key_read != Previous_Key and Key_read < 600) {
Serial.print(Key_read);
Serial.println(" - " + Key_id + " key pressed");
Previous_Key = Key_read;
delay(1000);
}
}
void Sound_detect()
{
Value = analogRead(Envl_pin);
if (not Value <= 9)
if (Value >= 10 and Value <= 19) Vol_id = "Low";
if (Value >= 20 and Value <= 29) Vol_id = "Moderate";
if (Value >= 30) Vol_id = "High";
if (Value >= 10) {
Serial.print(Value);
Serial.println(" - The volume is " + Vol_id);
delay(100);
}
void Mode_1()
{
digitalWrite(2, HIGH); // turn on channel A
digitalWrite(3, HIGH); // turn on channel B
digitalWrite(4, HIGH); // turn on channel C
digitalWrite(5, HIGH); // turn on channel D
digitalWrite(6, HIGH); // turn on channel E
digitalWrite(7, HIGH); // turn on channel F
digitalWrite(8, HIGH); // turn on channel G
digitalWrite(9, HIGH); // turn on channel H
}
void Mode_2()
{
{
int x;
for (int x = 2; x <= 9; x++)
{
digitalWrite(x, HIGH); // turn the EL channel on
delay(100); // wait for 1/10 second
digitalWrite(x, LOW); // turn the EL channel off
}
for (int x = 9; x >= 2; x--)
{
digitalWrite(x, HIGH); // turn the EL channel on
delay(100); // wait for 1/10 second
digitalWrite(x, LOW); // turn the EL channel off
}
}
}