Go Down

Topic: Please explain the code (Read 834 times) previous topic - next topic

May 09, 2012, 07:49 am Last Edit: May 09, 2012, 10:05 am by Coding Badly Reason: 1
Can someone explain this to me.
I am really noob in programming but I want to learn, btw I can understand some of the codes but a bit confuse.
This is for our project pulse oximeter. Using a
Nellcor MAX-A http://www.medical-supplies-equipment-company.com/product/ppf/id/13446/new_prod_full.asp
where the output of the pulse oximeter is inputed in the arduino decimila.

Another question: How can I change its Aref to higher voltage? just to light a LED.
Thanks in advance!


Here's the code:
Code: [Select]
int ledPin = 13;
int sensorPin = 0;

doouble alpha =0.75;
int period = 20;
double change = 0.0;

void setup()
{
pinMode(ledPin,OUTPUT);
Serial.begin(115200);
}

void loop()
{
static double oldValue = 0;
static double oldChange = 0;
int rawValue = analogRead(sensorPin);
double value = alpha * oldValue + (1-alpha)*rawValue;

digitalWrite(ledPin,(change<0.0 && oldChange >0.0));

Serial.println(value);

oldValue= value;
oldChange =change;
delay(period);
}



Moderator edit: [code] [/code] tags added.
Arduino Projects Problem!?
Visit my blog! Free download(PDF File) for 170+ projects and I will be adding!
Here: http://badassarduinoprojects

dxw00d

What do mean by
Quote
How can I change its Aref to higher voltage?


Change the Aref of what?

Koop

#2
May 09, 2012, 08:54 am Last Edit: May 09, 2012, 08:56 am by Koop Reason: 1
Its really quite simple to change the AREF of the Arduino (I assume that that's what you're talking about, if not sorry  :~).  Put whatever voltage you want the AREF to be into the AREF pin of the Arduino.

Koop

AWOL

Quote
Put whatever voltage you want the AREF to be into the AREF pin of the Arduino.

...as the long as it is less than or equal to the supply voltage.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

marco_c

#4
May 09, 2012, 09:37 am Last Edit: May 09, 2012, 11:40 am by marco_c Reason: 1
Code: [Select]
// declare a couple of floating point variables (double float).
// Static variables are not destoyed between calls to loop() and will be remembered for the next time
static double oldValue = 0;
static double oldChange = 0;

// declare an integer variable and initialise it witrh a value read from the sensor (0 to 1023)
int rawValue = analogRead(sensorPin);

// declare a floating point variable and do some sort of conversion from the raw sensor input to a value
// this calculaton means something to you if you know what sensor you are using
double value = alpha * oldValue + (1-alpha)*rawValue;

// Write a 0 or 1 to the digital output ledPin. The value written is a boolean that works out to false(0) if change and OldChange don't meet the conditions, and true (>0) if they do. This can be confusing until you get used to it.
digitalWrite(ledPin,(change<0.0 && oldChange >0.0));

Serial.println(value);

// save the values in variable that remain (persist) for the next time that loop is called
oldValue= value;
oldChange =change;

// wait a while and then do it all over again
delay(period);

Moderator edit : Code tags added.

I think there is a mistake in this code as change is never set in the code but is assigned to oldChange. After the first time through both change and oldChange will be 0.0.

Hope this helps.
Arduino libraries http://arduinocode.codeplex.com
Parola for Arduino http://parola.codeplex.com

MarkT


Quote
Put whatever voltage you want the AREF to be into the AREF pin of the Arduino.

...as the long as it is less than or equal to the supply voltage.


So long as it is between 1.0V and the supply voltage, is a low-impedance source and provided you call analogReference(EXTERNAL) in your setup() before any calls to analogRead().
[ I won't respond to messages, use the forum please ]

ea123

Hi,
the following line is a low pass digital filter: it smooths the analog input value by cutting the
high frequencies, "alpha" is the time constant of the filter.

Quote

Code: [Select]

// declare a floating point variable and do some sort of conversrion from the raw sensor input to a value
// this calculaton means something to you if you know what sensor you are using
double value = alpha * oldValue + (1-alpha)*rawValue;


Go Up