Pages: [1]   Go Down
Author Topic: Code not working with ATTINY 85  (Read 711 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!

Code:
/*  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
Logged

Brisbane, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1122
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

What exactly does it do on the ATTiny?  Also could you post a photo of your circuit so we can verify your connections?

Geoff
Logged

"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

Denmark
Offline Offline
Edison Member
*
Karma: 35
Posts: 1063
Happy Hobbyist
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

One thing that could make it
Quote
not work properly
is the timing. The bounce library use millis(), and if you choose
for example the board: Attiny85@8MHZ without setting the right fuses, the timing will be off by a factor 8.

The factory default is 1MHz, so unless you have set the fuses yourself you should choose Attiny85@1MHZ


If you want to run 8MHz, do this:

Select Board -> Attiny85@8MHZ
select Programmer -> Arduino as ISP (or watever programmer you are using)
Select ->Burn bootloader

Quote
I'm not sure that all the code is supported by the attiny85

It is
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks everyone for the help!

I got it working properly.  I had the program set to 8MHz and the attiny was at 1MHz  smiley-red

I also was accidentally pulling down the reset pin, because I had the LED and CLR on the wrong pin.

Thanks again!

Karma Bump!
Logged

Pages: [1]   Go Up
Jump to: