Advertisement
Guest User

Untitled

a guest
Mar 19th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. #define MaxCountForTurns 300 //count for 2 rotations of the motor
  2.  
  3. int main(void)
  4. {
  5. CyGlobalIntEnable; /* Enable global interrupts. */
  6.  
  7.  
  8. uint16 onCount = 0x00;
  9. uint16 offCount = 0x00;
  10. uint8 gateClose = 0x00;
  11. uint8 motorON = 0x00;
  12. uint8 pirValue = 0x00;
  13.  
  14.  
  15. UART_Start();
  16.  
  17. for(;;)
  18. {
  19. if (gateClose == 0x00) {
  20. pirValue |= pirInput_Read();
  21. }
  22.  
  23. if ((pirValue & 0x01) && (motorON == 0)) {
  24. motorON = 0x01;
  25. UART_PutString("Pet movement detected : Motor will be turned ONn");
  26. CyDelay(10);
  27. }
  28. if(motorON) {
  29. onCount++;
  30. Control_Reg_Write(0x0c);
  31. CyDelay(10);
  32. Control_Reg_Write(0x06);
  33. CyDelay(10);
  34. Control_Reg_Write(0x03);
  35. CyDelay(10);
  36. Control_Reg_Write(0x09);
  37. CyDelay(10);
  38. }
  39.  
  40. if (gateClose) {
  41. offCount++;
  42. Control_Reg_Write(0x09);
  43. CyDelay(10);
  44. Control_Reg_Write(0x03);
  45. CyDelay(10);
  46. Control_Reg_Write(0x06);
  47. CyDelay(10);
  48. Control_Reg_Write(0x0c);
  49. CyDelay(10);
  50. }
  51.  
  52. // turns in fwd direction
  53. if(onCount > MaxCountForTurns) {
  54. motorON = 0x00;
  55. onCount = 0x00;
  56. pirValue = 0x00;
  57. CyDelay(50);
  58. gateClose = 0x01;
  59. }
  60.  
  61. // turns in reverse direction
  62. if(offCount > MaxCountForTurns) {
  63. gateClose &= 0x00;
  64. }
  65. }
  66. }
  67.  
  68. import time
  69. import serial
  70. import smtplib
  71. TO = 'pet_feeder@gmail.com'
  72. GMAIL_USER = 'pir_sensor@gmail.com'
  73. GMAIL_PASS = 'psoc_pir_pet_feeder'
  74. SUBJECT = 'Pet Feeder System Alert!!'
  75. TEXT = 'PIR sensor detected pet movement, Motor will be turned ON'
  76. ser = serial.Serial('COM2', 9600)
  77. def send_email():
  78. print("Sending Email")
  79. smtpserver = smtplib.SMTP("smtp.gmail.com",587)
  80. smtpserver.ehlo()
  81. smtpserver.starttls()
  82. smtpserver.ehlo
  83. smtpserver.login(GMAIL_USER, GMAIL_PASS)
  84. header = 'To:' + TO + 'n' + 'From: ' + GMAIL_USER
  85. header = header + 'n' + 'Subject:' + SUBJECT + 'n'
  86. print header
  87. msg = header + 'n' + TEXT + ' nn'
  88. smtpserver.sendmail(GMAIL_USER, TO, msg)
  89. smtpserver.close()
  90.  
  91. while True:
  92. message = ser.readline()
  93. print(message)
  94. if message[0] == 'M' :
  95. send_email()
  96. time.sleep(0.5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement