Hi.
Think this is nothing about simulide, this is about using variable types in C/C++;
In the first case you are using integer numbers calculations then store into a long, integers overflow, so you get negative numbers. Cast to long and it will work as espected.
👍
1
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
aha! so basically the output of the analogRead is int anyways and the temporary memory used for arithmetics is the same as the operator pairs. if I do ((long) analogRead(...)) it should be solved. Will try and come back.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
this worked great. Thanks a lot.
As a side feature request, the rotating wheel for potentiometer is a bit difficult to control. it would be great if one could change it to a slider and/or put the values manually (e.g. in the properties section).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You can put the value in potentiometer properties (the last property: "Value Ohm").
And manually there is a trick to controll it with accuracy:
Click on the pot wheel and hold it, then move mouse pointer outside of the pot as far as you want, the moving mouse pointer in a circle around the pot. The further you go from pot the more accurate you can change the value.
👍
1
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have a simple model with some LEDs and potentiometers (in the attachment) and the code below:
but I get negative values :
It seems like a bug to me.
For the moment I used a float variable as a workaround:
Hi.
Think this is nothing about simulide, this is about using variable types in C/C++;
In the first case you are using integer numbers calculations then store into a long, integers overflow, so you get negative numbers. Cast to long and it will work as espected.
aha! so basically the output of the
analogRead
isint
anyways and the temporary memory used for arithmetics is the same as the operator pairs. if I do((long) analogRead(...))
it should be solved. Will try and come back.this worked great. Thanks a lot.
As a side feature request, the rotating wheel for potentiometer is a bit difficult to control. it would be great if one could change it to a slider and/or put the values manually (e.g. in the properties section).
You can put the value in potentiometer properties (the last property: "Value Ohm").
And manually there is a trick to controll it with accuracy:
Click on the pot wheel and hold it, then move mouse pointer outside of the pot as far as you want, the moving mouse pointer in a circle around the pot. The further you go from pot the more accurate you can change the value.