ATtiny85 relay control

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
unknown5591
 
Posts: 75
Joined: Mon Jun 13, 2016 8:19 pm

Re: ATtiny85 relay control

Post by unknown5591 »

So when

Code: Select all

if (digitalRead(buttonPin)==LOW)
meaning the button is pressed it starts the timer of

Code: Select all

volatile uint32_t pressStart
If its held for longer then 500ms it should start the switch statement. Else the ATtiny remains asleep.

I'm not sure how they get cleared independently of any debounce timing. I am pretty code illiterate I'm trying to make as much sense of this as I can.

I am unsure what you suggest I do.

Thanks for all your help so far.

User avatar
adafruit_support_bill
 
Posts: 88154
Joined: Sat Feb 07, 2009 10:11 am

Re: ATtiny85 relay control

Post by adafruit_support_bill »

It looks like you are trying to do multiple possibly conflicting things based on the button up and down times.

Please define exactly what behavior you are trying to implement.

User avatar
unknown5591
 
Posts: 75
Joined: Mon Jun 13, 2016 8:19 pm

Re: ATtiny85 relay control

Post by unknown5591 »

Ok

After running through the setup sequence the AT goes to sleep.

A prolonged button press wakes the AT. When awake the relay turns on by a flip in polarity of the coil pins.

While awake additional button presses will toggle the relay between two states (steady and flashing).

Only a prolonged press will put the AT back to sleep and reverse the poles of the relay.

User avatar
adafruit_support_bill
 
Posts: 88154
Joined: Sat Feb 07, 2009 10:11 am

Re: ATtiny85 relay control

Post by adafruit_support_bill »

So put that all the button timing in your ISR logic, and eliminate all the time-related stuff in your loop;

Code: Select all

ISR(PCINT0_vect) 
{
	if(digitalRead(buttonPin) == LOW) // low will indicate the button press
	{   
		pressStart = millis();              // start/enable a 'soft' timer
	}
	else 
	{
		if (millis() - pressStart > 500)  // button has been down for > 500ms
		{
			onOff = !onOff; // toggle on/off state
		}
		else
		{
			buttonPushCounter++;  // increment the button press
		}
	}
} //end of ISR

User avatar
unknown5591
 
Posts: 75
Joined: Mon Jun 13, 2016 8:19 pm

Re: ATtiny85 relay control

Post by unknown5591 »

That did it!!!!!

Works like a dream!

User avatar
unknown5591
 
Posts: 75
Joined: Mon Jun 13, 2016 8:19 pm

Re: ATtiny85 relay control

Post by unknown5591 »

THANK YOU SO MUCH!

User avatar
adafruit_support_bill
 
Posts: 88154
Joined: Sat Feb 07, 2009 10:11 am

Re: ATtiny85 relay control

Post by adafruit_support_bill »

Good to hear it is working. Thanks for the follow-up.

Locked
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”