Go Down

Topic: We've figured it out. Problem solved!! (Read 5786 times) previous topic - next topic

AKSoapy29

Sorry, but I don't get what your drawning means.
Andrew K.

CrossRoads

How were you able to wire up the arduino/shield/LED/buttons/resisters in your picture?
You must have been following some kind of schematic/layout.

Seperately from that,
Post the sketch  you want to run.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

AKSoapy29

I'm not following anything. I just made a diagram to help you with this. It's basically this:

Andrew K.

AKSoapy29

Andrew K.

AKSoapy29

#19
Dec 26, 2010, 10:32 pm Last Edit: Dec 26, 2010, 10:35 pm by Soapy29 Reason: 1
Refresh, or it's just you. Here's the link: http://www.vexforum.com/gallery/showimage.php?i=4873
Andrew K.

CrossRoads

Okay, you have the right idea for the buttons, just need to change the wiring a little.
The way you have it drawn, the button push is not able to change from hi to low.
Change it like this.
The resisters will pull pins 2,3,4 low, and when a button is pushed it will connect to 5V and can be read in as a high.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

AKSoapy29

So just change Ground and 5V in my drawing?
Andrew K.

AKSoapy29

Wait, nevermind. Is there something I have to change in my programming?
Andrew K.

CrossRoads

Changing 5V on the buttons to GND would work. If you have the D2,D3,D4 inputs set with the internals pullups enabled:

pinMode (D2, INPUT);
digitalWrite (D2, HIGH);  // enables internal pullup

then when the button is pressed the input would read as Low, and High the rest of the time.
You wouldn't need the resistors with the buttons at all.

Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

AKSoapy29

So the arrows on the switch goto what?
Andrew K.

AKSoapy29

#25
Dec 26, 2010, 11:15 pm Last Edit: Dec 26, 2010, 11:17 pm by Soapy29 Reason: 1
Here's what I have now:



And here's my code:
/*
 Button

Turns on and off a light emitting diode(LED) connected to digital  
pin 13, when pressing a pushbutton attached to pin 2.


The circuit:
* LED attached from pin 13 to ground
* pushbutton attached to pin 2 from +5V
* 10K resistor attached to pin 2 from ground

* Note: on most Arduinos there is already an LED on the board
attached to pin 13.


created 2005
by DojoDave <http://www.0j0.org>
modified 28 Oct 2010
by Tom Igoe

This example code is in the public domain.

http://www.arduino.cc/en/Tutorial/Button
*/

// constants won't change. They're used here to
// set pin numbers:
const int buttonPin1 = 2;     // the number of the pushbutton pin
const int ledPin1 =  8;      // the number of the LED pin
const int buttonPin2 = 3;     // the number of the pushbutton pin
const int ledPin2 =  9;      // the number of the LED pin
const int buttonPin3 = 4;     // the number of the pushbutton pin
const int ledPin3 =  10;      // the number of the LED pin

// variables will change:
int buttonState1 = 0;         // variable for reading the pushbutton status
int buttonState2 = 0;         // variable for reading the pushbutton status
int buttonState3 = 0;         // variable for reading the pushbutton status

void setup() {
 // initialize the LED pin as an output:
 pinMode(ledPin1, OUTPUT);      
 // initialize the pushbutton pin as an input:
 pinMode(buttonPin1, INPUT);    
  // initialize the LED pin as an output:
 pinMode(ledPin2, OUTPUT);      
 // initialize the pushbutton pin as an input:
 pinMode(buttonPin2, INPUT);
  // initialize the LED pin as an output:
 pinMode(ledPin3, OUTPUT);      
 // initialize the pushbutton pin as an input:
 pinMode(buttonPin3, INPUT);  
}

void loop(){
 // read the state of the pushbutton value:
 buttonState1 = digitalRead(buttonPin1);
   // read the state of the pushbutton value:
 buttonState2 = digitalRead(buttonPin2);
   // read the state of the pushbutton value:
 buttonState3 = digitalRead(buttonPin3);

 // check if the pushbutton is pressed.
 // if it is, the buttonState is HIGH:
 if (buttonState1 == LOW) {    
   // turn LED on:    
   digitalWrite(ledPin1, HIGH);  
 }
 else {
   // turn LED off:
   digitalWrite(ledPin1, LOW);
 }
   if (buttonState2 == LOW) {    
   // turn LED on:    
   digitalWrite(ledPin2, HIGH);  
 }
 else {
   // turn LED off:
   digitalWrite(ledPin2, LOW);
 }
   if (buttonState3 == LOW) {    
   // turn LED on:    
   digitalWrite(ledPin3, HIGH);  
 }
 else {
   // turn LED off:
   digitalWrite(ledPin3, LOW);
 }
}
Andrew K.

AWOL

#26
Dec 26, 2010, 11:19 pm Last Edit: Dec 26, 2010, 11:21 pm by AWOL Reason: 1
And posted correctly: (comments are a bit dodgy though)
Code: [Select]
/*
Button

Turns on and off a light emitting diode(LED) connected to digital  
pin 13, when pressing a pushbutton attached to pin 2.


The circuit:
* LED attached from pin 13 to ground
* pushbutton attached to pin 2 from +5V
* 10K resistor attached to pin 2 from ground

* Note: on most Arduinos there is already an LED on the board
attached to pin 13.


created 2005
by DojoDave <http://www.0j0.org>;
modified 28 Oct 2010
by Tom Igoe

This example code is in the public domain.

http://www.arduino.cc/en/Tutorial/Button
*/

// constants won't change. They're used here to
// set pin numbers:
const int buttonPin1 = 2;     // the number of the pushbutton pin
const int ledPin1 =  8;      // the number of the LED pin
const int buttonPin2 = 3;     // the number of the pushbutton pin
const int ledPin2 =  9;      // the number of the LED pin
const int buttonPin3 = 4;     // the number of the pushbutton pin
const int ledPin3 =  10;      // the number of the LED pin

// variables will change:
int buttonState1 = 0;         // variable for reading the pushbutton status
int buttonState2 = 0;         // variable for reading the pushbutton status
int buttonState3 = 0;         // variable for reading the pushbutton status

void setup() {
// initialize the LED pin as an output:
pinMode(ledPin1, OUTPUT);      
// initialize the pushbutton pin as an input:
pinMode(buttonPin1, INPUT);    
 // initialize the LED pin as an output:
pinMode(ledPin2, OUTPUT);      
// initialize the pushbutton pin as an input:
pinMode(buttonPin2, INPUT);
 // initialize the LED pin as an output:
pinMode(ledPin3, OUTPUT);      
// initialize the pushbutton pin as an input:
pinMode(buttonPin3, INPUT);  
}

void loop(){
// read the state of the pushbutton value:
buttonState1 = digitalRead(buttonPin1);
  // read the state of the pushbutton value:
buttonState2 = digitalRead(buttonPin2);
  // read the state of the pushbutton value:
buttonState3 = digitalRead(buttonPin3);

// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState1 == LOW) {    
  // turn LED on:    
  digitalWrite(ledPin1, HIGH);  
}
else {
  // turn LED off:
  digitalWrite(ledPin1, LOW);
}
  if (buttonState2 == LOW) {    
  // turn LED on:    
  digitalWrite(ledPin2, HIGH);  
}
else {
  // turn LED off:
  digitalWrite(ledPin2, LOW);
}
  if (buttonState3 == LOW) {    
  // turn LED on:    
  digitalWrite(ledPin3, HIGH);  
}
else {
  // turn LED off:
  digitalWrite(ledPin3, LOW);
}
}
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

CrossRoads

One contact on the switch goes to ground, one contact goes to an arduino pin.
The switch may have pins, am pretty sure the pins are connected in pairs.

Scroll down to where it says 'pcb layout' on this datasheet as an example.
http://www.sparkfun.com/datasheets/Components/Buttons/KSA_KSLMKII_4feb.pdf
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

AKSoapy29

Ok, I have them setup like you said. I posted my code above, and the led doesn't light. :(
Andrew K.

CrossRoads

#29
Dec 26, 2010, 11:25 pm Last Edit: Dec 26, 2010, 11:25 pm by CrossRoads Reason: 1
Just add this to the input definitions to ensure the pin is high when the button is not pressed.
// initialize the pushbutton pin as an input:
pinMode(buttonPin1, INPUT);
[glow]digitalWrite(buttonPin1, HIGH);  //enable internal pullup resister[/glow]
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Go Up