Example #1
0
////////////////////////////////////////////////////////////////////////////////
////                                                                        ////
////                            Sender Code                                 ////
////                                                                        ////
////////////////////////////////////////////////////////////////////////////////
void senderMain() {
    int fixweirdbehavior;
    unsigned char status;
    short i;
    char mode;
    short offset;

    //OpenADC(ADC_FOSC_64 & ADC_RIGHT_JUST & ADC_20_TAD, ADC_CH0 & ADC_INT_OFF, 0b0000);

    nrf_init();
    delay();

    nrf_txmode();
    delay();

    PIE1bits.RC1IE = SET; //enables peripheral interrupts for serial

    INTCONbits.TMR0IE = 0;
    INTCONbits.TMR0IF = 0;
    INTCONbits.PEIE = 1;
    INTCONbits.GIE = 1;

    LED_RED = 0;
    LED_GREEN = 0;
//    mode = 0;
//    while(1) {
//        //while (!PIR1bits.RC1IF);
//        //LED_RED = 1;
//        //readSerialIntoBuffer(led_buffer);
//        //LED_RED = 0;
//        //delay();
//
//        mode = !mode;
//        led_buffer[3] = mode ? 25 : 0;
//        led_buffer[4] = mode ? 25 : 0;
//        led_buffer[5] = mode ? 25 : 0;
//        sendStrip();
//        //STATUS_LED = 0;
//    }

    mode = 0;

    offset = 0;
    //LED_GREEN = 0;
    while(1) {
        //LED_RED++;

        offset ++;
        if (offset >= 125) offset = 0;

        //value = readPotentiometer();
        //value = value >> 4;
        //value = value >> 1;
        //if (value > 124) value = 124;

        //offset = value;
        //if (value > offset) offset++;
        //if (value < offset) offset--;

//        if (mode) {
//            clearStrip(0,0,0);
//            setLED(offset,10,10,10);
        //} else {
        for (i = 0; i<125; i++) {
            led_buffer[3*i] =   10*((i+offset) % 3 == 0);
            led_buffer[3*i+1] = 10*((i+offset) % 3 == 1);
            led_buffer[3*i+2] = 10*((i+offset) % 3 == 2);
        }
        //åloadPayload
        //writeSource(offset);
        //}

        //Delay10KTCYx(50);

        sendStrip();

        //sendStrip();
    }

    //CloseADC();
}
Example #2
0
void masterMain() {
    //master
    short i;
    short l;
    short nextSlot;
    int clients[MAX_CLIENTS];
    int clientInfo[MAX_CLIENTS];

    nrf_init();
    delay();

    nrf_txmode();
    delay();
    
    nextSlot = 0;
    for (i=0; i<MAX_CLIENTS; i++) {
        clients[i] = 0;
    }

    sendLiteralBytes("\nLoop Start\n");
    LED_RED = 0;
    LED_GREEN = 0;
//    while(1) {
//        LED_RED = !LED_RED;
//        LED_GREEN = nrf_send(&tx_buf,&rx_buf);
//        delay();
//    }
    while(1) {
        LED_RED = !LED_RED;
        delay();
        sendIntArray(&clients,MAX_CLIENTS);
        sendLiteralBytes("\n");
        
        nrf_setTxAddr(0); //master channel
        nrf_setRxAddr(0,0); //master channel
        tx_buf[0] = 0x42;
        tx_buf[1] = nextSlot+1;
        //sendLiteralBytes("Attempt Send\n");
        //displayStatus(nrf_getStatus());
        if (nrf_send(&tx_buf,&rx_buf)) {
            sendLiteralBytes("\nClient Connected!\n");

            clients[nextSlot] = 1;

            //find the next available slot
            nextSlot = -1;
            for (i=0; i<MAX_CLIENTS; i++) {
                if (clients[i] == 0) {
                    nextSlot = i;
                    break;
                }
            }
        }

        for (i=0; i<MAX_CLIENTS; i++) {
            if (clients[i] != 0) {
                nrf_setTxAddr(i+1); //slave channel
                nrf_setRxAddr(0,i+1); //slave channel
                if (nrf_send(&tx_buf,&rx_buf)) {
                    clients[i] = 1;
                    clientInfo[i] = 1;
                } else {
                    clients[i]++;
                    if (clients[i] > 3) {
                        sendLiteralBytes("Client Disconnected!\n");
                        clients[i] = 0;
                        clientInfo[i] = 0;
                    }
                    for (l=0; l<MAX_CLIENTS; l++) {
                        if (clients[l] == 0) {
                            nextSlot = l;
                            break;
                        }
                    }
                }
            }
        }
    }
}