Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. #include <string.h>
  2.  
  3. #include <Arduino.h>
  4. #include <Arduino_FreeRTOS.h>
  5. #include "queue.h"
  6.  
  7. #include "tasks.hpp"
  8. #include "message.hpp"
  9. const int LED_Blue = 9;
  10. const int LED_Red = 10;
  11. const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
  12. LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
  13. const int buzzer = 8; //buzzer to arduino pin 9
  14.  
  15.  
  16. // Task one sends a message to task two every 3 seconds.
  17. // The number in the message increases by one every time.
  18. void taskOne(void* queue)
  19. Serial.begin(115200);
  20. lcd.begin(16,2);
  21. pinMode(buzzer,OUTPUT);
  22. String rx_byte;
  23. piezofrequency = Serial.parseInt();
  24.  
  25. {
  26. if(Serial.available()>0){
  27. rx_byte = Serial.readString();
  28. Serial.setTimeout(1000);
  29. Serial.print(rx_byte+'\n');
  30. }
  31.  
  32.  
  33.  
  34.  
  35. // Fill out the initial values in the message
  36.  
  37. while(1)
  38. {
  39. Serial.println("Sending message to task two.");
  40.  
  41. // Send the message. Blocks if the queue is full
  42. xQueueSend(queue, &rx_byte, portMAX_DELAY);
  43. // message.number++;
  44.  
  45. // Suspend for three seconds until we send again
  46. vTaskDelay(pdMS_TO_TICKS(3000));
  47. }
  48. }
  49.  
  50. // Task two waits for a message then prints out what it received.
  51. // xQueueReceive() blocks the task until a message is available.
  52. void taskTwo(void* queue)
  53. {
  54. while (1)
  55. {
  56. String rx_byte;
  57.  
  58. // Block while waiting for a message
  59. xQueueReceive(queue, &rx_byte, portMAX_DELAY);
  60.  
  61. if (rx_byte == "Led 1 on") {
  62. digitalWrite(LED_Blue, HIGH);
  63. }
  64. else if ( rx_byte == "Led 1 off"){
  65. digitalWrite(LED_Blue, LOW);
  66. }
  67. else if (rx_byte == "Led 2 on") {
  68. digitalWrite(LED_Red, HIGH);
  69. }
  70. else if (rx_byte == "Led 2 off") {
  71. digitalWrite(LED_Red, LOW);
  72. }
  73. else if(rx_byte =="Piezo " + piezofrequency){
  74. piezofrequency = Serial.parseInt();
  75. Serial.print(piezofrequency);
  76. tone(buzzer, piezofrequency);
  77. }
  78. else if(rx_byte == "Piezo 0"){
  79.  
  80. noTone(buzzer);
  81.  
  82. }
  83. else if(rx_byte == "Get pot"){
  84. Serial.print(analogRead(A0));
  85. Serial.print('\n');
  86.  
  87. }
  88.  
  89. else if(rx_byte =="Set lcd"){
  90. lcd.clear();
  91. rx_byte = Serial.readString();
  92. Serial.print(rx_byte);
  93. lcd.print(rx_byte);
  94. Serial.print('\n');
  95. }
  96.  
  97. /*
  98. // Create a log string of the message
  99. char log[50];
  100. sprintf(log, "%d %s", message.number, message.text);
  101.  
  102. // Print out the message we got
  103. Serial.println("Got number and text from task one:");
  104. Serial.println(log);*/
  105. }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement