Arduino eeprom sayı kaydetme



#include <EEPROM.h>
long ss;
long address=0;


void setup() {
    EEPROM.begin(512);
    ss = EEPROMReadlong(address);
    Serial.begin (9600);
    }

void loop() {

   ss++;
   EEPROMWritelong(address,ss);
   delay(100);
   Serial.print("ss  ");
   Serial.println (ss, DEC);
   EEPROM.commit();
  }  


void EEPROMWritelong(int address, long value)
{
 //Decomposition from a long to 4 bytes by using bitshift.
 //One = Most significant -> Four = Least significant byte
 byte four = (value & 0xFF);
 byte three = ((value >> 8) & 0xFF);
 byte two = ((value >> 16) & 0xFF);
 byte one = ((value >> 24) & 0xFF);
 //Write the 4 bytes into the eeprom memory.
 EEPROM.write(address, four);
 EEPROM.write(address + 1, three);
 EEPROM.write(address + 2, two);
 EEPROM.write(address + 3, one);
}
long EEPROMReadlong(long address)
{
 //Read the 4 bytes from the eeprom memory.
 long four = EEPROM.read(address);
 long three = EEPROM.read(address + 1);
 long two = EEPROM.read(address + 2);
 long one = EEPROM.read(address + 3);
 //Return the recomposed long by using bitshift.
 return ((four << 0) & 0xFF) + ((three << 8) & 0xFFFF) + ((two << 16) & 0xFFFFFF) + ((one << 24) & 0xFFFFFFFF);
}

Yorumlar

Unknown dedi ki…
iyi günler hocam arduino dan ethernet shield ile buton saydırma işlemi gerçekleştirmek istiyorum siz 2015 yılında ilgilenmişsiniz aynı proje ile elinizde bilgi döküman varsa paylaşabilirmisiniz
Gökhan DÜZGÜN dedi ki…
Merhaba Ümit bey tel 05324566164 numaram servo motorda açı ayarı gmt Plc işe nasıl sağlanır bir bilgi verirmisin

Bu blogdaki popüler yayınlar

c# Delay fonksiyonu - c# bekletme (not sleep)

C# formun açık olup olmadığını denetlemek