Created
November 10, 2010 18:23
-
-
Save rohanbk/671264 to your computer and use it in GitHub Desktop.
Code that measures pressure from 6-piezoresistive force sensors (3 per foot) to the six analog pins of the Arduino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* FSR sampling class | |
@class ArduinoAnalogFSR | |
@author rohanbk | |
*/ | |
int rtoe, rfirstm,rfourthm,rheel,ltoe, lfirstm,lfourthm,lheel; | |
int debugpin=13; | |
void setup() | |
{ | |
Serial.begin(115200); // sets the serial line to baud rate 115200 | |
pinMode(debugpin,OUTPUT); | |
digitalWrite(debugpin,HIGH); | |
} | |
void loop() | |
{ | |
rtoe = map(analogRead(0), 0, 550, 0, 3000); // read analog input pin 0 | |
rfirstm = map(analogRead(1), 0, 550, 0, 3000); // read analog input pin 1 | |
rheel = map(analogRead(2), 0, 550, 0, 3000); // read analog input pin 3 | |
ltoe = map(analogRead(3), 0, 550, 0, 3000); // read analog input pin 0 | |
lfirstm = map(analogRead(4), 0, 550, 0, 3000); // read analog input pin 1 | |
lheel = map(analogRead(5), 0, 550, 0, 3000); | |
Serial.print("("); | |
Serial.print(rtoe); | |
Serial.print(","); // prints a space between the numbers | |
Serial.print(rfirstm); | |
Serial.print(","); // prints a space between the numbers | |
Serial.print(rheel); | |
Serial.print(","); // prints a space between the numbers | |
Serial.print(ltoe); | |
Serial.print(","); // prints a space between the numbers | |
Serial.print(lfirstm); | |
Serial.print(","); // prints a space between the numbers | |
Serial.print(lheel); | |
Serial.print(")\n"); | |
} | |
int RCtime(int RCpin) { | |
int reading = 0; // start with 0 | |
// set the pin to an output and pull to LOW (ground) | |
pinMode(RCpin, OUTPUT); | |
digitalWrite(RCpin, LOW); | |
// Now set the pin to an input and... | |
pinMode(RCpin, INPUT); | |
while (digitalRead(RCpin) == LOW) { // count how long it takes to rise up to HIGH | |
reading++; // increment to keep track of time | |
if (reading == 3000) { | |
// if we got this far, the resistance is so high | |
// its likely that nothing is connected! | |
break; // leave the loop | |
} | |
} | |
// OK either we maxed out at 30000 or hopefully got a reading, return the count | |
return reading; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment