Go Down

Topic: How to store a series of inputs as an array and use it in Processing (Read 1 time) previous topic - next topic

shreeraam

Jun 06, 2012, 10:45 am Last Edit: Jun 07, 2012, 02:08 am by Nick Gammon Reason: 1
HI guys,
i m new to the field of electronics and programming,i have this problem where i hv to store the analoginput as an array to use it in processing..the thing is i dunno how to store the constantly changing data from the sensor as an array and how to use the array in processing.plz help.



Moderator edit: Thread title made not all caps. (Nick Gammon)

AWOL

Have you worked through any of the examples in either the Arduino or Processing IDEs?

When is your assignment due?

shreeraam

Its not an assignment i m building a radar and i need the array to display the distance..

AWOL

OK, but which of the examples have you worked through, and what does your code look like?

(PS, please don't shout)

shreeraam

Code: [Select]
#include 
int i[18]
int pingPin = 13;
int inPin = 12;

void setup() {

}

void loop()
{
  // establish variables for duration of the ping,
  // and the distance result in inches and centimeters:
  long duration, inches, cm;

  // The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(pingPin, LOW);

  // The same pin is used to read the signal from the PING))): a HIGH
  // pulse whose duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  pinMode(inPin, INPUT);
  duration = pulseIn(inPin, HIGH);

  // convert the time into a distance
  inches = microsecondsToInches(duration);
  cm = microsecondsToCentimeters(duration);
  lcd.print(cm);
  lcd.print("cm");

  delay(100);
}

long microsecondsToCentimeters(long microseconds)
{
  // The speed of sound is 340 m/s or 29 microseconds per centimeter.
  // The ping travels out and back, so to find the distance of the
  // object we take half of the distance travelled.
  return microseconds / 29 / 2;
}


well this is the code i found i wanna know if i can use the following to get an array

Code: [Select]

for(int x=0;x<18;x++)
{
cm=i[x]
}


will this give me an array of data?

AWOL

Code: [Select]
#include 
int i[18]

"include" what, exactly?
"i" isn't the best name for an array of soundings, and the declaration needs a semicolon to terminate the line.

Code: [Select]
for(int x=0;x<18;x++)
{
cm=i[x]
}

Again, needs more semicolon, and this will simply write the same value into all 18 elements of your array.

Have you worked through any examples?

shreeraam

Thnx... Apart from the semicolons can you gv me solution to the problem..u hv a valid point that all my arrays will hv the same data what should i do to get the varying data and store em in the different arrays...i hv tried tutorials but doesnt seem to work so plz help.....

AWOL

Must be a slow morning - I didn't notice your assignment was the wrong way round!
Code: [Select]
for (int i = 0; i < N_READINGS; ++i) {
  sounding [i] = pingRange ();
}


AWOL

You'll probably want this:
Code: [Select]
unsigned long pinRange (byte pingPin)
{
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(pingPin, LOW);

  pinMode(inPin, INPUT);
  return pulseIn(inPin, HIGH);


Go Up