Author Topic: Controlling two attiny85s with one footswitch  (Read 4250 times)

patrick398

Re: Controlling two attiny85s with one footswitch
« Reply #20 on: December 20, 2020, 02:07:54 PM »
Actually, you could try that first yeah!  After all the setup, the modeswitching could be as simple as

if(mode1) {
  pinMode(1, INPUT);
} else {
  pinMode(1, OUTPUT);
}

If that doesn't work, you'll have to turn off the interrupts in mode1 and then turn them on in mode2, something like

if(mode1) {
  TIMSK = TIMSK & ~(1<<OCIE0A);              // Disable interrupt
  GIMSK = GIMSK & ~(1<<PCIE);                // Disable pin change interrupt
} else {
  TIMSK = TIMSK | 1<<OCIE0A;              // Enable interrupt
  GIMSK = GIMSK | 1<<PCIE;                // Enable pin change interrupt
}


Read up on 'bit manipulation' to learn how & why this works! For example (quick google) https://www.avrfreaks.net/forum/tut-c-bit-manipulation-aka-programming-101
 

If I had a Christmas card list, you would have just made the cut! Thanks so much for that man, looking forward to trying it out. And I'll try and wrap my tiny mind around bit manipulation. I've always thought I should be manipulating more bits

pruttelherrie

Re: Controlling two attiny85s with one footswitch
« Reply #21 on: December 21, 2020, 02:17:02 AM »
I've always thought I should be manipulating more bits

 :icon_cool: