Go Down

Topic: Button Function (Read 892 times) previous topic - next topic

tjdichoso

Hello Friends,

I have a project where I want to press a button multiple times, depending on the number of times I press the button, a certain function happens. I found this code online and am modifying it from here to do my own functions.
Code: [Select]
#include <Button.h>
/*
create a Button object at pin 12
connect button between pin 12 and GND
*/


Button button = Button(12,PULLDOWN);

void setup(){
  pinMode(8,OUTPUT); //debug to led 13
  pinMode(9,OUTPUT);
  pinMode(7,OUTPUT);
 
 
}
byte pressCount = 0;
void loop(){

  if (button.uniquePress())
pressCount++;

switch(pressCount)
       
        {case 1:
         
          digitalWrite(7,HIGH);
        digitalWrite(9,LOW);
        digitalWrite(8,LOW);
 
  break;

  case 2:
 

        digitalWrite(8,HIGH);
        digitalWrite(7,LOW);
        digitalWrite(6,LOW);
   
   break;
   case 3:
     
 

        digitalWrite(9,HIGH);
        digitalWrite(8,LOW);
        digitalWrite(7,LOW);
       
pressCount = 0;
       break; 

  }


   }


I downloaded and installed the library from here:
http://arduino.cc/playground/Code/Button#CurrentVersion

When I compile the sketch I keep getting the following message:
Quote
no matching function for call 'Button::Button(int,int)'


Do you know what's up?

dc42

Which Arduino software version are you using? There are different Button libraries for Arduino 0022 and Arduino 1.0. Are you sure you have the right one? Note that PULLDOWN in the 0022 library was changed to BUTTON_PULLDOWN in the 1.0 library.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Cybernetician

change the include file

Wprogram.h to  "Arduino.h" in button.h

cheers
From Idea To Invention

hi can help me it will in upload to the arduino but when i try to use then push button nuff working why?

Code: [Select]


int initializingsdcard =
  lcd.print ("Initializing");
  lcd.setCursor(0, 1);
  lcd.print("SD card");
  delay(2000);
  lcd.clear();
 
  pinMode(10, OUTPUT);
 
if (!SD.begin(10)) {
lcd.print("Sd Card Failed!");  //pass or fail if fail Retry or Skip (Skip USB Only not memu for pics
lcd.setCursor(1, 1);
lcd.print("Skip");// if buron pres go down to Resetting Motors (skip use only usb only for pc
lcd.print(" -- ");
lcd.print("Retry");

  buttonState1 = digitalRead(buttonselect);  // read the state of the pushbutton value:
  if (buttonState1 == HIGH) {     // check if the pushbutton is pressed.
  int initializingsdcard;
}
  else {                                 
     return; // stop code
  }
 
     // retry sd card agean if find said Sd Card Pass if not find go back to  skip or retey screen
 
 
return;
     }
  root = SD.open("/");
 
  printDirectory(root, 0);
 
lcd.print("Sd Card Pass!");

 

JimboZA

That code will very definitely not upload, because what you posted doesn't compile.
"Could you do the egg bacon spam and sausage without the spam then? "

No PMs for help please.
DO NOT power servos from Arduino 5V: give them their own power and connect the grounds.

well it dos and i lost try thing it but nuffin here full code is

Code: [Select]

           

#include <LiquidCrystal_I2C.h>
#include <Stepper.h>
#include <SD.h>
#include <SPI.h>
#include <Wire.h>

LiquidCrystal_I2C lcd (0x27,16,2);


const int buttonmenu = A0; // sd retry and Menu and burn (menu file Dellete)
const int buttonselect = A1; // sd skip and Select and Cancel
const int buttonup = A2; // Up
const int buttondown = A3; // Dowm
const int buttonleft = A4; // Left
const int buttonright = A5; // Right can go to menu enter

int buttonState = 0; // Retry
int buttonState1 = 0; // Skip
int buttonState2 = 0; // Up
int buttonState3 = 0; // Down
int buttonState4 = 0; // Left
int buttonState5 = 0; // Right

                  // Y axis
int motorPin1 = 2;    // Blue   - 28BYJ48 pin 1
int motorPin2 = 3;    // Pink   - 28BYJ48 pin 2
int motorPin3 = 4;    // Yellow - 28BYJ48 pin 3
int motorPin4 = 5;    // Orange - 28BYJ48 pin 4
                  // X axis
int motorPin5 = 6;    // Blue   - 28BYJ48 pin 1
int motorPin6 = 7;    // Pink   - 28BYJ48 pin 2
int motorPin7 = 8;    // Yellow - 28BYJ48 pin 3
int motorPin8 = 9;    // Orange - 28BYJ48 pin 4


// FULLSTEP 4 2048 monter spin
// HALFSTEP 8 1024 monter spin


              // sd card 10 11 12 13

//   * SD card attached to SPI bus as follows:
// ** CS - Pin 10 depends on your SD card shield or module.
// ** MOSI - pin 11 on Arduino Uno
// ** CLK - pin 13 on Arduino Uno
// ** MISO - pin 12 on Arduino Uno

//////////////////////////////////////////////////////////////////////////////
     
void setup()
{

          // Y axis
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);
           // X axis
pinMode(motorPin5, OUTPUT);
pinMode(motorPin6, OUTPUT);
pinMode(motorPin7, OUTPUT);
pinMode(motorPin8, OUTPUT);

//motor.setSpeed(20);

  File root;
 
  //////////////////////////////////////////////////////////////////////////////
 
  lcd.init();                      // initialize the lcd
  lcd.backlight();
  Serial.begin(9600);
 
 
  // put your setup code here, to run once:
  // Print a message to the LCD.
 
  lcd.print("Blu Ray Laser");
  lcd.setCursor(0, 1);
  lcd.print("cnc Machine V0.4");
  Serial.print("Arduino blu ray laser cnc machine"); 
  delay(6000);
  lcd.clear();
 
  int initializingsdcard;
  lcd.print ("Initializing");
  lcd.setCursor(0, 1);
  lcd.print("SD card");
  delay(2000);
  lcd.clear();
 
  pinMode(10, OUTPUT);
 
if (!SD.begin(10)) {
lcd.print("Sd Card Failed!"); 
lcd.setCursor(1, 1);
lcd.print("Retry"); // Retry the sd card
lcd.print(" -- ");
lcd.print("Skip");// if buron pres go down to Resetting Motors (skip use only usb only for pc - dont show menu option

  buttonState = digitalRead(buttonmenu);  // read the state of the pushbutton value:
  if (buttonState == HIGH) {     // check if the pushbutton is pressed.
  int initializingsdcard;
}
  else {                                 
     return; // stop code
  }
 
     // retry sd card agean if find said Sd Card Pass if not find go back to  skip or retey screen
 
 
return;
     }
  root = SD.open("/");
 
  printDirectory(root, 0);
 
lcd.print("Sd Card Pass!");
delay(2000);
lcd.clear();
 
lcd.setCursor(0, 0);
int resettingmotors;
lcd.print ("Resetting Motors");
  // move to motors to home places 0x0

//  motor buttun high to stop motor
 
delay(5000);
lcd.clear();
 
  lcd.print("Laser Ready");
  lcd.setCursor(0, 1);
 
 
// lcd.print("USB"); when it find usb comport of the computer
  lcd.setCursor(12, 1);

/*   
  lcd.print("Menu"); //Menu for pics to load up (example pic cat slect then burn or cancel (cancel back  to pics


}

void loop()
{
  // put your main code here, to run repeatedly:
}

               //sd card
  // nothing happens after setup finishes.

void printDirectory(File dir, int numTabs) {
   while(true) {
     
     File entry =  dir.openNextFile();
     if (! entry) {
       // no more files
       //Serial.println("**nomorefiles**");
       break;
     }
     for (uint8_t i=0; i<numTabs; i++) {
       Serial.print('\t');
     }
     Serial.print(entry.name());
     if (entry.isDirectory()) {
       Serial.println("/");
       printDirectory(entry, numTabs+1);
     } else {
       // files have sizes, directories do not
       Serial.print("\t\t");
       Serial.println(entry.size(), DEC);
     }
     entry.close();
   }
   
}

UKHeliBob

Quote
here full code is
That won't compile either.

Quote
// nothing happens after setup finishes.
That's because you don't have anything in the loop() function
Code: [Select]
void loop()
{
  // put your main code here, to run repeatedly:
}


When you read the button press in setup() all that happens is that the initializingsdcard variable is declared but is not given a value.  As it is not a global variable its value could be anything but that does not matter because it is never checked or used.
Code: [Select]
  buttonState = digitalRead(buttonmenu);  // read the state of the pushbutton value:
  if (buttonState == HIGH)
  {     // check if the pushbutton is pressed.
    int initializingsdcard;
  }
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

dave-in-nj

I suggest you go back to basics.

open the sketch button all by itself.   
add an led output for each stage you want.
alter 'button' it to light the number of LED's you have as different outputs or different stages.

then press the button and have the program change which LED is lit.

you might look at debounce as well.   similar to button, it adds a timing.

if you want to add a reset, hold the button for some duration so that a new 'IF' you create to see if the button has been held for a full 2 seconds has occurred (or some such)

once you have that part running properly, then merge your other code with it.

trying to get a multitude of features to all work together can cause a lot more confusion, best to get each segment working as a separate part, then merge them.





thanks try basics and work but try put Button to restart sdcard but that in setup got told to use SD init code into a function but how to do that when Button going to void loop and thing no guild to do that

dave-in-nj

Quote

I have a project where I want to press a button multiple times, depending on the number of times I press the button, a certain function happens.


slow down.   if you want to press the button multiple times and depending on the number of times, a certain function happens, then get one thing going at a time.

have you successfully wired up 3 LED's and then got each to light, depending on how you pressed the button ?

you cannot just load button and one led and then jump to reading SD cards.

write your own code to get one led to light when you press the button one time, then get a different LED to light when you press the button a second time, and then get a 3rd LED to light wen you press it a 3rd time, then all off when you press it a 4th time.

once you have that, then you have 4 places you can add code to make things happen.

once you have that, save that and open a completely blank sketch and do what you need to do on your SD card, record or play.  just use a simple switch.

once you have that function working, copy it and paste it when ONE led was being lit and  get it to work in ONE of the places the button will light an LED.

that would be a major milestone.   it would also give you more places to add more code.



no i have done one and  button
going try now
but it is same for function  or dint code when going them

ok help try to do to 9 led and 1 button but have no look and books and or site or code out ther to help me out

gunske

So what's the sollution for the
Quote
no matching function for call 'Button::Button(int,int)'

?
I ran into the same fault, spending my night searching for a sollution, but without succes  :smiley-sad-blue:

PaulS

Quote
I ran into the same fault, spending my night searching for a sollution, but without succes

Is there some part of the error message that you don't understand? The compiler is telling you that there is no version of the Button constructor that takes two integer arguments. So, the question is why do you assume that there is?

gunske

Fixed (2solutions);

You have to manually remove all the "button." files then add the newest library
or rename the newest version button-file and add it to the library (fastest way)

Go Up