Help needed with ATTiny 85 relay project for guitar pedal loop switcher

I need help!! :’)
Ok, i’m designing a guitar pedal switch. essentially it’s 6 momentary footswitches, 6 relays, and 6, 6 way dipswitches. the idea is, each footswitch is assigned a dipswitch, and each pin on the dipswitch corresponds to a relay?


With me so far?!


part of the schematic is below, but it just repeats across all 6 parts, and it’s working great, but i’m trying to figure out a way, that when i select a different footswitch, the previous ‘patch’ is turned off. I’ve still got pin 5 free on my attiny85 so was hoping someone with a bigger brain that me can point me in the right direction. Code is below.

const int led = 2;
const int button = 4;
const int setRelay = 1;
const int clearRelay = 0;
const int muteOutput = 3;
int led_state = LOW;
// Button states and debounce
int buttonState = 0;
int lastButtonState = HIGH;
unsigned long lastDebounceTime = 0;
void setup() {
  pinMode(led, OUTPUT);
  pinMode(button, INPUT_PULLUP);
  pinMode(setRelay, OUTPUT);
  pinMode(clearRelay, OUTPUT); 
  pinMode(muteOutput, OUTPUT);   
  digitalWrite(muteOutput, LOW);
  relayOff();
// Blink LED to show code running 
  digitalWrite(led, HIGH);
  delay(200);
  digitalWrite(led, LOW);
  delay(100);
  digitalWrite(led, LOW);
  delay(200);
  digitalWrite(led, LOW); 
  delay(100);
  digitalWrite(led, HIGH);
  delay(200);
  digitalWrite(led, LOW); 
}
void loop() {
  int reading = digitalRead(button);
  if (reading != lastButtonState)
    lastDebounceTime = millis();
  if ((millis() - lastDebounceTime) > 50) {
    if (reading != buttonState) {
      buttonState = reading;
      if (buttonState == LOW) {
        led_state = !led_state;
            if (led_state == LOW) { relayOff(); }
            if (led_state == HIGH) { relayOn(); }     
      }
    }
  }
  lastButtonState = reading;
  digitalWrite(led, led_state);
}
void relayOn() {
  digitalWrite(muteOutput, HIGH);
  digitalWrite(setRelay, HIGH);
  delay(5);
  digitalWrite(setRelay, HIGH);
  digitalWrite(muteOutput, HIGH);  
}
void relayOff() {
  digitalWrite(muteOutput, LOW);
  digitalWrite(clearRelay, LOW);
  delay(5);
  digitalWrite(setRelay, LOW); 
  digitalWrite(muteOutput, LOW); 

Where is the footswitch in the schematic?
I didn’t even try to read you code. Please read “How to use this forum” and put your formatted code into code brackets and repost.

Apologies, edited. The footswitch is SW4. it’s a pin header so i can feed wires to the hardware switch

So, do I understand that each footswitch has its own AT Tiny, six DIP switches and six relays?. 36 in all?

No, sorry i’ve probably worded it poorly. There’s 6 footswitches, 6 relays, and 6 ATTinys.
Each relay corresponds to an input and an output for guitar effects.
The idea is that by using the DIP switches, i can select which I/O’s i want, and turn the corresponding relays on with one footswitch, which is working fine. The issue i’m having is when i want to switch to a different footswitch with a different set of I/O’s, i need to turn the previous ATTiny ‘off’

If that makes sense?

HEre’s a more complete version

A little more.
The complete schematic makes a lot more sense. (Partial schematics, like code snippets almost always generate more questions than answers).
IS PB3 (Pin 2) on U1 an error?
What is the purpose of the Zener and capacitor?
Are the footswitches toggles or momentary buttons?

Is there a reason you want to use an AT Tiny for each footswitch instead of an Arduino with more I/O and a port expander like the MCP23017?

so U1 is the design i’m proceeding with i think. i was just updateing it as i was breadboarding, and didn’t get around to updating the other 6.

So the zener and the 100nf were part of a momentary mute circuit, paired with a pair of mosfets. i left them there incase i wanted to add the mosfets later on, but they’ll work fine without.

the fooswitches are momentary.

It’s an elaborated design of a standlone switching system i found online a while ago. I’m open to the idea of using something larger, but i’m a complete beginner with arduino, but i’m a bit better at the hardware side of it haha. Just figured i’d try work with what i know really!

Since it’s a momentary switch, you could (I’m spitballing here) make a pseudo one-wire bus so that each Tiny would know if another Tiny’s footswitch is down.
If you use a different Arduino with SPI, one MCP23017 would give you sixteen I/O ports. (I’ve never worked with the AT Tiny, so I don’t know if you can simulate SPI on it). If you use a single processor, you could simply scan the footswitches to see who is down.

I had considered that, but i’ve got no idea how to code it really! I found another design online (below) who seems to do a similar thing, but there’s no code with the schematic unless you buy their pre programmed ATTinys haha

The code is the easy part. It looks like they are doing what I suggested in making a one-wire bus with their ctrl pads on the PCB. The way the one wire bus works is the bus is pulled low in their schematic and any active Tiny would pull the bus high. The other AT Tiny’s would see the bus high and know that another Tiny has control. (I would use pullup resistors and pull the bus low but the operation is the same).

Remember the talking stick in elementary school? Whoever has the stick gets to talk. Everyone else just waits until they have the stick. A one-wire bus works the same.

So i’ve currently got Pin 2 free on my schematic. I could use pin 2 with a 100k resistor to ground, and daisy chain all the pin 2’s together essentially? that’s doable! it’s just the code, i wouldn’t even know where to start :’)

Are the AT Tinys going to be in the same box or separate? As I said, I would use a pullup resistor on each AT Tiny. Any AT Tiny that has control of the relays would pull PB3 down. Use the pin labels in your descriptions, not the physical pin numbers. It’s less confusing.

Sorry, Yeah they’re all going to me one one massive PCB eventually. Yeah PB3 is what i mean. so yeah, a 100k resistor from PB3 to 5V, then a link between PB3 on all 6 attinys?

Here’s where I am going. If they are all on one PCB then you only need one pullup resistor. Anything from 4K7 to 47K would work. When you press on the footswitch (on PB4), its associated processor would first look to PB3. If PB3 is low then another processor has the stick and no one else may speak to the relays. If PB3 is high then it would pull PB3 low to indicate to the other processors that they can’t control the relays.

The logic checks out, i just don’t really know how to translate it into code. I’ve tried copying parts of the existing code and editing it to match the pins i need etc, but keep getting errors and don’t know what they mean haha.

Should i be puttint it into the Void loop?

It’s time to fall back to the basics. Buy an Arduino Uno sensor kit- there’s dozens on Amazon. It doesn’t matter which one. Experiment with the sensors on a breadboard. Experiment with the sample sketches (what Arduino calls a program). This will give you a framework from which you can build the code for your project.

Start here: Arduino Education

When you start programming your project and you get errors, post your code (in code tags) and the error messages (also in code tags) and someone here will help you interpret the error.

I mean i understand where you’re coming from, but arduino is a means to an end for me. I’m asking for help with a code for a single project, which once finished, will be fine and never altered again. I’m a guitar pedal builder predominatly, and just need help with one project.

Also, apologies if that came off as me being angry, it wasn’t my intent, but it’s hard to judge emotion over text haha.

The principal purpose of the forum is to help people to learn to program the Arduino. Usually, we won’t write the code for you. It sounds like you need to post your project on the Gigs and Collaboration category.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.