Stockage sur EEPROM


bonjour,
tout d'abord je ne m'y connais pas vraiment en stockage sur l'eeprom de l'arduino mega, donc j'aurai besoin d'un peu d'aide ..
mon matériel:
clavier matriciel 16 touches
lcd 4*20
et une arduino mega 2560

j'ai créé un programme avec un menu qui grâce au clavier, je peux écrire une heure (format hh et les minutes format mm) ou je veux que ma porte s'ouvre et se referme.
le menu seul fonctionne,mais  j'aimerais pouvoir enregistrer ses données (heures minutes )dans l'eeprom , afin d'éviter de retaper les heures tous les jours...

j'ai essayé de comprendre ce tuto arduino et de l'utiliser avec les données de mon menu mais en vain ..
#include <eeprom.h>
#include <arduino.h>  // type definitions

template <class t> int eeprom_writeanything(int ee, const t& value)
{
    const byte* p = (const byte*)(const void*)&value;
    unsigned int i;
    (i = 0; < sizeof(value); i++)
     eeprom.write(ee++, *p++);
    return i;
}

template <class t> int eeprom_readanything(int ee, t& value)
{
    byte* p = (byte*)(void*)&value;
    unsigned int i;
    (i = 0; < sizeof(value); i++)
     *p++ = eeprom.read(ee++);
    return i;
}


si je n'ai pas été assez claire , dites le moi , merci :)

monkeydmina


voici une petite fonction avec exemple que j'ai utilisé récemment:

code: [select]
#include <eeprom.h>
// saving settings in eeprom
/*
!warning!
writing takes 3.3ms.
maximum life of eeprom 100000 writings/readings.
careful not use much, not replacable!
*/
#define adr_eprom_test 0                 // test 1st time init of arduino (first power on)
#define adr_eprom_alarm_min1 2           // default alarm min 3.60v
#define adr_eprom_nb_cells_batt1 4       // automaticaly detected , calculated
#define adr_eprom_alarm_on_off_batt1 6   // 0=false/disable 1=true/enable
#define adr_eprom_alarm_interval 8       // audio warning alarm interval



init:
code: [select]

// test 1st time init of arduino (first power on)
  int test = read_eprom(adr_eprom_test);
  if (test != 123)
  {
    write_eprom(adr_eprom_test,123);
    write_eprom(adr_eprom_alarm_min1,alarm_min1);
    write_eprom(adr_eprom_alarm_on_off_batt1,alarm_on_off_batt1);
  }


les fonctions ecture/écriture:
code: [select]
uint16_t gmessage::read_eprom(int address){
  return  (uint16_t) eeprom.read(address) * 256 + eeprom.read(address+1) ;
}

void gmessage::write_eprom(int address,uint16_t val){
  eeprom.write(address, val  / 256);
  eeprom.write(address+1,val % 256 );
}


a adapter pour tes besoins ;)


Arduino Forum > International > Français (Moderators: jfs, Snootlab) > Stockage sur EEPROM


arduino

Comments

Popular posts from this blog

VIDIOC_S_FMT error 16, Device or resource busy - Raspberry Pi Forums

using a laptop skeleton to build a pi laptop - Raspberry Pi Forums

Forum for Joomla? - Joomla! Forum - community, help and support