advice on "converting" script from Uno to Attiny85

I’ve been working on a project where one N.O. momentary button will control two outputs in sequence. I finally got the script to work on both a Uno and Nano board to my satisfaction. Basically the momentary button will turn on two relays individually in sequence then both together than both off with each button press. Now I’d like to physically reduce the size of the project by using an attiny84 controller. Can anyone assist in changing the code to run on the attiny?? My issue, of course, is the Button line in blue.

Error message is: Arduino: 1.6.7 (Windows 10), Board: “ATtiny, ATtiny85, 1 MHz (internal)”

WARNING: Category ‘’ in library OneWire is not valid. Setting to ‘Uncategorized’
two_items_one_button_attiny:7: error: ‘BUTTON_PULLUP_INTERNAL’ was not declared in this scope

Button button = Button(2, BUTTON_PULLUP_INTERNAL, true, 100);

^

exit status 1
‘BUTTON_PULLUP_INTERNAL’ was not declared in this scope

My converted script:

#include <Button.h>

/*
create a Button object at pin 12
connect button between pin 12 and GND
*/
Button button = Button(2, BUTTON_PULLUP_INTERNAL, true, 100);
void setup() {
pinMode(1, OUTPUT); //debug to led 13
pinMode(0, OUTPUT);
}
byte pressCount = 0;
void loop() {
if (button.uniquePress())
pressCount++;
switch (pressCount)
{ case 1:
digitalWrite(0, HIGH);
digitalWrite(1, LOW);
break;
case 2:
digitalWrite(0, LOW);
digitalWrite(1, HIGH);
break;
case 3:
digitalWrite(0, HIGH);
digitalWrite(1, HIGH);
break;
case 4:
digitalWrite(0, LOW);
digitalWrite(1, LOW);
pressCount = 0;
break;

}
}

Thanks in advance

two_items_one_button_attiny.ino (707 Bytes)

which Button library do you use??

Good question, the button.h file shows this:

|| @file Button.h
|| @version 1.6
|| @author Alexander Brevig
|| @contact alexanderbrevig@gmail.com
||

Thanks

I finally got the script to work on both a Uno and Nano board to my satisfaction.

are you sure this is really the truth?? How did this ever compile?

if you look at the constructor for the Button library you have

/*
|| <<constructor>>
|| @parameter buttonPin sets the pin that this switch is connected to
|| @parameter buttonMode indicates PULLUP or PULLDOWN resistor
*/
Button::Button(uint8_t buttonPin, uint8_t buttonMode){
	this->pin=buttonPin;
    pinMode(pin,INPUT);
	buttonMode==PULLDOWN ? pulldown() : pullup();
    state = 0;
    bitWrite(state,CURRENT,!mode);
}

so the line

Button button = Button(2, BUTTON_PULLUP_INTERNAL, true, 100);

is clearly not meant for that library and would never compile on any of your device…

I would suggest reading this

you will see that this library has for constructor

    Button(uint8_t buttonPin, uint8_t buttonMode=BUTTON_PULLUP_INTERNAL, bool _debounceMode=true, int _debounceDuration=20);

which you looks better for your code…

Thank you....now script uploads. Originally, when testing with Uno, I used only:

Button button = Button(2, BUTTON_PULLUP_INTERNAL);

but ran into bounce issues and the output LEDs lit at random when the button was pressed. I noticed another script that used the final code I used and that seemed to resolve the issue. Perhaps the Uno simply ignored the unknown code or something. In any case the code uploaded to the attiny85 so now I'll build the circuit to test the output.

Thanks for your help.

If application is simply controlling two relays with one button, it may be better, also for your education, to eliminate the library and code the entire application yourself. I guess the button library you are using does little more than debouncing and there are plenty of examples of that around.

6v6gt:
If application is simply controlling two relays with one button, it may be better, also for your education, to eliminate the library and code the entire application yourself. I guess the button library you are using does little more than debouncing and there are plenty of examples of that around.

Thank you. Actually I also use a 1uF capacitor across the button for some hardware debounce initially/also.

I've tried to find an example of code that would allow me to control two relays from one momentary button in the sequence I want/need but have failed so far. I have no issues with hardware but "code" is not something I even pretend to know or even enjoy writing. I can sometimes look at a script and figure out what it does but after that......well, I'm mostly lost. The basis of the script I initially posted was gleaned from the forums here. In any case I just tested with an attiny85 and a couple LEDs and it does seem to work as I intended. Now off to create a small PCB and decide on additional hardware.

Thanks again everyone.

Rick