Chapter 10: C Structures
ures can be nested:
}myPWMS;
ake programs
truc
You can do four things to a structure:
1.
2.
- Take its address with &
Let’s w to use structures
with th
- Pass components to the functions separately.
- Pass an entire structure to the function.
- Pass a pointer to a structure to the function.
In a moment we’ll see why #3 is best.
y = pulser1.pulseWidth // y now equals 127;
Struct
struct pwms {
struct pwm pulser1;
struct pwm pulser2;
struct pwm pulser2;
int numPulsers = 3;
and to access pulser1 pulseFreq we use:
x = myPWMS.pulser1.pulseFreq;
While it may not seem like it at this time, this kind of syntax can m
easier to write and understand, with the usually warning that C gurus will use
them to impress and thereby confuse you.
Structures and Functions
Copy it
Assign to it as a unit
Access its members
rite some functions to modulate some pulses and see how
em. We could approach this three ways: