PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
Simple-Libraries
Learn
Examples
Devices
Motor
DC
Two DC Motors 60 Percent.c
1
/*
2
Two DC Motors 60 Percent.c
3
4
Drive a pair of DC motors at 6/10 of full speed.
5
6
http://learn.parallax.com/propeller-c-tutorials
7
*/
8
9
#include "
simpletools.h
"
10
11
int
main
()
12
{
13
// Keep pins low if unused.
14
set_outputs
(5, 2, 0b0000);
15
set_directions
(5, 2, 0b1111);
16
17
// Start PWM process. Frequency = 1 kHz -> pulse period = 1 ms.
18
pwm_start
(1000);
19
20
// Turn motors counterclockwise for 3 s.
21
pwm_set
(3, 0, 600);
22
pwm_set
(4, 1, 600);
23
pause
(3000);
24
25
// Stop for 1 second.
26
pwm_set
(3, 0, 0);
27
pwm_set
(4, 1, 0);
28
pause
(1000);
29
30
// Turn motors counterclockwise for 3 s.
31
pwm_set
(2, 0, 600);
32
pwm_set
(5, 1, 600);
33
pause
(3000);
34
35
// Stop again
36
pwm_set
(2, 0, 0);
37
pwm_set
(5, 1, 0);
38
39
// End the PWM process
40
pwm_stop
();
41
}
42
pwm_stop
void pwm_stop(void)
Shut down PWM process and reclaim cog and I/O pins for other uses.
Definition:
pwm.c:58
set_directions
void set_directions(int endPin, int startPin, unsigned int pattern)
Set directions for a contiguous group of I/O pins.
Definition:
setDirections.c:19
pause
void pause(int time)
Delay cog from moving on to the next statement for a certain length of time.
Definition:
libws2812.c:125
pwm_start
int pwm_start(unsigned int cycleMicroseconds)
Start pulse width modulation (PWM) process in another cog.
Definition:
pwm.c:34
set_outputs
void set_outputs(int endPin, int startPin, unsigned int pattern)
Set output states for a contiguous group of I/O pins.
Definition:
setOutputs.c:20
simpletools.h
This library provides convenient functions for a variety of microcontroller I/O, timing,...
pwm_set
void pwm_set(int pin, int channel, int tHigh)
Set a PWM signal's high time.
Definition:
pwm.c:42
main
int main(void)
Definition:
GraphicsTest.c:20
Generated on Fri May 20 2022 16:48:04 for PropWare by
1.8.17