| WR Home Topic Home | Chapter: 1 2 3 4 |
| <Previous | Next> |
Chapter 04
Developing a Utility Library for the Propeller PCB
Page 9
Questions
Q14 Will the following code produce the same effect as previous code?
Suppose if the Propeller is rotating at a constant speed of RPM = 1200
It will make 20 number of turns in a second (1200/60 = 20)
and to move one degree it will take 137.888889 micro seconds
Assume that time taken to execute the LOOPING instructions is negligible.
What pattern the following code displays/renders:
float D = 137.888889;
unsigned int onSequence = 0x5555; // 0101 0101 0101 0101 Even LEDs are ON
int main()
{
int i;
while(1)
{
for(i=0; i< 90; i++) // First quadrant
{ switch_LEDs(onSequence, RED);
myDelay(D);
}
for(i=0; i< 90; i++) // Second quadrant
{ switch_LEDs(onSequence, BLUE);
myDelay(D);
}
for(i=0; i< 90; i++) // Third quadrant
{ switch_LEDs(onSequence, GREEN);
myDelay(D);
}
for(i=0; i< 90; i++) // Forth quadrant
{ switch_LEDs(onSequence, WHITE);
myDelay(D);
}
} // while(1)
} // main()
Imagine: What do you see ? Is it same as previous ? Scroll below to check your answer
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Answer: No change pattern remains the same as previous solution
To move one degree it will take 137.888889 micro seconds
To move one degree it will take D amount of time
To move one 90 degree it will take D x 90 amount of time
Since onSequence = 0x5555; // 0101 0101 0101 0101 Even LEDs are ON in RED for first 90° and
for next 90° the same LEDs are ON in BLUE color,
for next 90° the same LEDs are ON in GREEN color,
for next 90° the same LEDs are ON in WHITE color,
| WR Home Topic Home | Chapter: 1 2 3 4 |
| <Previous | Next> |