WR Home Topic Home | Chapter: 1 2 3 4 |
<Previous | Next> |
Chapter 04
Developing a Utility Library for the Propeller PCB
Page 10
Questions
Q15 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 onSequenceEVEN = 0x5555; // 0101 0101 0101 0101 EVEN LEDs are ON unsigned int onSequenceODD = 0xAAAA; // 1010 1010 1010 1010 ODD LEDs are ON int main() { int i; while(1) { for(i=0; i< 90; i++) // First quadrant { switch_LEDs(onSequenceEVEN, RED); myDelay(D/2); switch_LEDs(onSequenceODD, GREEN); myDelay(D/2); } for(i=0; i< 90; i++) // Second quadrant { switch_LEDs(onSequenceEVEN, BLUE); myDelay(D/2); switch_LEDs(onSequenceODD, WHITE); myDelay(D/2); } for(i=0; i< 90; i++) // Third quadrant { switch_LEDs(onSequenceEVEN, GREEN); myDelay(D/2); switch_LEDs(onSequenceODD, RED); myDelay(D/2); } for(i=0; i< 90; i++) // Forth quadrant { switch_LEDs(onSequenceEVEN, WHITE); myDelay(D/2); switch_LEDs(onSequenceODD, BLUE); myDelay(D/2); } } // while(1) } // main()
Imagine: DISCUSS: What do you see ? Scroll below to check your answer
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
HINT:
When Even numbered LEDs are in First quadrant, then ODD numbered LEDs are in opposite (Third) quadrant.
When Even numbered LEDs are in Second quadrant, then ODD numbered LEDs are in opposite (Forth) quadrant.
When Even numbered LEDs are in Third quadrant, then ODD numbered LEDs are in opposite (First) quadrant.
When Even numbered LEDs are in Forth quadrant, then ODD numbered LEDs are in opposite (Second) quadrant.
Explanation followed by Answer:
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
The Tip of the propeller PCB is denoted by a RED dot (circle)
for(i=0; i< 90; i++) // First quadrant { switch_LEDs(onSequenceEVEN, RED); myDelay(D/2); switch_LEDs(onSequenceODD, GREEN); myDelay(D/2); } For ½° its RED in First quadrant For another ½° its GREEN in Third quadrant The above repeats 90 times and due to POV, the pattern on right emerges. |
|
for(i=0; i< 90; i++) // Second quadrant { switch_LEDs(onSequenceEVEN, BLUE); myDelay(D/2); switch_LEDs(onSequenceODD, WHITE); myDelay(D/2); } For ½° its Blue in Second quadrant For another ½° its White in Forth quadrant The above repeats 90 times and due to POV, the pattern on right emerges. |
|
for(i=0; i< 90; i++) // Third quadrant { switch_LEDs(onSequenceEVEN, GREEN); myDelay(D/2); switch_LEDs(onSequenceODD, RED); myDelay(D/2); } For ½° its GREEN in Third quadrant For another ½° its RED in First quadrant The above repeats 90 times and due to POV, the pattern on right emerges. |
|
for(i=0; i< 90; i++) // Forth quadrant { switch_LEDs(onSequenceEVEN, WHITE); myDelay(D/2); switch_LEDs(onSequenceODD, BLUE); myDelay(D/2); } For ½° its WHITE in Forth quadrant For another ½° its BLUE in First quadrant The above repeats 90 times and due to POV, the pattern on right emerges. |
And finally due to persistence of vision:
WR Home Topic Home | Chapter: 1 2 3 4 |
<Previous | Next> |