Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Arduino.h>
- #include <LiquidCrystal.h>
- #include <Arduino_FreeRTOS.h>
- #include <string.h>
- #include <queue.h>
- #include <struct.hpp>
- LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
- void taskOne(void *pvParameters);
- void taskTwo(void *pvParameters);
- QueueHandle_t queue;
- void setup() {
- Serial.begin(115200);
- lcd.begin(16, 2);
- pinMode(7, OUTPUT);
- pinMode(8, OUTPUT);
- queue = xQueueCreate(10, sizeof(struct_t));
- xTaskCreate(taskOne, "Task one", 256, queue, 2, NULL);
- xTaskCreate(taskTwo, "Task two", 256, queue, 2, NULL);
- }
- void loop() {
- }
- void taskOne(void* queue)
- {
- struct_t message;
- char kopi[30];
- memset(kopi, 0x00, strlen(kopi));
- Serial.readBytes(kopi, 50);
- strcat(kopi, "\0");
- strcpy(message.goddag, kopi);
- while(1)
- {
- xQueueSend(queue, &message, portMAX_DELAY);
- memset(message.goddag, 0, strlen(message.goddag));
- // 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)
- {
- struct_t message;
- while (1)
- {
- xQueueReceive(queue, &message, portMAX_DELAY);
- char log[30];
- memset(log, 0x00, sizeof(log));
- //sprintf(log, "%s", message.goddag);
- strcpy(log, message.goddag);
- Serial.println(log);
- //Serial.println(log);
- if (strcmp(log, "2")) {
- digitalWrite(7, HIGH);
- } else if (strcmp(log, "1")) {
- digitalWrite(7, LOW);
- }
- /*
- if (message.goddag == "3") {
- digitalWrite(8, HIGH);
- } else if(message.goddag == "4") {
- digitalWrite(8, LOW);
- }
- if (message.goddag == "tone") {
- int hei = Serial.parseInt();
- Serial.println(hei);
- tone(10, hei);
- }
- if (message.goddag == "lcd") {
- String myChar = Serial.readString();
- lcd.print(myChar);
- }else if(message.goddag == "lcdoff"){
- lcd.clear();
- }
- if (message.goddag == "pot") {
- int val = analogRead(A0);
- Serial.println(val);
- }
- */
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement