Show Posts
Pages: [1]
1  Using Arduino / Audio / Re: What is the best audio playback shield for 20 or 30 words? on: April 28, 2013, 07:40:10 pm
Not sure Adafruit can do that many words.  A recent article in Servo Magazine http://www.servomagazine.com/, featured an Arduino based shield that can play at least 30 words.
I can look for the article if you can't find it.
2  Using Arduino / Audio / Re: Using arduino to trigger sound (Need Help, Am Noob) on: April 26, 2013, 08:45:00 pm
I had good luck with Lady Ada's waveshield which can be ordered from her WEb site, http://www.ladyada.net/make/waveshield/index.html   Also, as Marco_s touched on, the easiest solution was to use two Arduino's  -  one, an Uno, that the waveshield sits on and is dedicated to it.   And an older one I happened to have that only has to process my inputs (a bunch of reed switches that respond to a passing magnet) and turn them into clean 100 millisec output pulses.  These are fed into the Uno inputs through 500 ohm resistors to start each of six songs.  The two Arduinos use the same power supply and shared ground.

Some of my "songs" are actally voices, etc.   I use "Audacity" to process the material and make it compatible with the waveshield SD card.  To program IR sensor inputs should be very similar to what I have done and I believe sample code for this is available in "Arduino Examples".

Good luck.

 



3  Using Arduino / Programming Questions / Re: Two buttons - one output on: February 02, 2013, 02:04:53 pm
Problem solved!   Using hardware that actually works  -  plus code recommended by the Forum.  Thanks again for helping out.

Code:
/*
  TWO BUTTONS  -  ONE OUTPUT
 
 Turns on a light emitting diode(LED) when pressing one pushbutton;
 and off again when pressing a second button. LED stays on in between. 
 
 The circuit:
 * LED attached from pin 13 to ground
 * pushbuttons attached to pins 2 and 3 with 10k pull-down resistors to ground.
 
 Written 2/1/13 by
 Telefondreng.
 */

// constants used to
// set pin numbers:
const int button1 = 2;     // the number of the 1st pushbutton pin
const int button2 = 3;         // the 2nd
const int ledPin =  13;      // the number of the LED pin



void setup()
{
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);     
  // initialize the 1st pushbutton pin as an input:
  pinMode(button1, INPUT);   
  //initialize 2nd pushbutton
  pinMode(button2, INPUT);
 
  digitalWrite (ledPin,LOW);
 
}

void loop()
{
  if ( digitalRead(button1))
    {
      digitalWrite (ledPin,HIGH);
    } 
  if (digitalRead(button2))
    {
      digitalWrite(ledPin,LOW);
    } 
 } 

 
 
4  Using Arduino / Programming Questions / Re: Two buttons - one output on: February 01, 2013, 01:55:10 pm
Apologies are in order!  One of my test buttons from the junkbox was a normally-on type (didn't even know they exist), keeping pin 3 high instead of low. smiley-cry
Going back to test all the code previously submitted.
5  Using Arduino / Programming Questions / Re: Two buttons - one output on: February 01, 2013, 01:06:06 am
Sorry about the long absence from this project  (dental implant && medications == brain, OFF) but thanks for all the suggestions and debate.

The circuit and components  -  simple as it is  -  has been checked forwards and backwards.  The two if statements work by themselves, turning the Led on or off.  I.e. the innards of the Arduino are not at fault.  Yet, can not get them to work together.
Went back to external pull-down resistors.  Agree that debouncing should not be needed here (the two "push buttons" are in fact reed switches, reliably activated by a train to set or clear a red signal).

The post by lloyddean pretty much summarizes previous ideas, including reading the output pin as an argument in the on/off function. (is const uint8_t the same as const int; the former won't work in my version).
But OFF_BUTTON (= button2) does not work in this sketch.  Not sure what serial.print could tell us here that can not be seen with the Led on pin 13.

Still open to ideas
6  Using Arduino / Programming Questions / Re: Two buttons - one output on: January 29, 2013, 04:09:52 pm
Still not there.  Checked circuit and grounding and put a flag into the code. Now, button 2 turns LED on momentarily and nothing with button 1.

Code:
/*
 
 Turns on a light emitting diode(LED) connected to digital 
 pin 13, when pressing one pushbutton attached to pin 2,
 and off again when pressing a second button, attached to pin 3.
 
 The circuit:
 * LED attached from pin 13 to ground
 * pushbuttons attached to pins 2 and 3 from ground
 
 Written 1/27/13
 */

// constants used to
// set pin numbers:
const int button1 = 2;     // the number of the 1st pushbutton pin
const int button2 = 3;         // the 2nd
const int ledPin =  13;      // the number of the LED pin

// variables may change:
int flag = HIGH;

void setup()
{
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);     
  // initialize the 1st pushbutton pin as an input:
  pinMode(button1, INPUT);   
  //turn on internal pull-up resistor
  digitalWrite (button1,HIGH);
  //initialize 2nd pushbutton
  pinMode(button2, INPUT);
  //turn on pull-up resistor
  digitalWrite(button2,HIGH);
 
}

void loop()
{
  if (digitalRead (button1) && flag == HIGH)
    {
      flag = LOW;
      digitalWrite (ledPin,flag);
    }
  if (digitalRead (button2) && flag == LOW)
    {
      flag = HIGH;
      digitalWrite (ledPin,flag);
    }   
 } 

 
 
7  Using Arduino / Programming Questions / Re: Two buttons - one output on: January 28, 2013, 11:26:02 pm
Thanks guys.  We are getting closer!  Now button1 turns on LED, but the led does not stay on.  The goal was to make the led stay on after one momentary button push.  And use the second button to turn it off.

Code:
/*
 
 Turns on and off a light emitting diode(LED) connected to digital 
 pin 13, when pressing pushbuttons attached to pins 2 and 3.
 
 The circuit:
 * LED attached from pin 13 to ground
 * pushbuttons attached to pins 2 and 3 from ground
 
 Written 1/27/13
 */

// constants used to
// set pin numbers:
const int button1 = 2;     // the number of the 1st pushbutton pin
const int button2 = 3;         // the 2nd
const int ledPin =  13;      // the number of the LED pin

// variables may change:
int pressed = 0;

void setup()
{
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);     
  // initialize the 1st pushbutton pin as an input:
  pinMode(button1, INPUT);   
  //turn on internal pull-up resistor
  digitalWrite (button1,HIGH);
  //initialize 2nd pushbutton
  pinMode(button2, INPUT);
  //turn on pull-up resistor
  digitalWrite(button2,HIGH);
 
}

void loop()
{
  if (digitalRead (button1) == pressed)
    digitalWrite (ledPin,HIGH);
  else if (digitalRead (button2) == pressed)
    digitalWrite (ledPin,LOW); 
 } 

 
 
8  Using Arduino / Programming Questions / Re: Two buttons - one output on: January 28, 2013, 03:06:37 pm
Thanks for the helpful hint re. copying code to Forum.  Here is the code  -  cleaned up and still not working.

Code:
/*
 
 Turns on and off a light emitting diode(LED) connected to digital 
 pin 13, when pressing pushbuttons attached to pins 2 and 3.
 
 The circuit:
 * LED attached from pin 13 to ground
 * pushbuttons attached to pins 2 and 3 from ground
 
 Written 1/27/13
 */

// constants used to
// set pin numbers:
const int button1 = 2;     // the number of the 1st pushbutton pin
const int button2 = 3;         // the 2nd
const int ledPin =  13;      // the number of the LED pin

// variables may change:
int pressed = 0;

void setup()
{
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);     
  // initialize the 1st pushbutton pin as an input:
  pinMode(button1, INPUT);   
  //turn on internal pull-up resistor
  digitalWrite (button1,HIGH);
  //initialize 2nd pushbutton
  pinMode(button2, INPUT);
  //turn on pull-up resistor
  digitalWrite(button2,HIGH);
 
}

void loop()
{
  if (button1 == pressed)
    digitalWrite (ledPin,HIGH);
  else if (button2 == pressed)
    digitalWrite (ledPin,LOW); 
 } 

 
 
9  Using Arduino / Programming Questions / Re: Two buttons - one output on: January 28, 2013, 01:05:50 pm
Used the if statement in the following sketch.  The led is not coming on. Not sure where the variable, pressed, should be declared.

Code:
[quote]

[color=#7E7E7E]/*[/color]
[color=#7E7E7E] [/color]
[color=#7E7E7E] Turns on and off a light emitting diode(LED) connected to digital  [/color]
[color=#7E7E7E] pin 13, when pressing pushbuttons attached to pins 2 and 3. [/color]
[color=#7E7E7E] [/color]
[color=#7E7E7E] The circuit:[/color]
[color=#7E7E7E] * LED attached from pin 13 to ground [/color]
[color=#7E7E7E] * pushbuttons attached to pins 2 and 3 from ground[/color]
[color=#7E7E7E] [/color]
[color=#7E7E7E] Written 1/27/13[/color]
[color=#7E7E7E] */[/color]

[color=#7E7E7E]// constants won't change. They're used here to [/color]
[color=#7E7E7E]// set pin numbers:[/color]
const [color=#CC6600]int[/color] button1 = 2;     [color=#7E7E7E]// the number of the 1st pushbutton pin[/color]
const [color=#CC6600]int[/color] button2 = 3;         [color=#7E7E7E]// the 2nd[/color]
const [color=#CC6600]int[/color] ledPin =  13;      [color=#7E7E7E]// the number of the LED pin[/color]

[color=#7E7E7E]// variables may change:[/color]
[color=#CC6600]int[/color] pressed = 0;

[color=#CC6600]void[/color] [color=#CC6600][b]setup[/b][/color]()
{
  [color=#7E7E7E]// initialize the LED pin as an output:[/color]
  [color=#CC6600]pinMode[/color](ledPin, [color=#006699]OUTPUT[/color]);     
  [color=#7E7E7E]// initialize the 1st pushbutton pin as an input:[/color]
  [color=#CC6600]pinMode[/color](button1, [color=#006699]INPUT[/color]);   
  [color=#7E7E7E]//turn on internal pull-up resistor[/color]
  [color=#CC6600]digitalWrite[/color] (button1,[color=#006699]HIGH[/color]);
  [color=#7E7E7E]//initialize 2nd pushbutton[/color]
  [color=#CC6600]pinMode[/color](button2, [color=#006699]INPUT[/color]);
  [color=#7E7E7E]//turn on pull-up resistor[/color]
  [color=#CC6600]digitalWrite[/color](button2,[color=#006699]HIGH[/color]);
  
}

[color=#CC6600]void[/color] [color=#CC6600][b]loop[/b][/color]()

  [color=#CC6600]if[/color] (button1 == pressed)
    [color=#CC6600]digitalWrite[/color] (ledPin,[color=#006699]HIGH[/color]);
  [color=#CC6600]else[/color] [color=#CC6600]if[/color] (button2 == pressed)
    [color=#CC6600]digitalWrite[/color] (ledPin,[color=#006699]LOW[/color]); 
 }  

  
 

[/quote]
10  Using Arduino / Programming Questions / Two buttons - one output on: January 27, 2013, 01:32:33 am
Almost embarassed to post such a seemingly simple problem.  How do you make an output HIGH  -  i.e turn on a LED  and keep it on  -  by pushing one button, and turn it off with another?  Both buttons are momentary.
Pages: [1]