Hardware Reference
In-Depth Information
31 // Get the user's age
32 age = EEPROM.read(EEPROM_AGEPOS);
33
34 // Print out what we know of the user
35 Serial.println("I know you!");
36 Serial.print("Your name is ");
37 Serial.print(userName);
38 Serial.print(" and you are ");
39 Serial.print(age);
40 Serial.println(" years old.");
41
42 // Write zero back to the control number
43 EEPROM.write(EEPROM_DATAPOS, 0);
44 }
45 else
46 {
47 // Welcome the user
48 Serial.println("Hello! What is your name?");
49
50 // Wait until serial data is available
51 while(!Serial.available())
52 // Wait for all the data to arrive
53 delay(200);
54
55 // Read in serial data, one byte at a time
56 Serial.readBytes(userName, Serial.available());
57
58 // Say hello to the user
59 Serial.print("Hello, ");
60 Serial.print(userName);
61 Serial.print(". My name is ");
62 Serial.print(myName);
63 Serial.println("\n");
64
65 // Save the user's name to EEPROM
66 for (i = 0; i < sizeof(userName); i++)
67 {
68 EEPROM.write(EEPROM_NAMEPOS + i, userName[i]);
69 }
70
71 // Ask for user's age
72 Serial.print("How old are you, ");
73 Serial.print(userName);
74 Serial.println("?");
75
76 // Wait until serial data is available
77 while(!Serial.available())
78 // Wait for all the data to arrive
79 delay(200);
80 age = Serial.parseInt();
Continues
Search WWH ::




Custom Search