Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string.h>
- #include <Arduino.h>
- #include <Arduino_FreeRTOS.h>
- #include "queue.h"
- #include "tasks.hpp"
- #include "message.hpp"
- const int LED_Blue = 9;
- const int LED_Red = 10;
- const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
- LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
- const int buzzer = 8; //buzzer to arduino pin 9
- // Task one sends a message to task two every 3 seconds.
- // The number in the message increases by one every time.
- void taskOne(void* queue)
- Serial.begin(115200);
- lcd.begin(16,2);
- pinMode(buzzer,OUTPUT);
- String rx_byte;
- piezofrequency = Serial.parseInt();
- {
- if(Serial.available()>0){
- rx_byte = Serial.readString();
- Serial.setTimeout(1000);
- Serial.print(rx_byte+'\n');
- }
- // Fill out the initial values in the message
- while(1)
- {
- Serial.println("Sending message to task two.");
- // Send the message. Blocks if the queue is full
- xQueueSend(queue, &rx_byte, portMAX_DELAY);
- // message.number++;
- // Suspend for three seconds until we send again
- vTaskDelay(pdMS_TO_TICKS(3000));
- }
- }
- // Task two waits for a message then prints out what it received.
- // xQueueReceive() blocks the task until a message is available.
- void taskTwo(void* queue)
- {
- while (1)
- {
- String rx_byte;
- // Block while waiting for a message
- xQueueReceive(queue, &rx_byte, portMAX_DELAY);
- if (rx_byte == "Led 1 on") {
- digitalWrite(LED_Blue, HIGH);
- }
- else if ( rx_byte == "Led 1 off"){
- digitalWrite(LED_Blue, LOW);
- }
- else if (rx_byte == "Led 2 on") {
- digitalWrite(LED_Red, HIGH);
- }
- else if (rx_byte == "Led 2 off") {
- digitalWrite(LED_Red, LOW);
- }
- else if(rx_byte =="Piezo " + piezofrequency){
- piezofrequency = Serial.parseInt();
- Serial.print(piezofrequency);
- tone(buzzer, piezofrequency);
- }
- else if(rx_byte == "Piezo 0"){
- noTone(buzzer);
- }
- else if(rx_byte == "Get pot"){
- Serial.print(analogRead(A0));
- Serial.print('\n');
- }
- else if(rx_byte =="Set lcd"){
- lcd.clear();
- rx_byte = Serial.readString();
- Serial.print(rx_byte);
- lcd.print(rx_byte);
- Serial.print('\n');
- }
- /*
- // Create a log string of the message
- char log[50];
- sprintf(log, "%d %s", message.number, message.text);
- // Print out the message we got
- Serial.println("Got number and text from task one:");
- Serial.println(log);*/
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement