public
Created

Arduino workshop: adattárolás (2012. november 29.)

  • Download Gist
eeprom_repl.ino
Arduino
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
#include <EEPROM.h>
 
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
Serial.begin(9600);
}
 
// the loop routine runs over and over again forever:
void loop() {
Serial.print("Address: ");
int address = 0;
while (true) {
while (!Serial.available());
byte b = Serial.read();
Serial.write(b);
if (b == '\r') break;
if (b >= '0' && b <= '9') address = address * 10 + b - '0';
}
Serial.print("Value: ");
int value = 0;
boolean typed = false;
while (true) {
while (!Serial.available());
byte b = Serial.read();
Serial.write(b);
if (b == '\r') break;
typed = true;
if (b >= '0' && b <= '9') value = value * 10 + b - '0';
}
if (typed) {
EEPROM.write(address, (value & 0xFF00) >> 8);
EEPROM.write(address + 1, (value & 0xFF));
} else {
Serial.print("Read: ");
Serial.println((EEPROM.read(address) << 8) | EEPROM.read(address + 1), DEC);
}
}
progmem.ino
Arduino
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <avr/pgmspace.h>
 
char konstans[] PROGMEM = " Ez egy olyan szoveg, ami nem a RAM-bol lesz elerheto, hanem Flash-bol\r\n";
int j;
 
void setup() {
Serial.begin(9600);
j = 0;
}
 
void loop() {
Serial.print(j, DEC);
j++;
for (int i = 0; ; i++) {
byte b = pgm_read_byte_near(konstans + i);
if (b == '\0') break;
Serial.write(b);
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.