Two buttons and beep

Hello,

I need to develop a project on the following basis, need to read two buttons, BNT1 and BNT2 when BNT1 is pressed need a continuous beeb is issued, this sliding beep should no longer be continued when BNT2 is pressed and should become flashing, after 10 seconds it should accelerate and finally silence back to the waiting state by BNT1 again. Could someone give me a light where to start?

Thank

What programming have you done in the past?
Have you worked with any electronic projects before, what?
What is this project for?

LarryD:
What programming have you done in the past?
Have you worked with any electronic projects before, what?
What is this project for?

Yes, I have worked with Arduino, I can change some things, but I can not start a zero programming. :frowning: Yes, I rode simulators of traffic lights.

I need that when a person reaches an electric door she requested passage on the button 1, when requesting the sliding beep should initiate the transition to be released in 2 button it start beeping and the missing 10 seconds start accelerating beep.

What is “sliding beep” ?

You can create an audio frequency on a pin with:
tone(pin,frequency,duration)
https://www.arduino.cc/en/Reference/Tone

You can turn off a tone with:
noTone(pin);

You can time things using millis() see BWD (blink without delay techniques, example in the IDE)
See attached example .ino file

For information on switches see:
http://www.gammon.com.au/forum/?id=11955

Edit
Added a second BWD example
.

SwitchManagerExample1.ino (7.19 KB)

_1BWDTechniqueStandardVer1.ino (6 KB)

I just can’t resist those little puzzles. I made you an implementation in Automaton. The solution is in State Machines alright, but I prefer them neatly encapsulated in objects. I used a player state machine and a bunch of led, button and timer machines (all bundled with Automaton) to put this together. As for the sliding beep, I improvised something, perhaps you’ll like it.

#include <Automaton.h>

Atm_player player;
Atm_button button1, button2;
Atm_led led;
Appliance app;

const int pinBuzzer = 19;
const int pinButton1 = 2;
const int pinButton2 = 3;
const int pinLed = 4;
const int blinkRate1 = 500;
const int blinkRate2 = 100;
const int noOfBlinks1 = 10; // 10s speed up blink
const int noOfBlinks2 = 150; // 30s turn off led

int pattern[] = {  // Sound pattern: freq, duration, pause,
  880, 50, 0, 
  890, 50, 0, 
  900, 50, 0, 
  910, 50, 0, 
  920, 50, 0, 
  930, 50, 0, 
  940, 50, 0, 
  950, 50, 0, 
  960, 50, 0, 
  970, 50, 0, 
};

void setup() {
  app.component( 
    player.begin( pinBuzzer )
      .play( pattern, sizeof( pattern ) )
      .repeat( -1 )
  );
  app.component( 
    led.begin( pinLed )
      .onFinish( [] ( int idx, int v, int up ) {
        static bool first = true;
        if ( first ) {
          led.blink( blinkRate2, blinkRate2, noOfBlinks2  ).trigger( led.EVT_BLINK );           
          first = false;
        }
      })
  );
  app.component( 
    button1.begin( pinButton1 ) 
      .onPress( player, player.EVT_START )
  );  
  app.component( 
    button2.begin( pinButton2 ) 
      .onPress( []( int idx, int v, int up ) {
        player.trigger( player.EVT_STOP );  
        led.blink( blinkRate1, blinkRate1, noOfBlinks1 ).trigger( led.EVT_BLINK );
      })
  );
}

void loop() {
  app.run();
}

You’ll need the latest master branch of Automaton, it can be found here: https://github.com/tinkerspy/Automaton/wiki

Edit: I dropped the timers and used the blinking led as a timer. (10 blinks = 10s, etc)

camalau:
Hello,

I need to develop a project on the following basis, need to read two buttons, BNT1 and BNT2 when BNT1 is pressed need a continuous beeb is issued, this sliding beep should no longer be continued when BNT2 is pressed and should become flashing, after 10 seconds it should accelerate and finally silence back to the waiting state by BNT1 again. Could someone give me a light where to start?

Which type of buzzer are you using? An “active buzzer” which starts buzzing when you provide OUTPUT/HIGH or a “passive buzzer” which starts buzzing when driven with an audio frequency, like created by the "tone() function and which can beep in different frequencies?

LarryD:
What is "sliding beep" ?

You can create an audio frequency on a pin with:
tone(pin,frequency,duration)
tone() - Arduino Reference

You can turn off a tone with:
noTone(pin);

You can time things using millis() see BWD (blink without delay techniques, example in the IDE)
See attached example .ino file

For information on switches see:
Gammon Forum : Electronics : Microprocessors : Switches tutorial

Edit
Added a second BWD example
.

Thank you for your support with examples. I will study all possibilities.

Tinkerspy:
I just can’t resist those little puzzles. I made you an implementation in Automaton. The solution is in State Machines alright, but I prefer them neatly encapsulated in objects. I used a player state machine and a bunch of led, button and timer machines (all bundled with Automaton) to put this together. As for the sliding beep, I improvised something, perhaps you’ll like it.

#include <Automaton.h>

Atm_player player;
Atm_button button1, button2;
Atm_led led;
Appliance app;

const int pinBuzzer = 19;
const int pinButton1 = 2;
const int pinButton2 = 3;
const int pinLed = 4;
const int blinkRate1 = 500;
const int blinkRate2 = 100;
const int noOfBlinks1 = 10; // 10s speed up blink
const int noOfBlinks2 = 150; // 30s turn off led

int pattern = {  // Sound pattern: freq, duration, pause,
 880, 50, 0,
 890, 50, 0,
 900, 50, 0,
 910, 50, 0,
 920, 50, 0,
 930, 50, 0,
 940, 50, 0,
 950, 50, 0,
 960, 50, 0,
 970, 50, 0,
};

void setup() {
 app.component(
   player.begin( pinBuzzer )
     .play( pattern, sizeof( pattern ) )
     .repeat( -1 )
 );
 app.component(
   led.begin( pinLed )
     .onFinish( ( int idx, int v, int up ) {
       static bool first = true;
       if ( first ) {
         led.blink( blinkRate2, blinkRate2, noOfBlinks2  ).trigger( led.EVT_BLINK );          
         first = false;
       }
     })
 );
 app.component(
   button1.begin( pinButton1 )
     .onPress( player, player.EVT_START )
 );  
 app.component(
   button2.begin( pinButton2 )
     .onPress( ( int idx, int v, int up ) {
       player.trigger( player.EVT_STOP );  
       led.blink( blinkRate1, blinkRate1, noOfBlinks1 ).trigger( led.EVT_BLINK );
     })
 );
}

void loop() {
 app.run();
}




You'll need the latest master branch of Automaton, it can be found here: https://github.com/tinkerspy/Automaton/wiki

Edit: I dropped the timers and used the blinking led as a timer. (10 blinks = 10s, etc)

Thank you for your support. The quickest way, it was just what I needed.