**HELP** Button.h library compile errors

Hello All

I am trying to compile an old program I have and I am getting some compile errors

#include <Servo.h>
#include <Button.h>

 This program was written for an Arduino powered GoKart.  
 Press GO and the kart with ramp up to top speed
 This is done trough PWM to a motor controller
 Press REV and the kart will go into reverse with a preset max speed
 This is also done through PWM to a motor controller

Button goButton(7,PULLUP);
Button revButton(8,PULLUP);

int leftPin = 9;      // left motor controller connected to digital pin 9
int rightPin = 10;      // right motor controller connected to digital pin 10
byte  goPos = 0;      //Go loop counter
byte  revPos = 0;     //Reverse loop counter  

void setup()  
  Serial.begin (9600);
  pinMode(leftPin = 9, OUTPUT);
  pinMode(rightPin = 10, OUTPUT);

void loop()  
    if (goPos <= 255) {goPos ++;}
    if (goPos > 255)  {goPos = 255;}
    analogWrite(leftPin, goPos);
    analogWrite(rightPin, goPos);
    Serial.print(goPos, DEC);
    goPos = 90;

I am getting this error:

ArduKart.pde:-1: error: ‘PULLUP’ was not declared in this scope
ArduKart.pde:-1: error: ‘PULLUP’ was not declared in this scope


Scott Portocarrero

Can we see the Button.h header file's contents?

pinMode(leftPin = 9, OUTPUT);
pinMode(rightPin = 10, OUTPUT);

What are you doing? I don't think that you can assign a value as a parameter to pinMode(). Do you mean:

pinMode(leftPin, OUTPUT);
pinMode(rightPin, OUTPUT);

Here you go

/* $Id$
|| @file 		       Button.cpp
|| @author 		     Alexander Brevig              <alexanderbrevig@gmail.com>        
|| @url            http://alexanderbrevig.com
|| @description
|| | This is a Hardware Abstraction Library for Buttons
|| | It providea an easy way of handling buttons
|| #

#ifndef Button_h
#define Button_h

#include <inttypes.h>


class Button;
typedef void (*buttonEventHandler)(Button&);

class Button {
    Button(uint8_t buttonPin, uint8_t buttonMode=BUTTON_PULLUP_INTERNAL);
    void pullup(uint8_t buttonMode);
    void pulldown();
    bool isPressed();
    bool wasPressed();
    bool stateChanged();
    bool uniquePress();
    void setHoldThreshold(unsigned int holdTime);
    bool held(unsigned int time=0);
    bool heldFor(unsigned int time);
    void pressHandler(buttonEventHandler handler);
    void releaseHandler(buttonEventHandler handler);
    void clickHandler(buttonEventHandler handler);
    void holdHandler(buttonEventHandler handler, unsigned int holdTime=0);
    unsigned int holdTime() const;
    inline unsigned int presses() const { return numberOfPresses; }
    bool operator==(Button &rhs);
    uint8_t pin;
    uint8_t mode;
    uint8_t state;
    unsigned int pressedStartTime;
    unsigned int holdEventThreshold;
    buttonEventHandler cb_onPress;
    buttonEventHandler cb_onRelease;
    buttonEventHandler cb_onClick;
    buttonEventHandler cb_onHold;
    unsigned int numberOfPresses;
    bool triggeredHoldEvent;


In your sketch try changing PULLUP to BUTTON_PULLUP

No that didn't work

[quote author=Scott Portocarrero link=topic=114427.msg873593#msg873593 date=1343337609] No that didn't work

[/quote] What is the new error?

I stumbled onto this old topic as had the same problem using the button library in the Playground. I then found that the library has since been improved and seems to work OK now with Arduino 1.05 and using a Mega and four button objects. I had to change my PULLDOWN keyword to BUTTON_PULLDOWN when creating a button object.