PropWare
C++ objects and CMake build system for Parallax Propeller
Home
Download
Getting Started
Documentation
Reference
About
Related Links
Namespace List
Class List
File List
Examples
Build System
File List
File Members
propsideworkspace
Learn
Examples
Badge
03 Buttons
04 Touch Pad State Machine.c
1
/*
2
Touch Pad State Machine.c
3
Advance through various binary states of the state variable. By pressing
4
each button, all 7 binary digits will be 1, allowing the program to exit
5
the loop. This example uses the logical OR operation to copy previous
6
button presses to the history variable. When the history variable reaches
7
0b1111111, all buttons have been pressed and the loop terminates.
8
*/
9
10
#include "simpletools.h"
// Include simpletools library
11
#include "
badgetools.h
"
// Include badgetools library
12
13
int
history = 0, states = 0;
// State machine variables
14
15
void
main
()
// Main function
16
{
17
badge_setup
();
// Call badge setup
18
// User prompts
19
print(
"Touch pads to control blue lights!\n"
);
20
print(
"To exit pad mode, touch all 7 pads\n\n"
);
21
clear
();
// Heading
22
oledprint
(
"TOUCHPAD"
);
23
pause(500);
// Delay
24
text_size
(
SMALL
);
// Set text size small
25
cursor
(0, 5);
// Position cursor
26
27
// Another user prompt
28
oledprint
(
"Touch all 7 pads (to finish)"
);
29
30
while
(1)
// State machine loop
31
{
32
states =
buttons
();
// Get button states
33
history |= states;
// OR 1s to history variable
34
leds
(history);
35
// Light LEDs with history
36
if
(history == 0b1111111)
break
;
37
// Break from loop if all buttons
38
cursor
(0, 7);
// Position cursor
39
oledprint
(
"complete=%07b"
, history);
// Display history in binary
40
}
41
42
text_size
(
LARGE
);
// Display all done
43
cursor
(0, 0);
44
oledprint
(
"PADS Done! "
);
45
pause(800);
46
leds
(0b000000);
// Lights off
47
}
48
49
50
buttons
int buttons(void)
Gets the states of all seven touch buttons, and returns them in a value with 1s and 0s that correspon...
Definition:
jm_touchpads.c:90
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
clear
int clear(void)
Clear the display.
Definition:
oled_clear.c:7
LARGE
#define LARGE
For setting oLED character size to 32x16 pixels. Example: text_size(LARGE).
Definition:
badgetools.h:192
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
main
int main(void)
Definition:
GraphicsTest.c:20
leds
void leds(int bits)
Sets the on/off states of the 6 blue LEDs with a number that contains six binary 1/0 digits...
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.
cursor
void cursor(int col, int row)
Position the cursor to a certain column and row for printing text on the oLED display. Column can be 0 to 7 and row can be 0 or 1 in default LARGE text mode. In SMALL text mode, column can be 0 to 31, and row can be 0 to 7.
Definition:
oled_cursor.c:7
Generated on Sat Aug 27 2016 00:58:03 for PropWare by
1.8.12