Save values ​​in buffer and processing


I have a small circuit with temperature acquisition and value processing, read the comments in the code.

// Using millis()... no delays!

// Generally, you should use "unsigned long" for variables that hold time

// The value will quickly become too large for an int to store

unsigned long previousMillis = 0; // will store last time LED was updated

// constants won't change:

const long interval = 500; // interval at which to 'blink' (milliseconds)

void loop {

int buffer [16];

int val;

int counter = 0;

float temperature;

unsigned long currentMillis = millis();

`if (currentMillis - previousMillis >= interval) { // read analog value every 500ms` `val = analogRead(pin); // LM35 pin` `buffer[counter] = val; // store the analog value in the buffer` `//Calculate Temperature from analog value` `//Note that we use mV for Vref` 

//Vin = ADCresult*Vref/(2^10)

//Temp(^C) = Vin/(10) = ADCresult*Vref/(1024*10)

temp = val*1100/(1024*10);

`counter ++;` `previousMillis = currentMillis;` `}` 

if (buffer[16] != NULL){

`// when the buffer fills up, pass all the values to the Serial Monitor and stop the acquisition of temperature` `for (int i = 0; i < 17; i++) {` `Serial.print("Position: "); // buffer[0], buffer[1],...` 

. Serial.print(i);

 `Serial.print(Value: ); // analog value stored in the buffer` `Serial.print(buffer[i]);` `Serial.print("Temeperature: ");` `Serial.println(temp);` `previousMillis = currentMillis; // reset the timer` `}` `// resumes temperature acquisition` 

I'm not even sure how to start, or put it into practice, from google I rather wrote all this. Do you think it will work? What else do I miss?

This is the first step, I will have to do something more useful with those temperature values.

Touch here for the full post on the Arduino Apprentices tumblr

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s