We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi everyone, I get a series of long datatype from my TGAM EEG hardware and I would like to convert it to a small range of data so that I could use these variables to control my visuals. I mapped these long datatype roughly and directly but I found it's not a good way cause the result is incoherent and bouncing. Now I have no idea about it. Is there anyone has and idea about it? Any help will be appreciated.
float delta_ = map(delta, 0, 3072000, 0, 100);
float theta_ = map(theta, 0, 1300000, 0, 100);
float low_alpha_ = map(low_alpha, 0, 600000, 0, 100);
float high_alpha_ = map(high_alpha, 0, 300000, 0, 100);
float low_beta_ = map(low_beta, 0, 150000, 0, 100);
float high_beta_ = map(delta, 0, 3000000, 0, 100);
float low_gamma_ = map(delta, 0, 3000000, 0, 100);
float high_gamma_ = map(delta, 0, 3000000, 0, 100);
Answers
What does that mean?
What is the data type assigned to
delta
,theta
etc?Hi quark, they are the long datatype.
Just
(cast)
it toint
datatype: *-:)Rather than casing a
long
to anint
, you might try thisThis will cause the range values to be cast to
double
s so thatmap
returns adouble
which is then cast to afloat
Hi GoToLoop, I already have some previous steps like this
So I think I have already converted the long datatype before map maybe... I don't really know what's the function '_' in the numbers 3_072_000, but I just do it but I get a error "unexpected token:float".
Now the code like this: delta = Integer.parseInt(incomingValues[3]); theta = Integer.parseInt(incomingValues[4]); low_alpha = Integer.parseInt(incomingValues[5]); ... float delta_ = map(delta, 0, 3_072_000, 0, 100); float theta_ = map(theta, 0, 1_300_000, 0, 100); float low_alpha_ = map(low_alpha, 0, 600_000, 0, 100);
Hi quark, thanks for the response. I tried but I got the error that "the function 'map()' expects parameters like: 'map(float, float, float, float, float)'". I thinks maybe 'double' is on the right track but not in this way. Do you have some further advice?
Sorry my mistake. I looked at the source code for PApplet and although there is a version of map using the double data type it is commented out.
The problem with converting long data values to int data values is that you overflow the capacity of the int data type.
This code
produces the output
I suggest that you convert the long directly to float like this
That is just an IF. However, the max values
3072000
,1300000
&600000
are withinint
's range. L-)Thanks for your response. But I still get the very bouncing and jumping data as before. Is that because my mapping method not that appropriate?
Perhaps the input data is very bouncy and jumping. There is nothing wrong with the mapping provided the input values are inside the ranges you have specified.
e.g. delta is always in the range 0 to 3072000
Hi quark, thanks a lot. I will double check with the range values.
I have made a brain visualizer which maps the value dynamically based on the received the max and min value.