PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
Simple-Libraries
Learn
Examples
Badge
05 EEPROM Data Storage
05 Store and Retrieve Info.c
1
/*
2
Store and Retrieve Info.c
3
4
IMPORTANT: Erase EEPROM with 01 Erase Badge EEPROM.side before running
5
this.
6
7
The badgetools library has a feature to store and retrieve non string
8
data like integer and floating point variables. It also works for
9
multiple strings. This example program has a number AND a name.
10
Instead of stored, store and retrieve, use eeprinted, eeprint, and
11
eescan. They utilize format strings, just like print, and scan to
12
convert data to character strings and back again. This example also
13
uses contact_count to find out how many addresses were stored in EEPROM.
14
*/
15
16
#include "
simpletools.h
"
// Include simpletools library
17
#include "
badgetools.h
"
// Include badgetools library
18
19
// badge num name // Numbers and names
20
int
fredNum = 123;
21
char
fredName[] =
"Fred Flintstone"
;
22
23
int
wilmaNum = 456;
24
char
wilmaName[] =
"Wilma Flintstone"
;
25
26
int
num;
27
char
name[32];
28
int
exist, contacts;
29
30
void
main
()
// Main function
31
{
32
badge_setup
();
// Call badge setup
33
text_size
(
SMALL
);
34
oledprint
(
"Use SimpleIDE\nTerminal."
);
35
36
// Check if fred's info is already in EEPROM. If not
37
// eeprint it.
38
exist =
eeprinted
(
"%03d\n%32s\n"
, fredNum, fredName);
39
if
(!exist)
40
eeprint
(
"%03d\n%32s\n"
, fredNum, fredName);
41
42
// Repeat for wilma
43
exist =
eeprinted
(
"%03d\n%32s\n"
, wilmaNum, wilmaName);
44
if
(!exist)
45
eeprint
(
"%03d\n%32s\n"
, wilmaNum, wilmaName);
46
47
// Retrieve and display the data
48
contacts =
contacts_count
();
49
for
(
int
record = 0; record < contacts; record++)
50
{
51
eescan
(record,
"%d%s"
, &num, &name);
52
print
(
"record %d = %d, %s\n"
, record, num, name);
53
}
54
}
eeprinted
int eeprinted(const char *fmt,...)
Can be called before storing a record with eeprint. Example: if(!eeprinted("Hello EEPROM") eeprint("H...
Definition:
peb_eeprinted.c:12
eeprint
int eeprint(const char *fmt,...)
Use to store strings to EEPROM in a manner similar to displaying combinations of strings and variable...
Definition:
peb_eeprint.c:12
contacts_count
int contacts_count()
Find out how many contacts are currently stored in EEPROM. This is useful for setting up a loop to fe...
Definition:
peb_contacts_count.c:11
eescan
int eescan(int recIdx, const char *fmt,...)
Use to retrieve strings to EEPROM in a manner similar to retrieving strings that represent combinatio...
Definition:
peb_eescan.c:12
simpletools.h
This library provides convenient functions for a variety of microcontroller I/O, timing,...
print
int print(const char *format,...) __attribute__((format(printf
Print format "..." args to the default simple terminal device. The output is limited to 256 bytes.
main
int main(void)
Definition:
GraphicsTest.c:20
oledprint
int oledprint(const char *fmt,...)
Use to display strings on the oLED display in a manner similar to displaying combinations of strings ...
Definition:
peb_text.c:4
badge_setup
int badge_setup(void)
Set up all available badge drivers. Call this function at the start of any given program to allow acc...
Definition:
badgealpha.c:29
badgetools.h
This library provides convenient functions for a variety of Parallax eBadge operations.
text_size
void text_size(int size)
Set the text size to either 32x16 pixel (LARGE) or 7x5 (SMALL) characters. Examples: text_size(LARGE)...
Definition:
oled_text_size.c:7
SMALL
#define SMALL
For setting oLED character size to 7x5 pixels. Example: text_size(SMALL).
Definition:
badgetools.h:200
Generated on Fri May 20 2022 16:48:04 for PropWare by
1.8.17