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
01 Display
14 Multicore Dots.c
1
/*
2
Multicore Dots.c
3
Functions running in separate cogs independently update the positions
4
of two different dots.
5
*/
6
7
#include "simpletools.h"
// Include simpletools library
8
#include "
badgetools.h
"
// Include badgetools library
9
10
void
dot_A();
// Forward declare functions
11
void
dot_B();
12
13
void
main
()
// Main function
14
{
15
badge_setup
();
// Call badge setup
16
cog_run(dot_A, 128);
// dot_A to new cog
17
cog_run(dot_B, 128);
// dot_B to new cog
18
}
19
20
void
dot_A()
// dot_A function
21
{
22
srand(123);
// Random number seed
23
int
x, y, vx, vy, ox, oy, dt, t;
// Plotting & time
24
x = 5 + rand() % 100;
// Random inital x
25
ox = x;
// Initialize old x
26
y = 3 + rand() % 50;
// Repeat for y
27
oy = y;
28
vx = 1 + rand() % 3;
// Distance increments
29
vy = 1 + rand() % 3;
30
dt = 15 + rand() %10;
// Refresh time increment
31
while
(1)
// Cog loop
32
{
33
point
( x, y, 1);
// Plot new point
34
pause(dt);
// Wait refresh increment
35
36
ox = x;
// Figure out old points
37
oy = y;
38
point
(ox, oy, 0);
// Blot out old points
39
40
x = x + vx;
// Set up new points
41
y = y + vy;
42
43
if
(x >= 125 || x <= 2) {
// Limit point positions
44
vx = -1 * vx;
45
}
46
if
(y >= 62 || y <= 2) {
47
vy = -1 * vy;
48
}
49
}
50
}
51
52
53
// Same function, different seed, and different cog
54
void
dot_B()
55
{
56
srand(456);
57
int
x, y, vx, vy, ox, oy, dt, t;
58
x = 5 + rand() % 100;
59
ox = x;
60
y = 3 + rand() % 50;
61
oy = y;
62
vx = 1 + rand() % 3;
63
vy = 1 + rand() % 3;
64
dt = 15 + rand() %10;
65
while
(1)
66
{
67
point
( x, y, 1);
68
pause(dt);
69
70
ox = x;
71
oy = y;
72
point
(ox, oy, 0);
73
74
x = x + vx;
75
y = y + vy;
76
77
if
(x >= 125 || x <= 2) {
78
vx = -1 * vx;
79
}
80
if
(y >= 62 || y <= 2) {
81
vy = -1 * vy;
82
}
83
}
84
}
85
point
void point(int x, int y, int color)
Plot a point on the oLED screen.
main
int main(void)
Definition:
GraphicsTest.c:20
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.
Generated on Sat Aug 27 2016 00:58:03 for PropWare by
1.8.12