Go Down

Topic: Storing this code to EEPROM (SHARP IR SENSOR) (Read 1 time) previous topic - next topic

Hello everyone,
I'm really new to this microcontroller.
I'm using a sharp IR sensor GP2Y0A21 and I already have the code (credits to the one who made it, totally forgot) but I cant figure out how to put this code on a EEPROMwrite/read sketch.
I'm using it as stage level and i'ts giving me accurate-ish distance but it seems i dont know how to store it to EEPROM.
Can someone please help me how to put this code to an EEPROMwrite/read sketch??


Code: [Select]

int IRpin = 1;                                    // analog pin for reading the IR sensor
void setup() {
  Serial.begin(9600);                             // start the serial port
}
void loop() {
  float volts = analogRead(IRpin)*0.0048828125;   // value from sensor * (5/1024) - if running 3.3.volts then change 5 to 3.3
  float distance = 27*pow(volts, -1.10);          // worked out from graph 27 = theretical distance / (1/Volts)S - luckylarry.co.uk
  Serial.println(distance);                       // print the distance
  delay(1000);                                     // arbitary wait time.
}



Thanks.
Cheers.

PaulS

Quote
Can someone please help me how to put this code to an EEPROMwrite/read sketch??

What do you want to write to EEPROM? Why?

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy