I’ve been trying to receive whole arrays via serial communication, and have been trying to make use of pointers. Below is my cpp file.
/*
#include <Arduino.h>
#include "BreathSim.h"
BreathSim::BreathSim()
{
}
char BreathSim::checkstate(char state)
{
char aChar = Serial.read();
if (aChar == '<')
{
return 1;
}
else if (aChar=='>')
{
return 2
}
else
{
return state;
}
}
void BreathSim::GetChar(int index)
{
char inData[10];
char aChar = Serial.read();
inData[index] = aChar;
inData[index+1] = '\0';
}
void BreathSim::ToInt(int index, int *Array, char inData)
{
int inInt = atoi(inData);
*(Array+index) = inInt;
*(Array+index+1) = '\0';
}
void BreathSim::Step(int N, int T) {
int n = 0;
while (n < N)
{
PORTD = PORTD || 0x10;
delay(int(T / 2));
PORTD = PORTD && 0xEF;
delay(int(T / 2));
n = n + 1; // record this step
}
}
void BreathSim::Signal()
{
Serial.println('a');
char a = 'b';
while (a != 'a')
{
a = Serial.read();
}
}
And my main
#include <BreathSim.h>
int *Profile;
char state = 0; // 1 for started 2 for ended
int i = 0;
int ProfileIndex = 0;
char inData;
BreathSim breathsim;
void setup()
{
Serial.begin(115200);
DDRD = DDRD || 0xFC;
PORTD = 0x00;
breathsim.Signal();
}
void serialEvent()
{
if (Serial.available())
{
state == breathsim.checkstate(state);
if (state == 1)
{
breathsim.GetChar(i, inData);
i++;
}
if (state == 2)
{
i = 0;
breathsim.ToInt(ProfileIndex, *Profile, inData);
ProfileIndex++;
breathsim.Signal();
}
}
}
void loop()
{
if (ProfileIndex > 250)
{
digitalWrite(5, HIGH);
for (int j = 0; j <= ProfileIndex; j++)
{
breathsim.Step(1, *(Profile+j));
}
}
}
The issue I am having is in the line
breathsim.ToInt(ProfileIndex, *Profile, inData);
Where I get an error that I am converting from int to int*, I am a little confused as to why as I’m not sure where the int type is coming from, I thought I was just working with the pointer.
Any help would be much appreciated.