PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
Simple-Libraries
Learn
Examples
Robots
ActivityBot360
Test IR Distances.c
1
/*
2
IR Test Distances.c
3
4
Test distance detection with infrared detectors.
5
6
http://learn.parallax.com/activitybot/ir-test-distances
7
*/
8
9
#include "
simpletools.h
"
// Include simpletools
10
#include "
abdrive360.h
"
11
#include "
abvolts.h
"
12
13
int
irLeft, irRight;
// Global variables
14
15
int
main
()
// Main function
16
{
17
while
(1)
// Main loop
18
{
19
irLeft = 0;
// Detect variables to 0
20
irRight = 0;
21
22
// Test if an object is detected with 9 increasing levels of IR LED
23
// brightness. Keep track of the number of times an object is NOT
24
// detected. That's its distance value.
25
26
for
(
int
da = 448; da >= 0; da -= 64)
// Sweep da pins
27
{
28
da_out
(0, da);
// Set IR LED cathode volts
29
da_out
(1, da);
30
freqout
(11, 1, 38000);
// Left IR LED light
31
irLeft +=
input
(10);
// No detect? Add 1 to irLeft
32
freqout
(1, 1, 38000);
// Repeat for right detector
33
irRight +=
input
(2);
34
}
35
36
print
(
"%c irLeft = %d, irRight = %d "
,
// Display detector states
37
HOME
, irLeft, irRight);
38
pause
(100);
// Pause before repeating
39
}
40
}
41
HOME
#define HOME
HOME character (1) sends SimpleIDE Terminal's cursor to top-left "home" position.
Definition:
simpletools.h:233
freqout
void freqout(int pin, int msTime, int frequency)
Use same cog to send square wave of a certain frequency for a certain amount of time....
Definition:
freqout.c:10
pause
void pause(int time)
Delay cog from moving on to the next statement for a certain length of time.
Definition:
libws2812.c:125
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.
da_out
void da_out(int channel, int daVal)
Set D/A output.
Definition:
abvoltsDA.c:30
main
int main(void)
Definition:
GraphicsTest.c:20
input
int input(int pin)
Set an I/O pin to input and return 1 if pin detects a high signal, or 0 if it detects low.
Definition:
input.c:19
abdrive360.h
This library provides a simple set of functions for making the ActivityBot 360 go certain distances a...
abvolts.h
Functions for setting voltages with D/A0, D/A1 outputs and measuring voltages with A/D0....
Generated on Fri May 20 2022 16:48:04 for PropWare by
1.8.17