senddata.pde

/*
senddata.pde
Eric Ayars
7/31/11

Used with grabdata.py to show how an Arduino can be used to collect data.

This program waits for a single byte from the serial port, then replies by
sending that number of A/D conversions from pin A0, separated by time
DELAY. Output consists of individual lines containing millis() and raw A/D
conversions.

*/

#define DELAY 100
#define SENSOR A3

int received;           // characters received
char buffer[10];        // input buffer
int N;                  // how many measurements to make
char temp;
boolean done = false;

void setup() {
    Serial.begin(57600);
}

void loop() {

    received = 0;
    buffer[received] = '\0';
    temp = ' ';
    done = false;

    // Check input on serial line.
    while (!done) {
        if (Serial.available()) {   // Something is in the buffer
            N = Serial.read();      // so get the number byte
            done = true;
        }
    }

    // Now we know how many to get, so get them.
    for (byte j=0;j<N;j++) {
        Serial.print(millis(), DEC);
        Serial.print('\t');
        Serial.print(analogRead(SENSOR));
        Serial.print('\n');
        delay(DELAY);
    }
}


Generated by GNU enscript 1.6.4.