to create a "case" for displaying my voltage (in 2 decimal point) from the range of 0(min)-12v(max), and by commanding in through HTerm software, can get it to be transmitted back to me in Hex.
example i got was this "
case 03:
//set sampletime delay of the loop
sampleTime = (int)byteRead[5] * 256 + (int)byteRead[6];
for (int i=0; i<3;i++)
{
responseByte = byteRead*;*
* }*
* responseByte[5] = (byte)(sampleTime >> 8);*
* responseByte[6] = (byte)sampleTime;*
* replyCommand(responseByte);*
* break;*
however for now i am trying to reading the voltage.
so i hope someone with great programming skill can get me started, or help me with the codes.
this is the code that i used to read my A0
// the setup routine runs once when you press reset:
void setup() {
* // initialize serial communication at 9600 bits per second:*
* Serial.begin(9600);*
}
// the loop routine runs over and over again forever:
void loop() {
* // read the input on analog pin 0:*
* int sensorValue = analogRead(A0);*
* // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):*
_ float voltage = sensorValue * (12.0 / 1023.0);_
* // print out the value you read:*
* Serial.println(voltage);*
}
You must post the complete program because several parts of what you have shown can't be understood without it. And please use the code button </> so your code looks like this
and is easy to copy to a text editor - and there won't be any smileys.
It would also be helpful to explain what you want to do in more detail.
...R
//EPS Command
//-------------------------------------------------------------------------
void checkEPSCommand(byte byteRead[])
{
byte responseByte[7] = {0x00};
switch(byteRead[2])
{
case 01:
//Request Device ID
for (int i=0; i<3;i++)
{
responseByte = byteRead*;*
* }*
* responseByte[6] = DeviceID;*
* replyCommand(responseByte);*
* break;*
* case 02:*
* //Read Analog Voltage*
* // read the input on analog pin 0:*
* int sensorValue = analogRead(A0); //declared*
* // Convert the analog reading*
_ float voltage = sensorValue * (12.0 / 1023.0);
* {*
* for (float i=0; i<=12;i++)*
* {*
* responseByte[1] = byteRead[16];*
* }*
* responseByte[5] = (byte)(voltage >> 16);*
* responseByte[6] = (byte)voltage;*
* replyCommand(responseByte);*
* break;*
* }*
* }*
}
this is part of the program and
I'm trying to put this part in
void setup() {
* // initialize serial communication at 9600 bits per second:*
* Serial.begin(9600);*
}
// the loop routine runs over and over again forever:
void loop() {
* // read the input on analog pin 0:*
* int sensorValue = analogRead(A0);*
* // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):*
float voltage = sensorValue * (12.0 / 1023.0);_
* // print out the value you read:*
* Serial.println(voltage);*
}
which will be at case 2
so i could read my analog voltage and convert it to hex and display at HTerm(software)
Did you miss the advice to put the code in code tags ?
Is half of your code really in italics ? I don't think so.