oh blog

Icon

i rant cherish and archive my memories here

pedometer take2

pedometer take2

with tom’s advice, decided to connect one end of a switch to 5V of arduino board and the other end to the input pin(with 10k ohm pull down resistor).

since the circuitry on pedometer was not exactly a switch but a connection between ground to power to give a reading to a display, i kept the circuitry for the sake of keeping the display, then needed to put a seperate wire as an end of switch. (the one that connects to the input pin)
for the arduino code, added a simple counter that counts the steps with pedometer. had to figure out to limit/slow down the reading as it counted multiple times with one click of a switch. Therefore, put ’status’ variables, and also ‘delay’ to put some breaks between the readings.

<arduino code>

—————————-

/* pedometer with simple counter
jane oh
10.30.06
*/

int ledPin = 3; // choose the pin for the LED
int inPin = 2; // choose the input pin (for a pushbutton)
int val = 0; // variable for reading the pin status
int counter = 0;
int currentState = 0;
int preState = 0;
void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inPin, INPUT); // declare pushbutton as input
Serial.begin(9600);

digitalWrite(ledPin, HIGH); //blinkie
delay(200);
digitalWrite(ledPin, LOW);
delay(200);
digitalWrite(ledPin, HIGH);
delay(200);
digitalWrite(ledPin, LOW);
delay(200);

digitalWrite(inPin, LOW);
}

void loop(){
val = digitalRead(inPin); // read input value
if (val == HIGH) { // check if the input is HIGH (button pushed)
digitalWrite(ledPin, HIGH); // turn LED ON
currentState = 1;
}
else {
digitalWrite(ledPin, LOW); // turn LED off
currentState = 0;
}
if (currentState != preState){
if (currentState == 1){
counter = counter + 1;
Serial.print(counter, DEC);;
delay(500);
}
}
preState = currentState;
}
———————————-

Filed under: Networked Objects, pcomp

Leave a Reply

del.icio.us