Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * File: MatchingWristMain.c
- * Author: Zoe
- *
- * Created on 7 de abril de 2022, 7:08
- */
- #include "xc.h"
- #include "stdio.h"
- #include "math.h"
- //#include "iostream.h"
- //#include "FastLED.h"
- #include "nrf24_lib.h"
- #include "build/default/debug/../production/mcc_generated_files/../../production/mcc_generated_files/../../../../string.h"
- #include "mcc_generated_files/mcc.h"
- NRF24_INIT_STATUS ret;
- unsigned char i;
- char buffer1[20];
- unsigned char bufferTX[32];
- unsigned char bufferRX[32];
- #define NRF24L01_TX_EX 1
- #define NRF24L01_RX_EX !NRF24L01_TX_EX
- void blink_led() {
- LED_Toggle();
- }
- //#define LED_PIN 2
- //#define NUM_LED 3
- //CRGB leds[NUM_LED];
- //void setup ()
- //{
- //FastLED.addLeds<WS2812,LED_PIN, RGB>(leds,NUM_LED);
- //FastLED.SetMaxPowerInVoltsAndMilliamps(3,300);
- //leds[1]= CRGB (0,255,0);
- //FastLED.show();
- //FastLED.clear();
- //}
- void Led_color(int color)
- {
- if (color==1)
- {
- //leds[1]= CRGB[255,0,0];
- //FastLED.show();
- int k;
- for (k=0;k<= 6;k++)
- {
- //FastLED.SetBrightness(60);
- //delay(50);
- //FastLED.SetBrightness(10);
- //delay(10);
- printf("blink Red color\n");
- }
- }
- if (color==2)
- {
- //leds[1]= CRGB[0,0,255];
- //FastLED.show();
- int w;
- for (w=0;w<= 6;w++)
- {
- //FastLED.SetBrightness(60);
- //delay(50);
- //FastLED.SetBrightness(10);
- //delay(10);
- printf("blink yellow color\n");
- }
- }
- if (color==3)
- {
- //leds[1]= CRGB[0,255,0];
- //FastLED.show();
- int z;
- for (z=0;z<= 6;z++)
- {
- //FastLED.SetBrightness(60);
- //delay(50);
- //FastLED.SetBrightness(10);
- //delay(10);
- printf("blink green colour\n");
- }
- }
- }
- int main()
- {
- // Initialize the device
- SYSTEM_Initialize();
- // If using interrupts in PIC18 High/Low Priority Mode you need to enable the Global High and Low Interrupts
- // If using interrupts in PIC Mid-Range Compatibility Mode you need to enable the Global and Peripheral Interrupts
- // Use the following macros to:
- // Enable the Global Interrupts
- INTERRUPT_GlobalInterruptEnable();
- // Disable the Global Interrupts
- //INTERRUPT_GlobalInterruptDisable();
- // Enable the Peripheral Interrupts
- INTERRUPT_PeripheralInterruptEnable();
- // Disable the Peripheral Interrupts
- //INTERRUPT_PeripheralInterruptDisable();
- TMR0_SetInterruptHandler(blink_led);
- TMR0_StartTimer();
- SPI1_Open(SPI1_DEFAULT);
- #if NRF24L01_TX_EX
- ret = nrf24_rf_init(TX_MODE,115); // Tx mode with 2400+115 Ghz RF frq
- #elif NRF24L01_RX_EX
- ret = nrf24_rf_init(RX_MODE, 115); // Rx mode with 2400+115 Ghz RF frq
- #endif
- char guest[50];
- char data[14]={0x03,0x65,0x43,0x69,0x6B,0x6F,0x75,0x7F,0x81,0x83,0x8B,0x8E,0x90,0x96};//number of the device plus personal data
- for (int i=0;i<=13;i++)
- {
- sprintf(guest, "guest %x", data[i]);
- //nrf24_send_data(guest);
- puts(guest);
- }
- //data reception
- //#elif nr24l01_rx_ex
- //while nr24l01_data available
- char buffer;
- unsigned char host[14];
- for (int x=0;x<=13;x++)
- {
- //nrf24l01_read_rf_data(bufferrx)
- printf("please input your host data");
- scanf("%c",&buffer);
- host[x]=buffer;
- //sprintf(host[x],"datos%x",bufferrx);
- //puts(host);
- }
- printf("dispositivos a comparar=%x,%x\n",data[0],host[0]);
- if (data[0]==host[0]) //checks if its the same tx
- {
- printf("Dispositivo ya escaneado\n");
- goto finito;
- // end data reception
- //need to add code to remember several devices to dont keep comparing)
- }
- else
- {
- printf("New device\n");
- //puts(host);
- }
- char guest2[50];
- for (int y=0;y<=13;y++)
- {
- sprintf(guest2, "host %x", host[y]);
- puts(guest2);
- }
- //compatibility
- int c;
- if (data[1]==host[1])//revisa genero
- {
- printf("Mismo genero\n");
- Led_color(1);
- goto finito;
- //flash red the wrist
- }
- else
- {
- //convert host and data [2] to integer
- printf("Genero compatible\n");
- if ( host[2]<=data[2])//revisa edad
- {
- printf("Edad compatible\n");
- if ((host[3]==0x67 )||(host[3]==0x69)||(host[3]==0x6a))//revisa estado civil
- {
- printf("Estado civil compatible\n");
- if (host[4]==0x6c)//sin hijos
- {
- printf("Hijos compatible\n");
- if (data[5]==host[5])//misma.religion
- {
- printf("Religion compatible\n");
- if ((host[6]==0x75)||(host[6]==0x76)||(host[6]==0x77)||(host[6]==78)) // le gusta la profesion
- {
- printf("Profesion compatible\n");
- if (host[7]==0x7f)//si no toma
- {
- printf("Bebida compatible\n");
- if (host[8]==81)//si no fuma
- {
- printf("Fumar compatible\n"); if((host[9]==0x82)||(host[9]==0x83)||(host[9]==0x84))// agree with his job
- {
- printf("Trabajo compatible\n");
- if ((host[10]==0x87)||(host[10]==0x8A)||(host[10]==0x8C))// likes character
- {
- printf("Caracter compatible\n");
- if (host[11]==0x8E)//likes have a house
- {
- printf("Casa compatible\n");
- if (host[12]==0x90)//likes have a car
- {
- printf("Carro compatible\n");
- if (( host[13]==0x92)||(host[13]==0x93)||(host[13]==0x94)||(host[13]==99))//likes behaviour
- {
- printf("Personalidad compatible\n");
- Led_color(3);
- }
- else
- {
- //flash yellow wrist
- printf("personalidad no compatible\n");
- Led_color(2);
- }
- }
- else
- {
- printf("carro no compatible\n");Led_color(2);
- //flash yellow.wrist
- }
- }
- else
- {
- printf("casa no compatible\n");Led_color(2);
- //flash yellow wrist
- }
- }
- else
- {
- printf("caracter no compatible\n");Led_color(2);
- //flash yellow wrist
- }
- }
- else
- {
- printf("Trabajo no compatible\n");Led_color(2);
- //flash yellow.wrist
- }
- }
- else
- {
- printf("Fumar no compatible\n");
- Led_color(1);
- //flash.red wrist
- }
- }
- else
- {
- printf("Bebida no compatible\n");
- Led_color(1);
- //flash red wrist
- }
- }
- else
- {
- printf("Profesion no compatible\n");
- Led_color(1);
- //flash red wrist
- }
- }
- else
- {
- printf("Religion no compatible\n");
- Led_color(1);
- //flash red wrist
- }
- }
- else
- {
- printf("hijos no compatible\n");
- Led_color(1);
- //flash red wrist
- }
- }
- else
- {
- printf("Estado civil no compatible\n");
- Led_color(1);
- //flash red wrist
- }
- }
- else
- {
- printf("Edad no compatible\n");
- Led_color(1);
- //flash red wrist
- }
- //
- finito:
- return (0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement