165Views7Replies

Author Options:

How to get a arduino to use 3push buttons as inputs, and output a different signal on a speaker Answered

Hey all,
 I am new to the whole arduino using world.  I have a project that uses 3push buttons, a  breadboard, arduino, lcd display, and speaker.
The goal is to write program to play a certain freq. signal through the speaker, (each pushbutton has it's own frequency for the signal) when each of the buttons is pushed, and also display each signal on  the LCD display while doing it.

Comments

The forums are retiring in 2021 and are now closed for new topics and comments.
0
dsm5286
dsm5286

Answer 8 years ago

I got it figured out. Thanks for help. I started over from scratch and made each button it's own const int and each it's own button state, added in the LCD pin at Tx, and added the sub routines, and after few hours of fixing little typo's got it to work. Again thanks for the help.

0
steveastrouk
steveastrouk

8 years ago

Start simple: Use the examples in the Arduino IDE and make sure they work the bits you have. Learn how to read buttons, learn how to write to the LCD, learn how to make tones. Once you can do that, the code for the thing is very simple.

Steve

0
dsm5286
dsm5286

Answer 8 years ago

I have some code written. for setting up the buttons. The first two work, but the last one doesn't, and it just keeps playing one tone even if none are pressed...and I have the part down to write to the lcd.. I've made simple tones, but it keeps telling me I didn't define pitches.h in my program in one window, but if i copy and paste it to another blank page, it does what I described earlier in this reply.

0
steveastrouk
steveastrouk

Answer 8 years ago

Post your code. Do you have pull up resistors on your buttons, or pull downs ? "pitches.h" implies you are using a library. Where's it from ?

0
dsm5286
dsm5286

Answer 8 years ago

#include "pitches.h"


const int button = 0; // the number of the pushbutton pin
int buttonState = 0; // variable for reading the pushbutton status
// notes to play, corresponding to the 3 sensors:

int notes[] = {
NOTE_A3, NOTE_B4, NOTE_C3};

void setup() {
pinMode(button, INPUT);
// initialize the pushbutton pin as an input
}

void loop() {
for (int button = 0; button < 3; button++) {
// get a sensor reading:
int buttonState = digitalRead(button);

// if the sensor is pressed hard enough:
if (buttonState == HIGH) {
// play the note corresponding to this sensor:
tone(8, notes[button]);
}
}
}
here is the code so far. and once i get it to work properly by addin a no tone when digitalread=0 then i will move the button pins to 2-4 and add LCD code.

0
steveastrouk
steveastrouk

Answer 8 years ago

But you only have ONE button defined in the setup, and that is digital Pin 0.