negative value Conversion.
dear all,
i have 2 angle desired , actual. negative . using qmodbus software read below data modbus slave. if value of desired put has + value master read data in +ve value. if value assigned -ve . reading in image. if value selecting word -43 read. how convert readable format. instead of printing 65543 how make print either in +ve value or in -ve value
in below code checked if no negative multiply -1 else display is. -ve value displaying zero.
if hexadecimal , subtract ff value got add 1 actual no. since decimal no dint how it.
i have 2 angle desired , actual. negative . using qmodbus software read below data modbus slave. if value of desired put has + value master read data in +ve value. if value assigned -ve . reading in image. if value selecting word -43 read. how convert readable format. instead of printing 65543 how make print either in +ve value or in -ve value
in below code checked if no negative multiply -1 else display is. -ve value displaying zero.
if hexadecimal , subtract ff value got add 1 actual no. since decimal no dint how it.
code: [select]
#include "glob.h"
#include "rtc.h"
#include "config.h"
#include"timecalc.h"
#define id 1
static int local_day=10;
static int local_month=4;
static int local_year=2014;
static int local_s=2;
static int local_h=13;
static int local_m=14;
int wind_speed=30;
int wind_kmph=67;
float desired_angle=-45.0;
float actual_angle=-43.0;
modbus slave(id, 0, 0);
boolean led;
int8_t state = 0;
unsigned long tempus;
// data array modbus network sharing
uint16_t au16data[14];
void setup() {
// start communication
slave.begin( 9600 );
rtcsetup();
tempus = millis() + 100;
digitalwrite(13, high );
}
void loop() {
// poll messages
// blink led pin on each valid message
state = slave.poll( au16data, 14);
if (state > 4) {
tempus = millis() + 50;
digitalwrite(13, high);
}
if (millis() > tempus) digitalwrite(13, low );
calctime();
convertutctolocal();
au16data[0]=local_year;
au16data[1]=local_month;
au16data[2]=local_day;
au16data[3]=wkday;
au16data[4]=local_h;
au16data[5]=local_m;
au16data[6]=local_s;
au16data[7]=wind_speed;
au16data[8]=wind_kmph;
if(desired_angle<0)
{
au16data[9]=(int)desired_angle*-1;
au16data[10]=(int)actual_angle*-1;
}else
{
au16data[9]=(int)desired_angle;
au16data[10]=(int)actual_angle;
}
au16data[11] = slave.getincnt();
au16data[12] = slave.getoutcnt();
au16data[13] = slave.geterrcnt();
}
au16data unsigned - how can hold negative value?
instead of working negative angles, why not work positive values? remember, angles in circle, -1° same 359°, -2° 358°, etc.
instead of working negative angles, why not work positive values? remember, angles in circle, -1° same 359°, -2° 358°, etc.
Arduino Forum > Using Arduino > Programming Questions > negative value Conversion.
arduino
Comments
Post a Comment