::::::::::::::::   Anne Hong    
::::::::::::::::   NYU | Tisch School | ITP    
::::::::::::::::   MPS Candidate-2007  
::::::::::::::::   info@annehong.com  
::::::::::::::::   Toy Design Workshop  
      User Interaction and Programming
       


Research

Each bracelet has 2 regular switches, 1 reed switch and 8 LED lights. I didn't want to define a specific language, since this was a toy. I also want the users to be imaginative with creating their own meaning with light as the visual language. I researched the morse Code Alphabet, and visually the patterns look like musical notations, and rhythm. Telepathy is defined as the direct transference of thought from one person to another without using the usual sensory channels of communication (Crystalinks web site). I also researched Twin Telepathy and twins learning patterns, and found that twins are more perceptive with their twin, and are exceptionally keen to reading their personalities. In researching Extra Sensory Perception, and I came up with my own metaphor for telepathy, which is like tuning frequency or radio station (Mental Radio (1930). Upton Sinclair and foreword by Albert Einstein).

Morse Code




Sasu Bracelets have 4 modes:

I designed the interface similar to that of a digital watch, where one mode is always on. The first mode is always on and represents the energy level your "twin" feeding you. This requires physical interaction, and a gesture that unites the bracelets by powering them through a reed switch and magnet present on each bracelet. Over time, the power bars/levels fade so that you have to meet again to power up.

The second mode represents an expression of an emotion, consisting of animation and inanimate patterns. You can send your friend a message to convey your mood. They can send this to a friend via RF link, and over time this too will fade. There are 4 variables: fast animation to convey a sense of urgency, slow animation which can mean constancy or stability, dimness of the lights (visually would look like a blur) could mean warmth, and full brightness could mean strength or intensity. I envision this mode to look like vital stats of a heart rate monitor.

The third mode would be a gift exchange of "jewels." You can send a gift of beauty to your friend. There will be set patterns that you can scroll through, which also leaves the possibility of developing an application that will motivate young girls to write a little code to send a customized pattern.

The fourth mode will access Ochie's Cube. Ochie guards these girls belongings. A light is always illuminated when the box is activated, i.e. pink or whatever color they always assign "Ochie" to be. When they deactivate to gain access to the box, the light will fade to the last person who accessed the box ("blue" or "amber"), allowing them both to know who was the last person to touch it. When the box is accessed without the bracelets, it will notify both bracelets, and the lights of the box will pulse. Code for both the bracelets and cube are documented below.



-

Written by James N. Sears

Code For Sasu Twin Bracelets

'Takes in 2 lines

OSCCON = %01111110

OSCTUNE = %10000000

DEFINE OSC 8 

'include modedefs.bas for shiftin and out modes

enable interrupt

INCLUDE "modedefs.bas"

'***************************************************************************

'*VARIABLES

'***************************************************************************

    'general purpose variables

        temp var byte

        temp2 var byte

        newCounter var byte

        i VAR BYTE

        counter VAR BYTE   

    'pin definitions for comm w/ Laipec TRW-24G

        RF_CE   VAR    PORTA.0 'yellow

        RF_CS   VAR    PORTB.4 'dark green

        RF_DR   VAR    PORTB.3 'blue

    'channel 1 PIN definitions

        RF_CLK1 VAR    PORTB.2 'black

        RF_DATA_In VAR PORTB.1 'light blue

        RF_DATA_Out VAR PORTB.1

    'I/O + Control PINS

        switch1  VAR portc.1

        switch2 var portc.0

        switchReed var portb.0

       

        LED0 VAR PORTC.2

        LED1 var PORTC.3

        LED2 VAR PORTD.0

        LED3 VAR PORTD.1

        LED4 VAR PORTD.2

        LED5 VAR PORTD.3

        LED6 VAR PORTC.4

        LED7 VAR PORTC.5 

       

        ' THIS IS THE ADDRESS FOR THE MiRF v01

        WhichAddress1 VAR BYTE    'Channel 1

        WhichAddress2 VAR BYTE    'Channel 2   

 

    'constants for RF configuration modes

        CONRFRX VAR BYTE

        CONRFTX VAR BYTE   

    'indicates state of current RF configuration - TX is 0, RX is 1

        RFCurrentState VAR BIT   

    'hold data for RF message

        RFDataArrayIN VAR BYTE[19]

        RFDataArrayOUT VAR BYTE[19]  

    'hold data for RF configuration

        RFConfigArray VAR BYTE[16]   

    'variables for each received or sent message

        msgFromID VAR BYTE

        msgToID VAR BYTE

    'ID variables   

        me  VAR BYTE    'ID that should be set to a unique number for each board

        friend  VAR BYTE

        me = 1      'ID that should be set to a unique number for each board

        friend = 2   

     'this variable in association with switch triggers a send  

         trigger VAR BIT

         trigger1 var bit

         trigger2 var bit

         click2 var bit

         trigger=0

         trigger1=0

         trigger2=0

         click2=0

         line_number VAR BYTE

         line_number=0    

         message1 var byte

         message1=0 

        

         doubleClick var bit

         doubleclick = 0 

        

         mode var byte

         mode2Sub var byte

         mode = 1

         mode2sub = 1

         energySub var word

         energySub = 0

         energy var word

         energy = 0

'***************************************************************************

'*END VARIABLES

'***************************************************************************

'***************************************************************************

'*BOOTUP + MAIN CODE

'***************************************************************************

    BOOTUP:

    gosub init

   

    MAIN:

       LOW RF_CS   ' bring CS low before turning CE high - only one high at a time!

       HIGH RF_CE  ' bring CE high to bring RF into active mode

          

        if(switch1=0 and trigger1=0) then

            trigger1=1

            doubleclick = 0

            newcounter=0

            while(newcounter < 255 AND doubleclick==0)

                newcounter = newcounter + 1

                if switch2 = 0 then

                    doubleclick = 1

                    trigger2 = 1

                    if mode<>2 then

                        gosub ledsoff

                    endif

                    mode=2

                endif

                pauseus 25

            wend

           

            if(doubleClick = 0) then

                if mode<>1 then

                    gosub ledsoff

                endif

                 mode=1

            endif

                   

        endif

       

        if(switch2=0 and trigger2=0) then

            trigger2=1

            doubleclick = 0

            newcounter=0

            while(newcounter < 255 AND doubleclick==0)

                newcounter = newcounter + 1

                if switch1 = 0 then

                    doubleclick = 1

                    trigger1 = 1

                    if mode<>2 then

                        gosub ledsoff

                    endif

                    mode=2

                endif

                pauseus 25

            wend

           

            if(doubleClick = 0) then

                click2 = 1

            endif

                   

        endif

       

        if(switch1=1) then

            trigger1=0

        endif

        if(switch2=1) then

            trigger2=0

        endif

       

        if(switchreed=0) then

            if(mode <> 1) then

                gosub ledsoff

            endif

            mode = 1           

        endif

   

        gosub mode1

        if(mode = 3) then

            pause 1

        endif

       

        if mode == 2 then

            gosub chase

        endif

       

        if mode == 3 then

            gosub ledsoff

        endif

   

       'if there's a message waiting in the RX buffer, read it

       IF RF_DR = 1 THEN

           INPUT RF_DATA_In 'This makes that pin an Input PIN

           GOSUB receiveRF

       ENDIF

        

       if click2 = 1 then

            gosub ledson

            pause 500

            click2 = 0

           msgToID = friend   ' CHANGE THIS TO WHO SHOULD RECIEVE MESSAGE

                line_number=1               

                message1=0            

                GOSUB sendData    ' goto the sendData function      

 

       endif

   

    GOTO main

   

   

   

   

   

'***************************************************************************

'*SUB PROGRAMS

'***************************************************************************      

    'RECEIVERF  

    'LOADARRAYS  

    'RUNDISPLAY  

    'SENDDATA  

    'SETRFCONFIG 

    'INITRFCONFIG

    

    RECEIVERF:  

        gosub ledson

        pause 1000

        INPUT RF_DATA_In 'Redudant? given we say this in main loop?

       'power down RF front-end for current conservation

       LOW RF_CE

       'clock in data from RF-24G to PIC

       FOR i=0 TO 18

           'clock should follow data by at least 50nsec

           ''This basically sends out a clock signal

           ''SHIFTIN  DataPin,ClockPin,Mode,[Var{\Bits}...]

           SHIFTIN RF_DATA_In, RF_CLK1, MSBPRE, [RFDataArrayIN[i]\8]

       NEXT

   

'       if RFDataArrayIn[3] == 1 then

'            high receive2led

'            pause 500

'            low receive2led

'       endif

     '  if rfdataarrayin[3] == 0 then

            for temp=0 to 4

                gosub ledson

                pause 250

                gosub ledsoff

                pause 250

            next temp

      ' endif

'       if rfdataarrayin[3] == 7 then

'            high receive3led

'            pause 500

'            low receive3led

'       endif

           

       'power up RF front-end again

      HIGH RF_CE

      'Absorb the incoming Message

      msgToID = RFDataArrayIN[0]       'the receiver is in msgToID

      msgFromID = RFDataArrayIN[1]    'sender information in msgFromID

   

      'Here we blink to acknowledge we have received the message

'        HIGH receiveLED:PAUSE 50:LOW receiveLED:PAUSE 50

'        HIGH receiveLED:PAUSE 50:LOW receiveLED:PAUSE 50   

    RETURN 'RECEIVERF

   

    SETARRAY:

   

    RETURN'SETOUTARRAY

   

    SENDDATA:

        '19 byte message

        'Load the RF data out array with our message

           RFDataArrayOUT[0] = msgToID

           RFDataArrayOUT[1] = msgFromID

           RFDataArrayOUT[2] = line_number 'this is line number 1-3, here just the number of times we've sent

           'This it the paragraph message

           'RFDataArrayOUT[3] = "0"'byteval'msgData1

           RFDataArrayOUT[3] = message1'byteval'msgData1

           RFDataArrayOUT[4] = "1"'msgData2

           RFDataArrayOUT[5] = "2"'msgData2

           RFDataArrayOUT[6] = "3"'msgData2

           RFDataArrayOUT[7] = "4"'msgData2

           RFDataArrayOUT[8] = "5"'msgData2

           RFDataArrayOUT[9] = "6"'msgData2

           RFDataArrayOUT[10] = "7"'msgData2

           RFDataArrayOUT[11] = "8"'msgData2

           RFDataArrayOUT[12] = "9"'msgData2

           RFDataArrayOUT[13] = "A"'msgData2

           RFDataArrayOUT[14] = line_number+48'msgData2

           RFDataArrayOUT[15] = "C"'msgData2

           RFDataArrayOUT[16] = "D"'msgData2

           RFDataArrayOUT[17] = "E"'msgData2

           RFDataArrayOUT[18] = "F"'msgData2

          

           'for newcounter = 3 to 18  'debug

           ' rfdataarrayout[newcounter] = message1

           'next newcounter

          

           'set RF to transmit mode...

            RFCurrentState = CONRFTX

            GOSUB setRFConfig

   

    ' for shockburst TX, the sum of RX address, payload, and CRC must be less than 256 bits long

    ' the chip then tacks on a preamble to this message, and the total msg is 266 bits

   

           OUTPUT RF_DATA_Out   'Makes the pin an Output

   

           'get back into active mode

           HIGH RF_CE

   

           'Need pause between CE high and DATA clock out

           PAUSEUS 100

   

           'clock out 5 byte RF address of recipient

           FOR i = 8 TO 12

               'clock out this byte

               SHIFTOUT RF_DATA_Out, RF_CLK1, MSBFIRST, [RFConfigArray[i]\8]

           NEXT

   

           'clock out 19 bytes of data payload

           FOR i = 0 TO 18

               'clock out this byte

               SHIFTOUT RF_DATA_Out, RF_CLK1, MSBFIRST, [RFDataArrayOUT[i]\8]

           NEXT

   

           'start shockburst transmission

           LOW RF_CE

           PAUSEUS 300

   

           'flash LED to indicate that we transmitted

'           HIGH sendLED:PAUSE 50:LOW sendLED:PAUSE 50

'           HIGH sendLED:PAUSE 50:LOW sendLED:PAUSE 50

       

           'afterward, set RF back to its default receive state

                RFCurrentState = CONRFRX

                GOSUB setRFConfig

    RETURN'SENDATA

          

    SETRFCONFIG:  '  THIS IS USED TO SWITCH BETWEEN RECIEVE AND TRANSMIT MODES   

       'during configuration of the transmitter, we need RF_DATA as an output

       OUTPUT RF_DATA_Out

   

       'set chip to configure mode (CE low, CS high)

       LOW RF_CE

       HIGH RF_CS

   

       'pause between CS high and DATA clockout

       PAUSEUS 100

   

       'RFCurrentState indicates 2402 Mhz frequency and either RX or TX state

       'clock out new configuration data from PIC to RF-24G

       SHIFTOUT RF_DATA_Out, RF_CLK1, MSBFIRST, [RFCurrentState\8]

   

       'configuration set on falling edge of CS

       LOW RF_CS

       LOW RF_CE

   

       'for consistency with the rx, stick this here

       INPUT RF_DR

   

       'flash the LED on B6 to indicate that we configured

       'high DEBUG_LED1

      ' pause 250

       'low DEBUG_LED1   

    RETURN'SETRFCONFIG

   

    INITRFCONFIG:

       'configuration is a 144 bit word

       'must be clocked in MSB first

       'bit map

       '143:120 - reserved for testing

       '119:112 - length of data payload section RX channel 2

       '111-104 - length of data payload section RX channel 1

       '103:64  - up to 5 byte address for RX channel 2

       '63:24   - up to 5 byte address for RX channel 1

       '23:18   - number of address bits (both RX channels)

       '17      - 8 or 16 bit CRC

       '16      - enable on-chip CRCD generation/checking

       '15      - enable two channel receive mode

       '14      - communication mode (direct or shockburst)

       '13      - RF data rate (1Mbps requires 16Mhz crystal)

       '12:10   - crystal frequency

       '9:8     - RF output power

       '7:1     - frequency channel

       '0       - RX or TX operation

   

       'setup RFConfigArray with config bytes, see datasheet for default configuration

       'this array is backwards so we can clock from MSB to LSB by increasing the index

       'Data bits 119-112: Max data width on channel 2 (excluding CRC and adrs)

        RFConfigArray[1] = $98 'payloadSize, 19 BYTES (this is 19*8 for bits in hex)

       'Data bits 111-104: Max data width on channel 1 (excluding CRC and adrs)

        RFConfigArray[2] = $98 'payloadSize, 19 BYTES

       'Data bits 103-64: Channel 2 address, 5 bytes (40 bits)

        RFConfigArray[3] = WhichAddress2

        RFConfigArray[4] = WhichAddress2

        RFConfigArray[5] = WhichAddress2

        RFConfigArray[6] = WhichAddress2

        RFConfigArray[7] = WhichAddress2

       'Data bits 63-24: Channel 1 address, 5 bytes (40 bits)

        RFConfigArray[8] = WhichAddress1

        RFConfigArray[9] = WhichAddress1

        RFConfigArray[10] = WhichAddress1

        RFConfigArray[11] = WhichAddress1

        RFConfigArray[12] = WhichAddress1

       'Data bits 23-16: Address width and CRC  - 40 bit addr, 16 bit CRC, CRC enabled

        RFConfigArray[13] = $A3

       'Data bits 15-8: One Channel Receive, Shockburst Enabled, 250 kilobits, etc

        RFConfigArray[14] = $4F

       'Data bits 7-0: 2402 Mhz frequency, RX enabled/disabled (depending on RFCurrentState)

        RFConfigArray[15] = RFCurrentState

   

       '===================================================================

       'During configuration of the transmitter, we need RF_DATA as an output

       INPUT RF_DR

       INPUT RF_DATA_In

       OUTPUT RF_DATA_Out

   

       'set chip to configure mode (CE low, CS high)

       LOW RF_CE

       HIGH RF_CS

   

       'pause between CS high and DATA clockout

       PAUSEUS 100

   

       'clock out configuration bytes from PIC to RF-24G

       FOR i = 1 TO 15

           'set config one byte at a time from MSB to LSB

           SHIFTOUT RF_DATA_Out, RF_CLK1, MSBFIRST, [RFConfigArray[i]\8]

       NEXT

       'configuration is set on the falling edge of CS, bring it low

       LOW RF_CS

       LOW RF_CE

   

       'flash LED on pin B6 to debug that we configured

        gosub chase

   

    RETURN'INITRFCONFIG

   

   

    INIT:

       

       WhichAddress1 =$F0 'These are things maybe to change????

       WhichAddress2 =$F0

       PORTA = %00000000;

       TRISA = %00000000;  ' 0 = Output, 1 = Input  (A.1 is RxPC)

   

       PORTB = %00000000;

       TRISB = %01101011;  ' 0 = Output, 1 = Input (C.1 is RF_DATA_In, C.3 is RF_DR)

   

        TRISC = %00000011;

       'intialize RF module configuration

       'constants to define receive/transmit modes at 2402 Mhz frequency

       CONRFRX = $05

       CONRFTX = $04

       RFCurrentState = CONRFRX

   

       GOSUB initRFConfig

   

       msgToID = 0   ' CHANGE THIS TO WHO SHOULD RECIEVE MESSAGE

       msgFromID = me   '  CHANGE THIS TO ID OF SENDER

       return

      

chase:   

        HIGH LED0

        PAUSE 40

        LOW LED0

        HIGH LED1

        PAUSE 40

        LOW LED1

        HIGH LED2

        PAUSE 40

        LOW LED2

        HIGH LED3

        PAUSE 40

        LOW LED3

        HIGH LED4

        PAUSE 40

        LOW LED4

        HIGH LED5

        PAUSE 40

        LOW LED5

        HIGH LED6

        PAUSE 40

        LOW LED6

        HIGH LED7

        PAUSE 40

        LOW LED7               

        return      

       

ledsOff:

    low led0

    low led1

    low led2

    low led3

    low led4

    low led5

    low led6

    low led7

   

    return

   

ledsOn:

    HIGH led0

    HIGH led1

    HIGH led2

    HIGH led3

    HIGH led4

    HIGH led5

    HIGH led6

    HIGH led7

   

    return

   

'***************************************************************************

'*END SUB PROGRAMS

'***************************************************************************   

mode1:

if(switchReed == 0) then

     gosub mode1Acc

else

    gosub mode1Desc

endif

if mode==1 then

    gosub mode1Disp

endif

return

; mode functions

mode1Desc:

    if mode == 2 and energy > 0 then

        energy = energy - 20

    else

        energySub = energySub + 1

        if energySub >= 5 then

        energySub = 0

        if(energy > 0) then

        energy = energy - 1

    endif

    endif

    endif

    return

mode1Acc:

    energySub = energySub + 1

    if energySub >= 1 then

    energySub = 0

    if(energy <= 2040) then

    energy = energy + 1

    endif

    endif

    return

   

mode1Disp:

    temp = energy / 255

    temp2 = energy // 255

    if(temp >= 0) then

        high led0

    else

        low led0

    endif

    if(temp >= 1) then

        high led1

    else

        low led1

    endif

    if(temp = 0) then

        pwm led1,temp2,1

    endif

    if(temp >= 2) then

        high LED2

    else

        low led2

    endif

    if(temp = 1) then

        pwm led2,temp2,1

    endif

    if(temp >= 3) then

        high LED3

    else

        low led3

    endif   

    if(temp = 2) then

        pwm led3,temp2,1

    endif

    if(temp >= 4) then

        high LED4

    else

        low led4

    endif

    if(temp = 3) then

        pwm led4,temp2,1

    endif   

    if(temp >= 5) then

        high LED5

    else

        low led5

    endif

    if(temp = 4) then

        pwm led5,temp2,1

    endif

    if(temp >= 6) then

        high LED6

    else

        low led6

    endif

    if(temp = 5) then

        pwm led6,temp2,1

    endif

    if(temp >= 7) then

        high LED7

    else

        low led7

    endif

    if(temp = 6) then

        pwm led7,temp2,1

    endif

return

mode2:

    gosub chase

    return


Code For Ochie's Cube



'Takes in 2 lines
OSCCON = %01111110
OSCTUNE = %10000000
DEFINE OSC 8 

'include modedefs.bas for shiftin and out modes
enable interrupt
INCLUDE "modedefs.bas"

ledr1 var trisb.0
ledb1 var trisc.5
ledg1 var trisc.6
ledr2 var trisc.7
ledb2 var trisd.4
ledg2 var trisd.5
ledr3 var trisd.6
ledb3 var trisd.7

ledg3 var trisc.4
ledr4 var trisd.3
ledb4 var trisd.2
ledg4 var trisd.1
ledr5 var trisd.0
ledb5 var trisc.3
ledg5 var trisc.2
ledr6 var trisc.1

ledb6 var trisa.1
ledg6 var trisa.2
ledr7 var trisa.3
ledb7 var trisa.4
ledg7 var trisa.5
ledr8 var trise.0
ledb8 var trise.1
ledg8 var trise.2



low portb.0
low portc.5
low portc.6
low portc.7
low portd.4
low portd.5
low portd.6
low portd.7

low portc.4
low portd.3
low portd.2
low portd.1
low portd.0
low portc.3
low portc.2
low portc.1

low porta.1
low porta.2
low porta.3
low porta.4
low porta.5
low porte.0
low porte.1
low porte.2

br1 var byte
br2 var byte
br3 var byte
br4 var byte
br5 var byte
br6 var byte
br7 var byte
br8 var byte

bg1 var byte
bg2 var byte
bg3 var byte
bg4 var byte
bg5 var byte
bg6 var byte
bg7 var byte
bg8 var byte

bb1 var byte
bb2 var byte
bb3 var byte
bb4 var byte
bb5 var byte
bb6 var byte
bb7 var byte
bb8 var byte

pwmCounter var byte

br1 = 0




'***************************************************************************
'*VARIABLES
'***************************************************************************
    'general purpose variables
        temp var byte
        temp2 var byte
        newCounter var byte
        i VAR BYTE
        counter VAR BYTE   
    'pin definitions for comm w/ Laipec TRW-24G
        RF_CE   VAR    PORTA.0 'yellow
        RF_CS   VAR    PORTB.4 'dark green
        RF_DR   VAR    PORTB.3 'blue
    'channel 1 PIN definitions
        RF_CLK1 VAR    PORTB.2 'black
        RF_DATA_In VAR PORTB.1 'light blue
        RF_DATA_Out VAR PORTB.1
    'I/O + Control PINS
 
       
        ' THIS IS THE ADDRESS FOR THE MiRF v01
        WhichAddress1 VAR BYTE    'Channel 1
        WhichAddress2 VAR BYTE    'Channel 2   
 
    'constants for RF configuration modes
        CONRFRX VAR BYTE
        CONRFTX VAR BYTE   
    'indicates state of current RF configuration - TX is 0, RX is 1
        RFCurrentState VAR BIT   
    'hold data for RF message
        RFDataArrayIN VAR BYTE[19]
        RFDataArrayOUT VAR BYTE[19]  
    'hold data for RF configuration
        RFConfigArray VAR BYTE[16]   
    'variables for each received or sent message
        msgFromID VAR BYTE
        msgToID VAR BYTE
    'ID variables   
        me  VAR BYTE    'ID that should be set to a unique number for each board
        friend  VAR BYTE
        me = 2      'ID that should be set to a unique number for each board
        friend = 1   
     'this variable in association with switch triggers a send  
         trigger VAR BIT
         trigger1 var bit
         trigger2 var bit
         click2 var bit
         trigger=0
         trigger1=0
         trigger2=0
         click2=0
         line_number VAR BYTE
         line_number=0    
         message1 var byte
         message1=0 
        
         doubleClick var bit
         doubleclick = 0 
        
         mode var byte
         mode2Sub var byte
         mode = 1
         mode2sub = 1
         energySub var word
         energySub = 0
         energy var word
         energy = 0


'***************************************************************************
'*END VARIABLES
'***************************************************************************

'***************************************************************************
'*BOOTUP + MAIN CODE
'***************************************************************************
    BOOTUP:
    gosub init
    gosub ledson
   
    MAIN:
       LOW RF_CS   ' bring CS low before turning CE high - only one high at a time!
       HIGH RF_CE  ' bring CE high to bring RF into active mode
          
       
       

   
       'if there's a message waiting in the RX buffer, read it
       IF RF_DR = 1 THEN
           INPUT RF_DATA_In 'This makes that pin an Input PIN
           GOSUB receiveRF
       ENDIF
      
   
    GOTO main
   
'***************************************************************************
'*SUB PROGRAMS
'***************************************************************************      
    'RECEIVERF  
    'LOADARRAYS  
    'RUNDISPLAY  
    'SENDDATA  
    'SETRFCONFIG 
    'INITRFCONFIG
    
    RECEIVERF:  
        INPUT RF_DATA_In 'Redudant? given we say this in main loop?
       'power down RF front-end for current conservation
       LOW RF_CE
       'clock in data from RF-24G to PIC
       FOR i=0 TO 18
           'clock should follow data by at least 50nsec
           ''This basically sends out a clock signal
           ''SHIFTIN  DataPin,ClockPin,Mode,[Var{\Bits}...]
           SHIFTIN RF_DATA_In, RF_CLK1, MSBPRE, [RFDataArrayIN[i]\8]
       NEXT
      
      msgToID = RFDataArrayIN[0]       'the receiver is in msgToID
      msgFromID = RFDataArrayIN[1]    'sender information in msgFromID
 
        
   
      if msgToid == me then
      gosub fadeout
'       if RFDataArrayIn[3] == 1 then
'            high led2
'            pause 500
'            low led2
'       endif
'       if rfdataarrayin[3] == 0 then
'            high led1
'            pause 500
'            low led1
'       endif
'       if rfdataarrayin[3] == 7 then
'            high led0
'            pause 500
'            low led0
'       endif
           


      'Absorb the incoming Message

   
      'Here we blink to acknowledge we have received the message
    endif  
    'power up RF front-end again
    HIGH RF_CE
    RETURN 'RECEIVERF
   
    SETARRAY:
   
    RETURN'SETOUTARRAY
   
    SENDDATA:
        '19 byte message
        'Load the RF data out array with our message
           RFDataArrayOUT[0] = msgToID
           RFDataArrayOUT[1] = msgFromID
           RFDataArrayOUT[2] = line_number 'this is line number 1-3, here just the number of times we've sent
           'This it the paragraph message
           'RFDataArrayOUT[3] = "0"'byteval'msgData1
           RFDataArrayOUT[3] = message1'byteval'msgData1
           RFDataArrayOUT[4] = "1"'msgData2
           RFDataArrayOUT[5] = "2"'msgData2
           RFDataArrayOUT[6] = "3"'msgData2
           RFDataArrayOUT[7] = "4"'msgData2
           RFDataArrayOUT[8] = "5"'msgData2
           RFDataArrayOUT[9] = "6"'msgData2
           RFDataArrayOUT[10] = "7"'msgData2
           RFDataArrayOUT[11] = "8"'msgData2
           RFDataArrayOUT[12] = "9"'msgData2
           RFDataArrayOUT[13] = "A"'msgData2
           RFDataArrayOUT[14] = line_number+48'msgData2
           RFDataArrayOUT[15] = "C"'msgData2
           RFDataArrayOUT[16] = "D"'msgData2
           RFDataArrayOUT[17] = "E"'msgData2
           RFDataArrayOUT[18] = "F"'msgData2
          
           'for newcounter = 3 to 18  'debug
           ' rfdataarrayout[newcounter] = message1
           'next newcounter
          
           'set RF to transmit mode...
            RFCurrentState = CONRFTX
            GOSUB setRFConfig
   
    ' for shockburst TX, the sum of RX address, payload, and CRC must be less than 256 bits long
    ' the chip then tacks on a preamble to this message, and the total msg is 266 bits
   
           OUTPUT RF_DATA_Out   'Makes the pin an Output
   
           'get back into active mode
           HIGH RF_CE
   
           'Need pause between CE high and DATA clock out
           PAUSEUS 100
   
           'clock out 5 byte RF address of recipient
           FOR i = 8 TO 12
               'clock out this byte
               SHIFTOUT RF_DATA_Out, RF_CLK1, MSBFIRST, [RFConfigArray[i]\8]
           NEXT
   
           'clock out 19 bytes of data payload
           FOR i = 0 TO 18
               'clock out this byte
               SHIFTOUT RF_DATA_Out, RF_CLK1, MSBFIRST, [RFDataArrayOUT[i]\8]
           NEXT
   
           'start shockburst transmission
           LOW RF_CE
           PAUSEUS 300
   
           'flash LED to indicate that we transmitted
       
           'afterward, set RF back to its default receive state
                RFCurrentState = CONRFRX
                GOSUB setRFConfig
    RETURN'SENDATA
          
    SETRFCONFIG:  '  THIS IS USED TO SWITCH BETWEEN RECIEVE AND TRANSMIT MODES   
       'during configuration of the transmitter, we need RF_DATA as an output
       OUTPUT RF_DATA_Out
   
       'set chip to configure mode (CE low, CS high)
       LOW RF_CE
       HIGH RF_CS
   
       'pause between CS high and DATA clockout
       PAUSEUS 100
   
       'RFCurrentState indicates 2402 Mhz frequency and either RX or TX state
       'clock out new configuration data from PIC to RF-24G
       SHIFTOUT RF_DATA_Out, RF_CLK1, MSBFIRST, [RFCurrentState\8]
   
       'configuration set on falling edge of CS
       LOW RF_CS
       LOW RF_CE
   
       'for consistency with the rx, stick this here
       INPUT RF_DR
   
       'flash the LED on B6 to indicate that we configured
       'high DEBUG_LED1
      ' pause 250
       'low DEBUG_LED1   
    RETURN'SETRFCONFIG
   
    INITRFCONFIG:
       'configuration is a 144 bit word
       'must be clocked in MSB first
       'bit map
       '143:120 - reserved for testing
       '119:112 - length of data payload section RX channel 2
       '111-104 - length of data payload section RX channel 1
       '103:64  - up to 5 byte address for RX channel 2
       '63:24   - up to 5 byte address for RX channel 1
       '23:18   - number of address bits (both RX channels)
       '17      - 8 or 16 bit CRC
       '16      - enable on-chip CRCD generation/checking
       '15      - enable two channel receive mode
       '14      - communication mode (direct or shockburst)
       '13      - RF data rate (1Mbps requires 16Mhz crystal)
       '12:10   - crystal frequency
       '9:8     - RF output power
       '7:1     - frequency channel
       '0       - RX or TX operation
   
       'setup RFConfigArray with config bytes, see datasheet for default configuration
       'this array is backwards so we can clock from MSB to LSB by increasing the index
       'Data bits 119-112: Max data width on channel 2 (excluding CRC and adrs)
        RFConfigArray[1] = $98 'payloadSize, 19 BYTES (this is 19*8 for bits in hex)
       'Data bits 111-104: Max data width on channel 1 (excluding CRC and adrs)
        RFConfigArray[2] = $98 'payloadSize, 19 BYTES
       'Data bits 103-64: Channel 2 address, 5 bytes (40 bits)
        RFConfigArray[3] = WhichAddress2
        RFConfigArray[4] = WhichAddress2
        RFConfigArray[5] = WhichAddress2
        RFConfigArray[6] = WhichAddress2
        RFConfigArray[7] = WhichAddress2
       'Data bits 63-24: Channel 1 address, 5 bytes (40 bits)
        RFConfigArray[8] = WhichAddress1
        RFConfigArray[9] = WhichAddress1
        RFConfigArray[10] = WhichAddress1
        RFConfigArray[11] = WhichAddress1
        RFConfigArray[12] = WhichAddress1
       'Data bits 23-16: Address width and CRC  - 40 bit addr, 16 bit CRC, CRC enabled
        RFConfigArray[13] = $A3
       'Data bits 15-8: One Channel Receive, Shockburst Enabled, 250 kilobits, etc
        RFConfigArray[14] = $4F
       'Data bits 7-0: 2402 Mhz frequency, RX enabled/disabled (depending on RFCurrentState)
        RFConfigArray[15] = RFCurrentState
   
       '===================================================================
       'During configuration of the transmitter, we need RF_DATA as an output
       INPUT RF_DR
       INPUT RF_DATA_In
       OUTPUT RF_DATA_Out
   
       'set chip to configure mode (CE low, CS high)
       LOW RF_CE
       HIGH RF_CS
   
       'pause between CS high and DATA clockout
       PAUSEUS 100
   
       'clock out configuration bytes from PIC to RF-24G
       FOR i = 1 TO 15
           'set config one byte at a time from MSB to LSB
           SHIFTOUT RF_DATA_Out, RF_CLK1, MSBFIRST, [RFConfigArray[i]\8]
       NEXT
       'configuration is set on the falling edge of CS, bring it low
       LOW RF_CS
       LOW RF_CE
   
       'flash LED on pin B6 to debug that we configured
   
    RETURN'INITRFCONFIG
   
'***************************************************************************
'*END SUB PROGRAMS
'***************************************************************************   

   INIT:
       
       WhichAddress1 =$F0 'These are things maybe to change????
       WhichAddress2 =$F0
       PORTA = %00000000;
       TRISA = %00000000;  ' 0 = Output, 1 = Input  (A.1 is RxPC)
   
       PORTB = %00000000;
       TRISB = %01101010;  ' 0 = Output, 1 = Input (C.1 is RF_DATA_In, C.3 is RF_DR)
   
        TRISC = %00000001;
       'intialize RF module configuration
       'constants to define receive/transmit modes at 2402 Mhz frequency
       CONRFRX = $05
       CONRFTX = $04
       RFCurrentState = CONRFRX
   
       GOSUB initRFConfig
   
       msgToID = 0   ' CHANGE THIS TO WHO SHOULD RECIEVE MESSAGE
       msgFromID = me   '  CHANGE THIS TO ID OF SENDER
       return


       
fadeOut:
    for br1 = 255 to 0 step -1
        for counter = 0 to 20
            gosub runpwm
        next counter
 
    next br1
    pause 3000
   
    gosub ledson
return        
       
runPWM:
    if br1 > 0 then
        gosub ledson
    else
        gosub ledsoff
    endif
   
    for pwmcounter = 0 to 255
        if br1 == pwmcounter then
            gosub ledsoff           
        endif
    next pwmcounter

return


ledsOff:
HIGH ledr1
HIGH ledb1
HIGH ledg1
HIGH ledr2
HIGH ledb2
HIGH ledg2
HIGH ledr3
HIGH ledb3

HIGH ledg3
HIGH ledr4
HIGH ledb4
HIGH ledg4
HIGH ledr5
HIGH ledb5
HIGH ledg5
HIGH ledr6

HIGH ledb6
HIGH ledg6
HIGH ledr7
HIGH ledb7
HIGH ledg7
HIGH ledr8
HIGH ledb8
HIGH ledg8

return


ledsOn:
low ledr1
low ledb1
low ledg1
low ledr2
low ledb2
low ledg2
low ledr3
low ledb3

low ledg3
low ledr4
low ledb4
low ledg4
low ledr5
low ledb5
low ledg5
low ledr6

low ledb6
low ledg6
low ledr7
low ledb7
low ledg7
low ledr8
low ledb8
low ledg8

return