Go Down

Topic: Noob help with Centipede shield (Read 625 times) previous topic - next topic

Fredrik

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

johnwasser

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: [Select]

#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);
  }
}
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Fredrik

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!

johnwasser

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: [Select]

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);
}
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Fredrik

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: [Select]

#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);
  }
}

Go Up
 

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it's been approved by a moderator.
Name:
Email:

shortcuts: alt+s submit/post or alt+p preview