33 bool isAnswerNo (
char const userInput[]);
35 void error (
const PropWare::ErrorCode err);
51 pwOut.
printf(
"Hello! I'd like to teach you how to use PropWare to read from the terminal!\n");
54 pwOut <<
"First, what's your name?\n>>> ";
55 pwIn.
gets(userInput,
sizeof(userInput));
56 strcpy(name, userInput);
58 pwOut <<
"And how old are you?\n>>> ";
61 pwOut <<
"Is your name " << name <<
" and are you " << age <<
" years old?\n>>> ";
62 pwIn.
input_prompt(
"",
"Please enter either 'yes' or 'no' (y/n)\n>>> ", userInput,
sizeof(userInput),
64 }
while (isAnswerNo(userInput));
70 bool isAnswerNo (
char const userInput[]) {
71 return 0 == strcmp(
"n", userInput) || 0 == strcmp(
"no", userInput);
74 void error (
const PropWare::ErrorCode err) {
78 debugLEDs.write((uint32_t) err);
79 waitcnt(100 * MILLISECOND);
81 waitcnt(100 * MILLISECOND);
The PropWare::SimplePort is the recommended way to use data ports on the Propeller. All pins are consecutive, which allows for some simple shortcuts in reading, writing, and initialization.
const PropWare::Printer pwOut
Most common use of printing in PropWare applications (not thread safe; see PropWare::pwSyncOut for mu...
void printf(const char fmt[], const T first, const Targs...remaining) const
Similar in functionality to the C-standard function printf.
void input_prompt(const char prompt[], const char failureResponse[], char userInput[], const size_t bufferLength, const Comparator< char > &comparator)
Prompt the user for input and store the value only if it is sanitized.
const PropWare::YesNoComparator YES_NO_COMP
Global instance for shared use by PropWare applications.
ErrorCode gets(char string[], int32_t length, const char delimiter=DEFAULT_DELIMITER)