battle programmers alliance
Would you like to react to this message? Create an account in a few clicks or log in to continue.


battle programming a forum for elite programmers with extreme will power to sharpen their skills
 
HomeGallerySearchRegisterLog in
 

 Arduino Grimoire

Go down 
Go to page : Previous  1, 2
AuthorMessage
Moti Barski
super
super
Moti Barski

Posts : 547
Join date : 2011-08-02

Arduino Grimoire - Page 2 Empty
PostSubject: Re: Arduino Grimoire   Arduino Grimoire - Page 2 EmptySun Apr 18, 2021 9:51 pm

SOLDERING




_________________
MB over and out emp it up
Back to top Go down
Moti Barski
super
super
Moti Barski

Posts : 547
Join date : 2011-08-02

Arduino Grimoire - Page 2 Empty
PostSubject: Re: Arduino Grimoire   Arduino Grimoire - Page 2 EmptySun Apr 18, 2021 9:56 pm

the ATMega 328 at the heart of the arduino uno has 1k of EEPROM, designed to remember it's contents
for many year, despite its name it is read and writtable.

read save 1 char :

Code:
#include <EEPROM.h>
int addr = 0;
char ch;
void setup() {
  Serial.begin(9600);
  ch = EEPROM.read(addr);
 }
void loop() {
  if (Serial.available() > 0)  {  ch = Serial.read();  EEPROM.write(0, ch);  Serial.println(ch);  }
  Serial.println(ch);  delay(1000);
}

write int :

int x = 1234; EEPROM.write(0, highByte(x)); EEPROM.write(1, lowByte(x));

0, 1 being the EEPROM memory addresses, which much be in the 0 - 1023 range
overall you can save about 100 k times

read int
byte high = EEPROM.read(0); byte low = EEPROM.read(1); int x = (high << Cool + low;

using the built in EEPROM library to save or read data :

Code:
#include <avr/eeprom.h>

void setup() {
 Serial.begin(9600);
 int i1 = 123;
 eeprom_write_block(&i1, 0, 2);
 int i2 = 0;
 eeprom_read_block(&i2, 0, 2);
 Serial.println(i2); }
void loop() { }

read save float :

Code:
#include <avr/eeprom.h>
void setup() {
Serial.begin(9600);
 float f1 = 1.23;
 eeprom_write_block(&f1, 0, 4);
 float f2 = 0;
 eeprom_read_block(&f2, 0, 4);
 Serial.println(f2); }
void loop() { }

read write string

Code:
const int maxPasswordSize = 20;
char password[maxPasswordSize];
void setup() {
 eeprom_read_block(&password, 0, maxPasswordSize);
 Serial.begin(9600);
 }
void loop() {
 Serial.print("Your password is:");
 Serial.println(password);
 Serial.println("Enter a NEW password");
 while (!Serial.available()) {}; int n = Serial.readBytesUntil('\n', password, maxPasswordSize);
 password[n] = '\0'; eeprom_write_block(password, 0, maxPasswordSize);
 Serial.print("Saved Password: ");
 Seria.println(password);

clear the arduino EEPROM

Code:
#include <EEPROM.h>

void setup() {
 Serial.begin(9600);
 Serial.println("Clearing EEPROM")a;
 for (int i = 0; i < 1024; i++) { EEPROM.write(i, 0); }
 Serial.println("EEPROM Cleared");
}
void loop() { }

_________________
MB over and out emp it up
Back to top Go down
Moti Barski
super
super
Moti Barski

Posts : 547
Join date : 2011-08-02

Arduino Grimoire - Page 2 Empty
PostSubject: Re: Arduino Grimoire   Arduino Grimoire - Page 2 EmptyTue Apr 20, 2021 9:10 am


_________________
MB over and out emp it up
Back to top Go down
 
Arduino Grimoire
Back to top 
Page 2 of 2Go to page : Previous  1, 2

Permissions in this forum:You cannot reply to topics in this forum
battle programmers alliance :: battle programming alliance :: battle programming-
Jump to: