Pages: [1]   Go Down
Author Topic: Noob help with Centipede shield  (Read 578 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 40
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello

Übernoob warning!

I've got a Centipede shield;

http://docs.macetech.com/doku.php/centipede_shield

But damn, I can't seem to figure out how to connect regular tact pushbuttons to it.

Do I need pull down resistors, like the standard arduino pushbutton scetch, or can I use the "internal 100k" and the .pinPullup function?

I.e. do I need to multiply something like this for each button: http://www.arduino.cc/en/Tutorial/Button

Could someone (Mr Macetech maybe...) please explain with a simple scetch how I connect a button and how to read it's state, and maybe add to the documentation.

Thanks
F
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 201
Posts: 8685
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is how you change the basic button example to work with the button on shield pin 98 and the LED on shield pin 99.
Code:
#include <Wire.h>
#include <Centipede.h>
Centipede CS; // create Centipede object

// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 98;     // the number of the pushbutton pin (was 2)
const int ledPin =  99;        // the number of the LED pin (was 13)

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  CS.pinMode(ledPin, OUTPUT);     
  // initialize the pushbutton pin as an input:
  CS.pinMode(buttonPin, INPUT);     
}

void loop(){
  // read the state of the pushbutton value:
  buttonState = CS.digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {     
    // turn LED on:   
    CS.digitalWrite(ledPin, HIGH); 
  }
  else {
    // turn LED off:
    CS.digitalWrite(ledPin, LOW);
  }
}
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

0
Offline Offline
Newbie
*
Karma: 0
Posts: 40
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, great, thanks!

So the schematics, will I need a resistor for each button like in the example?

Just thought if the internal 100k pull up resistor was to use for stuff like buttons to make my life easier...

Cheers!
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 201
Posts: 8685
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Enabling the pull-up resistor on a shield input pin is close to the way you do it on an Arduino pin but you use CS.pinPullup(pin,HIGH) instead of digitalWrite(pin, HIGH).

Code:
void setup() {
  // initialize the LED pin as an output
  CS.pinMode(ledPin, OUTPUT);

  // initialize the pushbutton pin as an input and enable the pull-up:
  CS.pinMode(buttonPin, INPUT);     
  CS.pinPullup(buttonPin, HIGH);
}
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

0
Offline Offline
Newbie
*
Karma: 0
Posts: 40
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Allright, got it working it seems! The following code will light up the on-board led (13) when Centipede pin 10 is connected to ground.

Code:
#include <Wire.h>
#include <Centipede.h>

Centipede CS;
const int buttonPin = 10;
int buttonState = 0;

void setup() {               
  Wire.begin();
  CS.initialize();
  pinMode(13, OUTPUT);
  CS.pinMode(buttonPin, INPUT);
  CS.pinPullup(buttonPin, HIGH); 
}

void loop() {
  buttonState = CS.digitalRead(buttonPin); 
  if (buttonState == LOW) {     
    digitalWrite(13, HIGH); 
  }
  else {
    digitalWrite(13, LOW);
  }
}
Logged

Pages: [1]   Go Up
Jump to: