Skip to content

Instantly share code, notes, and snippets.

@dnet
Created December 5, 2012 21:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dnet/4219595 to your computer and use it in GitHub Desktop.
Save dnet/4219595 to your computer and use it in GitHub Desktop.
Arduino workshop: adattárolás (2012. november 29.)
#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);
}
}
#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);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment