You are on page 1of 1

int sensorPin = A0; // select the input pin for the potentiometer int ledPin = 13; // select the

pin for the LED int sensorValue = 0; void setup() { Serial.begin(9600); float fact(float n); float pow(float nu,float p); pinMode(ledPin, OUTPUT); } float fact(float n) { float i; float ans=1; for(i=n;i>0;i--) { ans = ans * i; } return ans; } float pow(float nu,float p) { float an=1; for(p=p;p>0;p--) { an=an*nu; } return an; } void loop() { int sensorValue = analogRead(A0); Serial.println(sensorValue, DEC); float deg; float temp; float ans=0; float i; sensorValue = analogRead(sensorPin); sensorValue=sensorValue*(36)*(22/(7*180)); for(float z=0;z<6;z++) { temp=pow(-1,z); temp=temp*pow(sensorValue,2*i+1); temp=temp/fact(2*i+1); ans=ans+temp; } Serial.print("sensor = " ); Serial.print(sensorValue); Serial.print("\t output = "); Serial.println(ans); digitalWrite(13, HIGH); // set the LED on delay(ans); // wait for a second digitalWrite(13, LOW); // set the LED off delay(ans); }

You might also like