Advertisement
Mukmin039

Main

May 5th, 2022
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.42 KB | None | 0 0
  1. /*
  2.  * File:   MatchingWristMain.c
  3.  * Author: Zoe
  4.  *
  5.  * Created on 7 de abril de 2022, 7:08
  6.  */
  7.  
  8.  
  9. #include "xc.h"
  10. #include "stdio.h"
  11. #include "math.h"
  12. //#include "iostream.h"
  13. //#include "FastLED.h"
  14. #include "nrf24_lib.h"
  15. #include "build/default/debug/../production/mcc_generated_files/../../production/mcc_generated_files/../../../../string.h"
  16. #include "mcc_generated_files/mcc.h"
  17.  
  18.  
  19.  
  20. NRF24_INIT_STATUS ret;
  21. unsigned char i;
  22. char buffer1[20];
  23. unsigned char bufferTX[32];
  24. unsigned char bufferRX[32];
  25.  
  26. #define NRF24L01_TX_EX  1
  27. #define NRF24L01_RX_EX  !NRF24L01_TX_EX
  28.  
  29. void blink_led() {
  30.     LED_Toggle();
  31. }
  32.  
  33.  
  34.        
  35.  
  36.  
  37.  
  38. //#define LED_PIN 2
  39. //#define NUM_LED 3
  40.  
  41. //CRGB leds[NUM_LED];
  42.  
  43. //void setup ()
  44. //{
  45. //FastLED.addLeds<WS2812,LED_PIN, RGB>(leds,NUM_LED);
  46. //FastLED.SetMaxPowerInVoltsAndMilliamps(3,300);
  47. //leds[1]= CRGB (0,255,0);
  48. //FastLED.show();
  49. //FastLED.clear();
  50. //}
  51.  
  52. void Led_color(int color)
  53. {
  54. if (color==1)
  55. {
  56. //leds[1]= CRGB[255,0,0];
  57. //FastLED.show();
  58. int k;
  59. for (k=0;k<= 6;k++)
  60. {
  61. //FastLED.SetBrightness(60);
  62. //delay(50);
  63. //FastLED.SetBrightness(10);
  64. //delay(10);
  65. printf("blink Red color\n");
  66. }
  67. }
  68. if (color==2)
  69. {
  70. //leds[1]= CRGB[0,0,255];
  71. //FastLED.show();
  72. int w;
  73. for (w=0;w<= 6;w++)
  74. {
  75. //FastLED.SetBrightness(60);
  76. //delay(50);
  77. //FastLED.SetBrightness(10);
  78. //delay(10);
  79. printf("blink yellow color\n");
  80. }
  81. }
  82. if (color==3)
  83. {
  84. //leds[1]= CRGB[0,255,0];
  85. //FastLED.show();
  86. int z;
  87. for (z=0;z<= 6;z++)
  88. {
  89. //FastLED.SetBrightness(60);
  90. //delay(50);
  91. //FastLED.SetBrightness(10);
  92. //delay(10);
  93. printf("blink green colour\n");
  94. }
  95. }
  96. }
  97.  
  98.  
  99. int main()
  100. {
  101.  
  102.     // Initialize the device
  103.     SYSTEM_Initialize();
  104.  
  105.     // If using interrupts in PIC18 High/Low Priority Mode you need to enable the Global High and Low Interrupts
  106.     // If using interrupts in PIC Mid-Range Compatibility Mode you need to enable the Global and Peripheral Interrupts
  107.     // Use the following macros to:
  108.  
  109.     // Enable the Global Interrupts
  110.     INTERRUPT_GlobalInterruptEnable();
  111.  
  112.     // Disable the Global Interrupts
  113.     //INTERRUPT_GlobalInterruptDisable();
  114.  
  115.     // Enable the Peripheral Interrupts
  116.     INTERRUPT_PeripheralInterruptEnable();
  117.  
  118.     // Disable the Peripheral Interrupts
  119.     //INTERRUPT_PeripheralInterruptDisable();  
  120.    
  121. TMR0_SetInterruptHandler(blink_led);
  122. TMR0_StartTimer();    
  123. SPI1_Open(SPI1_DEFAULT);  
  124. #if NRF24L01_TX_EX
  125.     ret = nrf24_rf_init(TX_MODE,115); // Tx mode with 2400+115 Ghz RF frq
  126. #elif NRF24L01_RX_EX
  127.     ret = nrf24_rf_init(RX_MODE, 115); // Rx mode with 2400+115 Ghz RF frq
  128. #endif
  129.  
  130.    
  131. char guest[50];
  132. char data[14]={0x03,0x65,0x43,0x69,0x6B,0x6F,0x75,0x7F,0x81,0x83,0x8B,0x8E,0x90,0x96};//number of the device plus personal data
  133. for (int i=0;i<=13;i++)
  134. {
  135. sprintf(guest, "guest %x", data[i]);
  136. //nrf24_send_data(guest);
  137. puts(guest);
  138. }
  139.  
  140. //data reception
  141. //#elif nr24l01_rx_ex
  142. //while nr24l01_data available
  143. char buffer;
  144. unsigned char host[14];
  145. for (int x=0;x<=13;x++)
  146. {
  147. //nrf24l01_read_rf_data(bufferrx)
  148. printf("please input your host data");
  149. scanf("%c",&buffer);
  150. host[x]=buffer;
  151. //sprintf(host[x],"datos%x",bufferrx);
  152. //puts(host);
  153. }
  154. printf("dispositivos a comparar=%x,%x\n",data[0],host[0]);
  155. if (data[0]==host[0]) //checks if its the same tx
  156. {
  157. printf("Dispositivo ya escaneado\n");
  158. goto finito;
  159. // end data reception
  160. //need to add code to remember several devices to dont keep comparing)
  161. }
  162. else
  163. {
  164. printf("New device\n");
  165. //puts(host);
  166. }
  167. char guest2[50];
  168. for (int y=0;y<=13;y++)
  169. {
  170. sprintf(guest2, "host %x", host[y]);
  171. puts(guest2);
  172. }
  173.  
  174. //compatibility
  175. int c;
  176. if (data[1]==host[1])//revisa genero
  177. {
  178. printf("Mismo genero\n");
  179. Led_color(1);
  180. goto finito;
  181. //flash red the wrist
  182. }
  183. else
  184. {
  185. //convert host and data [2] to integer
  186. printf("Genero compatible\n");
  187. if ( host[2]<=data[2])//revisa edad
  188. {
  189. printf("Edad compatible\n");
  190. if ((host[3]==0x67 )||(host[3]==0x69)||(host[3]==0x6a))//revisa estado civil
  191. {
  192. printf("Estado civil compatible\n");
  193. if (host[4]==0x6c)//sin hijos
  194. {
  195. printf("Hijos compatible\n");
  196. if (data[5]==host[5])//misma.religion
  197. {
  198. printf("Religion compatible\n");
  199. if ((host[6]==0x75)||(host[6]==0x76)||(host[6]==0x77)||(host[6]==78)) // le gusta la profesion
  200. {
  201. printf("Profesion compatible\n");
  202. if (host[7]==0x7f)//si no toma
  203. {
  204. printf("Bebida compatible\n");
  205. if (host[8]==81)//si no fuma
  206. {
  207. printf("Fumar compatible\n"); if((host[9]==0x82)||(host[9]==0x83)||(host[9]==0x84))// agree with his job
  208.   {
  209. printf("Trabajo compatible\n");
  210. if ((host[10]==0x87)||(host[10]==0x8A)||(host[10]==0x8C))// likes character
  211. {
  212. printf("Caracter compatible\n");
  213. if (host[11]==0x8E)//likes have a house
  214. {
  215. printf("Casa compatible\n");
  216. if (host[12]==0x90)//likes have a car
  217. {
  218. printf("Carro compatible\n");
  219. if (( host[13]==0x92)||(host[13]==0x93)||(host[13]==0x94)||(host[13]==99))//likes behaviour
  220. {
  221.    printf("Personalidad compatible\n");
  222.    Led_color(3);
  223.   }        
  224.   else
  225.   {
  226.   //flash yellow wrist
  227. printf("personalidad no compatible\n");
  228. Led_color(2);
  229.     }
  230.                        
  231.                   }
  232.                   else
  233.                   {
  234.                        printf("carro no compatible\n");Led_color(2);
  235.                   //flash yellow.wrist
  236.                   }
  237.                  
  238.                   }
  239.                   else
  240.                   {
  241.                      printf("casa no compatible\n");Led_color(2);                
  242.                   //flash yellow wrist
  243.                   }
  244.                 }
  245.                 else
  246.                 {
  247.                 printf("caracter no compatible\n");Led_color(2);
  248.                 //flash yellow wrist
  249.                 }
  250.                
  251.                
  252.               }
  253.               else
  254.               {
  255.               printf("Trabajo no compatible\n");Led_color(2);
  256.               //flash yellow.wrist
  257.               }
  258.              
  259. }
  260. else
  261. {
  262. printf("Fumar no compatible\n");
  263. Led_color(1);
  264.     //flash.red wrist
  265. }
  266. }
  267. else
  268. {
  269. printf("Bebida no compatible\n");
  270. Led_color(1);
  271. //flash red wrist
  272. }
  273. }
  274. else
  275. {
  276. printf("Profesion no compatible\n");
  277. Led_color(1);
  278. //flash red wrist
  279. }
  280. }
  281. else
  282. {
  283. printf("Religion no compatible\n");
  284. Led_color(1);
  285. //flash red wrist
  286. }
  287. }
  288. else
  289. {
  290. printf("hijos no compatible\n");
  291. Led_color(1);
  292. //flash red wrist
  293. }
  294. }
  295. else
  296. {
  297. printf("Estado civil no compatible\n");
  298. Led_color(1);
  299. //flash red wrist
  300. }
  301. }
  302. else
  303. {
  304. printf("Edad no compatible\n");
  305. Led_color(1);
  306. //flash red wrist
  307. }
  308. //
  309. finito:
  310. return (0);
  311. }
  312. }
  313.  
  314.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement