WR Home      Topic Home      Chapter:  1  2  3  4  5  6  7  8 
<Previous Next>

Chapter 08

Developing an algorithm to generate visual patterns

Page 2

Experiment 2

A similar example
STEP 1: Represent the PATTERN in numeric form
Suppose the following pattern is to be displayed on the rotating propeller:

pie_slices_06_2color

The animation is shown below (The RED dot denotes the propeller-head):

Animation


The circular area of the rotating propeller will now be divided in 6-pie slices
First Pie Slice Second Pie Slice Third Pie Slice
First Pie Slice Second Pie Slice Third Pie Slice
4th Pie Slice 5th Pie Slice 6th Pie Slice
Fourth Pie Slice Fifth Pie Slice Sixth Pie Slice

 4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  ray_no= 0
 5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  ray_no= 1
 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  ray_no= 2
 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  ray_no= 3
 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  ray_no= 4
 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  ray_no= 5
 

STEP 2: SWAP: ODD sectors of OPPOSITE rays


 SWAP: ODD sectors of opposite rays

 0  4  0  4  0  4  0  4  0  4  0  4  0  4  0  ray_no= 0
 0  5  0  5  0  5  0  5  0  5  0  5  0  5  0  ray_no= 1
 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  ray_no= 2
 4  0  4  0  4  0  4  0  4  0  4  0  4  0  4  ray_no= 3
 5  0  5  0  5  0  5  0  5  0  5  0  5  0  5  ray_no= 4
 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  ray_no= 5


STEP 3: Convert in 16-bit format



  ray_no= 0 
 .  4  .  4  .  4  .  4  .  4  .  4  .  4  .  BLUE    ( 4)

 ray_no= 1 
 .  5  .  5  .  5  .  5  .  5  .  5  .  5  .  MAGENTA ( 5)

 ray_no= 2 
 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  BLACK   ( 0)
 
 ray_no= 3 
 4  .  4  .  4  .  4  .  4  .  4  .  4  .  4  BLUE    ( 4)

 ray_no= 4 
 5  .  5  .  5  .  5  .  5  .  5  .  5  .  5  MAGENTA ( 5)

 ray_no= 5 
 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  BLACK   ( 0)



STEP 4: Convert to PORT OUTPUT format


 ray_no= 0 
 .  4  .  4  .  4  .  4  .  4  .  4  .  4  .  BLUE    ( 4)

 sectors : 0x2AAA 0010 1010 1010 1010  BLUE    ( 4)

 PORTC=0X22 PORTB=0X2a PORTD=0Xa2 0010 0010  | 0010 1010  | 1010 0010 

 ray_no= 1 
 .  5  .  5  .  5  .  5  .  5  .  5  .  5  .  MAGENTA ( 5)

 sectors : 0x2AAA 0010 1010 1010 1010  MAGENTA ( 5)


 PORTC=0X2a PORTB=0X2a PORTD=0Xa2 0010 1010  | 0010 1010  | 1010 0010 

 ray_no= 2 


 All LEDs OFF for ray : 0x0000 0000 0000 0000 0000  BLACK   ( 0)

 PORTC=0X00 PORTB=0X00 PORTD=0X00 0000 0000  | 0000 0000  | 0000 0000 

 ray_no= 3 
 4  .  4  .  4  .  4  .  4  .  4  .  4  .  4  BLUE    ( 4)

 sectors : 0x5555 0101 0101 0101 0101  BLUE    ( 4)

 PORTC=0X25 PORTB=0X15 PORTD=0X51 0010 0101  | 0001 0101  | 0101 0001 

 ray_no= 4 
 5  .  5  .  5  .  5  .  5  .  5  .  5  .  5  MAGENTA ( 5)

 sectors : 0x5555 0101 0101 0101 0101  MAGENTA ( 5)


 PORTC=0X2d PORTB=0X15 PORTD=0X51 0010 1101  | 0001 0101  | 0101 0001 

 ray_no= 5 


 All LEDs OFF for ray : 0x0000 0000 0000 0000 0000  BLACK   ( 0)

 PORTC=0X00 PORTB=0X00 PORTD=0X00 0000 0000  | 0000 0000  | 0000 0000 



STEP 5: Consider writing a program !











NOTE: Port pins should not be addressed directly to send outputs (For example PORTD=0xa2) because other input devices (such as remote sensor TSOP and Index Sensor ) are connected to the port. The above code is just a diluted version to help and understand the development of the algorithm.


WR Home      Topic Home      Chapter:  1  2  3  4  5  6  7  8 
<Previous Next>