Pages: 1 [2] 3 4 5   Go Down
Author Topic: We've figured it out. Problem solved!!  (Read 5480 times)
0 Members and 1 Guest are viewing this topic.
Minnesota!
Offline Offline
Sr. Member
****
Karma: 0
Posts: 388
My nickname on the forum used to be Soapy29.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Andrew K.

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 545
Posts: 27352
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Minnesota!
Offline Offline
Sr. Member
****
Karma: 0
Posts: 388
My nickname on the forum used to be Soapy29.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

Andrew K.

Minnesota!
Offline Offline
Sr. Member
****
Karma: 0
Posts: 388
My nickname on the forum used to be Soapy29.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The yellow should be black. Whoops..
Logged

Andrew K.

Minnesota!
Offline Offline
Sr. Member
****
Karma: 0
Posts: 388
My nickname on the forum used to be Soapy29.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Refresh, or it's just you. Here's the link: http://www.vexforum.com/gallery/showimage.php?i=4873
« Last Edit: December 26, 2010, 04:35:31 pm by Soapy29 » Logged

Andrew K.

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 545
Posts: 27352
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Minnesota!
Offline Offline
Sr. Member
****
Karma: 0
Posts: 388
My nickname on the forum used to be Soapy29.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

So just change Ground and 5V in my drawing?
Logged

Andrew K.

Minnesota!
Offline Offline
Sr. Member
****
Karma: 0
Posts: 388
My nickname on the forum used to be Soapy29.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Andrew K.

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 545
Posts: 27352
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Minnesota!
Offline Offline
Sr. Member
****
Karma: 0
Posts: 388
My nickname on the forum used to be Soapy29.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

So the arrows on the switch goto what?
Logged

Andrew K.

Minnesota!
Offline Offline
Sr. Member
****
Karma: 0
Posts: 388
My nickname on the forum used to be Soapy29.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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);
  }
}
« Last Edit: December 26, 2010, 05:17:34 pm by Soapy29 » Logged

Andrew K.

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26481
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

And posted correctly: (comments are a bit dodgy though)
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);
 }
}
« Last Edit: December 26, 2010, 05:21:07 pm by AWOL » Logged

"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.

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 545
Posts: 27352
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Minnesota!
Offline Offline
Sr. Member
****
Karma: 0
Posts: 388
My nickname on the forum used to be Soapy29.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, I have them setup like you said. I posted my code above, and the led doesn't light. smiley-sad
Logged

Andrew K.

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 545
Posts: 27352
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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]
« Last Edit: December 26, 2010, 05:25:34 pm by CrossRoads » Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Pages: 1 [2] 3 4 5   Go Up
Jump to: