I have successfully used this code on the Uno board to control a LED and latching relay. I adjusted the pins for an attiny85. The programming is working correctly for a blink sketch but when I upload the following code it does not work properly. I'm new to arduino and uploading to the attinys so I'm not sure that all the code is supported by the attiny85. For right now the switch is using an external pull up. Any help is much appreciated!
/* Alternating LED & Relay */
#include <Bounce.h>
const int inputPin = 0; // momentary switch
const int ledPin = 4; // the number of the LED pin
const int relayPin1 = 2;
const int relayPin2 = 3;
byte mode = 0;
Bounce bouncer = Bounce(inputPin,75); //settup debounce for first push button
void setup()
{
pinMode(inputPin, INPUT);
pinMode(ledPin, OUTPUT);
pinMode(relayPin1, OUTPUT);
pinMode(relayPin2, OUTPUT);
}
void loop() {
bouncer.update ( ); // Update the debouncer for the push button
switch( mode )
{
case 0://------------------------ I'm off and in restmode
if ( bouncer.read() == HIGH )
{
digitalWrite (ledPin, HIGH); // switch LED ON
digitalWrite (relayPin2, LOW); // switch relay ON
digitalWrite (relayPin1, HIGH); // switch relay ON
delay (30);
digitalWrite (relayPin1, LOW);
mode = 1;
}
break;
case 1://------------------------ I'm in ON mode, w8 4 keyrelease
if ( bouncer.read() == LOW )
mode = 2;
break;
case 2://------------------------ I'm ON and in restmode
if ( bouncer.read() == HIGH )
{
digitalWrite (relayPin1, LOW); // switch relay OFF
digitalWrite (relayPin2, HIGH); // switch relay OFF
digitalWrite (ledPin, LOW); // switch LED OFF
delay (30);
digitalWrite (relayPin2, LOW);
mode = 3;
}
break;
case 3://------------------------ I'm in OFF mode, w8 4 keyrelease
if ( bouncer.read() == LOW )
mode = 0;
break;
}//switch
}//loop