Infinity Cube

This is my first time using an arduino board and I am still new with circuits as well. I'm making a cube with an infinity mirror on 5 sides. I want to have a toggle switch to switch between position 1: LED strip on and all LEDs remaining on (no flashing or anything), position 2: Music activated using a keyes microphone, and position 3: Chasing lights throughout the strip with a pot to change the speed (not sure if I can change the speed with a pot or if I can just change it in the code). How do I connect the toggle switch to the arduino to make this happen? Like I said I am new to the arduino and any tips will help. I need to put a voltage divider in to make the 24v work as well.

west164:
... with a pot to change the speed (not sure if I can change the speed with a pot or if I can just change it in the code).

Well, the only way you can change the speed if you are using an Arduino - which is a digital device - is through the code, so if you want a potentiometer to change the speed, then the code has to read the potentiometer using the ADC and use that value to change the way it counts to time the process. It is actually somewhat easier to use "fast" and "slow" buttons.

If you have three modes, I suppose you would be wanting a three position toggle switch. This has two "on" positions with the centre off, you just connect the common to ground and each of the "on" positions to an Arduino input using the "INPUT_PULLUP" function of the chip. Mind you, with proper (debounce) code, you can just use a single push-button to cycle between modes.

I have the codes I want to use. How do I adjust the code to switch between the positions using a push button?

Without seeing your code, we can't tell you exactly how to change it... But, I wouldn't take the time to study and analyze your code anyway.... :wink:

So this isn't code, but it's the basic logic :

If button is pushed and mode is 1, change to mode 2.

If button is pushed and mode is 2, change to mode 3.

If button is pushed and mode is 3, change to mode 1.

(Keep running the same loop if no button is pushed.)

I need to put a voltage divider in to make the 24v work as well.

What??? Don't use a voltage divider for anything related to power. i.e. If you have a 24V power supply and you want to power the Arduino, you need a voltage regulator.

If you need to lower an input voltage or signal voltage, or you need to create a reference voltage, you can use a voltage divider. You can't use a voltage divider where there is significant current.

west164:
How do I adjust the code to switch between the positions using a push button?

Well, let me give you a piece of code to study. It no doubt looks complex to start with, but is designed to debounce a pushbutton and be absolutely reliable in doing so. Also to flash a number of LEDs independently - it should be a good basis from which to develop other applications.

// Blink without "delay()" - multi!

const int led1Pin =  13;    // LED pin number
const int led2Pin =  10;
const int led3Pin =  11;
const int button1 =  4;
int led1State = LOW;        // initialise the LED
int led2State = LOW;
int led3State = LOW;
char bstate1 = 0;
unsigned long count1 = 0;   // will store last time LED was updated
unsigned long count2 = 0;
unsigned long count3 = 0;
unsigned long bcount1 = 0; // button debounce timer.  Replicate as necessary.

// Have we completed the specified interval since last confirmed event?
// "marker" chooses which counter to check 
boolean timeout(unsigned long *marker, unsigned long interval) {
  if (millis() - *marker >= interval) { 
    *marker += interval;    // move on ready for next interval
    return true;       
  } 
  else return false;
}

// Deal with a button read; true if button pressed and debounced is a new event
// Uses reading of button input, debounce store, state store and debounce interval.
boolean butndown(char button, unsigned long *marker, char *butnstate, unsigned long interval) {
  switch (*butnstate) {               // Odd states if was pressed, >= 2 if debounce in progress
  case 0: // Button up so far, 
    if (button == HIGH) return false; // Nothing happening!
    else { 
      *butnstate = 2;                 // record that is now pressed
      *marker = millis();             // note when was pressed
      return false;                   // and move on
    }

  case 1: // Button down so far, 
    if (button == LOW) return false; // Nothing happening!
    else { 
      *butnstate = 3;                 // record that is now released
      *marker = millis();             // note when was released
      return false;                   // and move on
    }

  case 2: // Button was up, now down.
    if (button == HIGH) {
      *butnstate = 0;                 // no, not debounced; revert the state
      return false;                   // False alarm!
    }
    else { 
      if (millis() - *marker >= interval) {
        *butnstate = 1;               // jackpot!  update the state
        return true;                  // because we have the desired event!
      }
      else 
        return false;                 // not done yet; just move on
    }

  case 3: // Button was down, now up.
    if (button == LOW) {
      *butnstate = 1;                 // no, not debounced; revert the state
      return false;                   // False alarm!
    }
    else { 
      if (millis() - *marker >= interval) {
        *butnstate = 0;               // Debounced; update the state
        return false;                 // but it is not the event we want
      }
      else 
        return false;                 // not done yet; just move on
    }
  default:                            // Error; recover anyway
    {  
      *butnstate = 0;
      return false;                   // Definitely false!
    }
  }
}

void setup() {
  pinMode(led1Pin, OUTPUT);      
  pinMode(led2Pin, OUTPUT);      
  pinMode(led3Pin, OUTPUT);      
  pinMode(button1, INPUT);      
  digitalWrite(button1,HIGH);        // internal pullup all versions
}

void loop() {
  // Toggle LED if button debounced
  if (butndown(digitalRead(button1), &bcount1, &bstate1, 10UL )) {
    if (led1State == LOW) {
      led1State = HIGH;
    }
    else {
      led1State = LOW; 
    } 
    digitalWrite(led1Pin, led1State);
  } 

  // Act if the latter time (ms) has now passed on this particular counter,
  if (timeout(&count2, 300UL )) {
    if (led2State == LOW) {
      led2State = HIGH;
    }
    else {
      led2State = LOW; 
    } 
    digitalWrite(led2Pin, led2State);
  } 

  if (timeout(&count3, 77UL )) {
    if (led3State == LOW) {
      led3State = HIGH;
    }
    else {
      led3State = LOW; 
    } 
    digitalWrite(led3Pin, led3State);
  } 
}

with a pot to change the speed...

A pot will work.

Or, you could have a speed-up button and a slow-down button. Or a single button that goes-through a speed-up/slow down cycle that locks-in when you release the button.

Or you can use the same mode-select button and if you you are in the chase mode and ou hold the biutton down for a second or two (instead of a quick push-and-release), it goes through a speed-up/slow down cycle 'till you release and lock-in the speed.

Or, just have it constantly speeding up and slowing down, or randomly change the speed once in awhile.

chasing lights throughout the strip...

You don't have to stick with the "standard" chase pattern. You can load a random pattern and chase (you have to make sure the random pattern doesn't end-up all-on or all-off). Or, you can create a [u]Johnson Counter[/u] where the state is inverted as it "loops around". You can also randomly reverse directions and/or make a standard ring-counter in one direction and Johnson-counter in the other.

I've got a sound activated chase effect that does all of that "random" stuff where the speed depends on the loudness, or the direction is switched with the beat/loudness, etc.

I've also got a mode where loud sounds turn-on the 1st lamp and "inject" an on-state into the chase-sequence. I call that a "shooter effect". There are also random options where the on-state shoots-through and bounces back.