Pass Array in xTaskCreate()
Posted: Thu Dec 31, 2020 9:27 am
I am trying to pass in the array of data that is created to the second core for sending over LoRa but am unable to get the syntax right. I commented all the important lines where the states[] array is used. Any help would be much appreciated.
Code: Select all
#include <Arduino.h>
#include "heltec.h"
#define BAND 915E6
const uint8_t receiverInput = 12;
const uint8_t escPin = 13;
int timer;
bool ticked = false;
int currentState = 0;
int states[11]; //Initial Creation
void sendPacket(void * parameter){
LoRa.beginPacket();
LoRa.setTxPower(14, RF_PACONFIG_PASELECT_PABOOST);
for(int i = 1; i < 12; i++)
{
LoRa.println(states[i]); //To Print Here
Serial.print("Sent Packet: ");
Serial.println(i);
Serial.println(*((int*)parameter[i])); //And To Print Here
}
LoRa.endPacket();
vTaskDelete(NULL);
}
void IRAM_ATTR escTick(){
states[currentState] = micros() - timer;
ticked = true;
if(currentState == 11)
{
Serial.println(states[currentState]);
xTaskCreatePinnedToCore(sendPacket, "SendPacket", 1000, (void*)&states, 1, NULL, 1); //Passing in Variable Here
}
}
void IRAM_ATTR pwmChange(){
if(digitalRead(receiverInput))
{
detachInterrupt(escPin);
pinMode(escPin, OUTPUT);
digitalWrite(escPin, LOW);
if(!ticked)
{
currentState = 0;
}
}
else
{
digitalWrite(escPin, HIGH);
pinMode(escPin, INPUT);
attachInterrupt(escPin, escTick, FALLING);
timer = micros();
currentState += 1;
ticked = false;
}
}
void setup() {
Heltec.begin(false, true, true, true, BAND);
Serial.begin(115200);
pinMode(receiverInput, INPUT);
pinMode(escPin, OUTPUT);
digitalWrite(escPin, HIGH);
attachInterrupt(receiverInput, pwmChange, CHANGE);
Serial.println("Initialized!");
}
void loop() {
}