Serial port control problem
i doing programming arduino me control microwave frequency converter have built - trying make little control box uses nano drive 4 ttl control lines different commands sent via serial port to...... pretty simple stuff........
each state entered typing 1/ or 2/....... /6 sets 4 ttl lines cetain state.
i have 6 states want control lines in. 6th state want have 1 of lines turning on , off have sucessfully done.
what can't seem once code has entered 6th state function can't write new serial command , change ttl lines 1 of other 5 states
here code, "if (digitalstate == 6)....." function having trouble with with.....
thanks in advance want out microwave engineer ;-)
dan.
code: [select]
/* 4 line led drive via serila command
type
1/ 0101
2/ 0110
3/ 1000
4/ 1001
5/ 1010
6/ ever programmed befor pin 4 blinking
*/
unsigned long serialdata;
int inbyte;
int digitalstate;
int pinnumber;
void setup()
{
serial.begin(9600);
}
void loop()
{
getserial();
digitalstate = serialdata;
pinmode(2, output); // sets pin output
pinmode(3, output); // sets pin output
pinmode(4, output); // sets pin output
pinmode(5, output); // sets pin output
//serial.println(serialdata);
if (digitalstate == 1)
{
serial.print("18-23ghz selected ");
digitalwrite(2, high); // sw1_1
digitalwrite(3, low); // sw1_1
digitalwrite(4, high); // sw1_1
digitalwrite(5, low); // sw1_1
}
if (digitalstate == 2)
{
serial.print("23-26.5ghz selected ");
digitalwrite(2, low);
digitalwrite(3, high);
digitalwrite(4, high);
digitalwrite(5, low);
}
if (digitalstate == 3)
{
serial.print("26.5-33.599ghz selected ");
digitalwrite(2, low);
digitalwrite(3, low);
digitalwrite(4, low);
digitalwrite(5, high);
}
if (digitalstate == 4)
{
serial.print("33.6-37.99ghz selected ");
digitalwrite(2, high);
digitalwrite(3, low);
digitalwrite(46, low);
digitalwrite(5, high);
}
if (digitalstate == 5)
{
serial.print("38-40ghz selected ");
digitalwrite(2, low);
digitalwrite(3, high);
digitalwrite(4, low);
digitalwrite(5, high);
}
if (digitalstate == 6) // makes pin 4 blink on , off - how allow function exit due new serial command????
{
serial.print("pulse ");
while (digitalstate == 6)
{
// cal();
digitalwrite(4, high);
delay(100);
digitalwrite(4, low);
delay(200);
// serialdata = serial.read();
serial.println(serialdata);
// how make loop exit when type other serial command ????
}
}
}
long getserial() // serial data function
{
serialdata = 0;
while (inbyte != '/')
{
inbyte = serial.read();
if (inbyte > 0 && inbyte != '/')
{
serialdata = serialdata * 10 + inbyte - '0';
serial.print(" inbyte = ");
serial.println(inbyte);
}
}
inbyte = 0;
serial.print("serial read function serialdata = ");
serial.println(serialdata);
return serialdata;
}
/[code][/code]
hello,
something this?
not sure if want keep led blinking while receiving more ocmmands or if want blink once.
if want turn on , off blinking function, easiest integrate blink without delay example here.
something this?
code: [select]
/* 4 line led drive via serila command
type
1 0101
2 0110
3 1000
4 1001
5 1010
6 ever programmed befor pin 4 blinking
*/
unsigned long serialdata;
int inbyte;
int digitalstate;
int pinnumber;
void setup()
{
serial.begin(9600);
pinmode(2, output); // sets pin output
pinmode(3, output); // sets pin output
pinmode(4, output); // sets pin output
pinmode(5, output); // sets pin output
//serial.println(serialdata);
}
void loop()
{
digitalstate = serial.read(); //implement check ascii digits on this.
if (digitalstate == '1')
{
serial.print("18-23ghz selected ");
digitalwrite(2, high); // sw1_1
digitalwrite(3, low); // sw1_1
digitalwrite(4, high); // sw1_1
digitalwrite(5, low); // sw1_1
}
if (digitalstate == '2')
{
serial.print("23-26.5ghz selected ");
digitalwrite(2, low);
digitalwrite(3, high);
digitalwrite(4, high);
digitalwrite(5, low);
}
if (digitalstate == '3')
{
serial.print("26.5-33.599ghz selected ");
digitalwrite(2, low);
digitalwrite(3, low);
digitalwrite(4, low);
digitalwrite(5, high);
}
if (digitalstate == '4')
{
serial.print("33.6-37.99ghz selected ");
digitalwrite(2, high);
digitalwrite(3, low);
digitalwrite(46, low);
digitalwrite(5, high);
}
if (digitalstate == '5')
{
serial.print("38-40ghz selected ");
digitalwrite(2, low);
digitalwrite(3, high);
digitalwrite(4, low);
digitalwrite(5, high);
}
if (digitalstate == '6') // makes pin 4 blink on , off - how allow function exit due new serial command????
{
serial.print("pulse ");
while (digitalstate == '6')
{
// cal();
digitalwrite(4, high);
delay(100);
digitalwrite(4, low);
delay(200);
digitalstate = serial.read();
}
}
}
not sure if want keep led blinking while receiving more ocmmands or if want blink once.
if want turn on , off blinking function, easiest integrate blink without delay example here.

Arduino Forum > Using Arduino > Programming Questions > Serial port control problem
arduino
Comments
Post a Comment