-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment 3.ino
More file actions
44 lines (38 loc) · 1.36 KB
/
Assignment 3.ino
File metadata and controls
44 lines (38 loc) · 1.36 KB
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
39
40
41
42
43
44
/*
Write a sketch that allows a user to access data in EEPROM using the serial monitor.
Write a sketch that allows a user to access data in EEPROM using the serial monitor.
In the serial monitor the user should be able to type one of two commands: “read” and “write.
"Read" takes one argument, an EEPROM address.
"Write" takes two arguments, an EEPROM address and a value.
For example, if the user types “read 3” then the contents of EEPROM address 3 should be printed to the serial monitor.
If the user types “write 3 10” then the value 10 should be written into address 3 of the EEPROM.
*/
#include <EEPROM.h>
void setup()
{
Serial.begin(9600);
}
int address;
int dataToWrite;
void loop()
{
String buffer = "";
buffer = Serial.readString();
if(buffer.startsWith("read")) {
address = buffer.substring(buffer.indexOf(' ') +1).toInt();
Serial.print("Data from the Address : ");
Serial.print(address);
Serial.println();
Serial.println(EEPROM.read(address));
} else if(buffer.startsWith("write")) {
address = buffer.substring(6,7).toInt();
dataToWrite = buffer.substring(8).toInt();
Serial.print("Written ");
Serial.print(dataToWrite);
Serial.println();
Serial.print("to the Address: ");
Serial.print(address);
Serial.println();
EEPROM.write(address,dataToWrite);
}
}