aliyesami
Full Member level 6
- Joined
- Jan 7, 2010
- Messages
- 369
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,296
- Location
- USA
- Activity points
- 4,190
I saw the following in the arduino-examples section but i am not understanding why the analog input is being divided by 4.
if e.g the input value is 1023 then it will require 2 bytes to store since 1023 is 3FF hex. but if i divide it by 4 then i am not storing the original value rather the divided value .
can someone explain how i can save the input analog values to EEPROM ?
thanks
if e.g the input value is 1023 then it will require 2 bytes to store since 1023 is 3FF hex. but if i divide it by 4 then i am not storing the original value rather the divided value .
can someone explain how i can save the input analog values to EEPROM ?
thanks
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 void loop() { // need to divide by 4 because analog inputs range from // 0 to 1023 and each byte of the EEPROM can only hold a // value from 0 to 255. int val = analogRead(0) / 4; // write the value to the appropriate byte of the EEPROM. // these values will remain there when the board is // turned off. EEPROM.write(addr, val); // advance to the next address. there are 512 bytes in // the EEPROM, so go back to 0 when we hit 512. addr = addr + 1; if (addr == 512) addr = 0; delay(100);
Last edited by a moderator: