Hi, how i can read first char from serial, and send valuest after char to pin?
Example: I send to arduino H1234, arduino get it, and send 1234 to pin 13, next I send to arduino Z7239, arduino get it, and send 7239 to pin 12
Here is my code, working only 13 pin.
int thr = 13;
int pitch = 12;
int roll = 11;
int yaw = 10;
int aux = 9;
int val;
void setup()
{
Serial.begin(9600);
pinMode(thr, OUTPUT);
pinMode(pitch, OUTPUT);
pinMode(roll, OUTPUT);
pinMode(yaw, OUTPUT);
pinMode(aux, OUTPUT);
}
void loop()
{
if (Serial.available()) {
val = Serial.read();
digitalWrite(thr, HIGH);
digitalWrite(thr, val);
digitalWrite(thr, LOW);
delayMicroseconds(500);
digitalWrite(yaw, HIGH);
digitalWrite(yaw, val);
digitalWrite(yaw, LOW);
delayMicroseconds(500);
}
}
If you are using the Serial Monitor application to send data, it is sending strings. If you send "H1234", sending 'H' to the LED hardly makes sense, any more than sending '1', '2', '3', or '4' does.
Misunderstanding. I need to do 6 channel controller to control ESC by Multiwii on my atmega2560, so i want to send command via serial from my wifi router to arduino mini, and want to separate channels. If there is H1234 sended, the controller reads its an H and send the value next to H (in this example is 1234) to digital pin 13, and if i send Z1234, controller reads first Z and send next digits to anoter pin (12 or else)
send the value next to H (in this example is 1234) to digital pin 13,
The bit we don't understand is how you send 1234 to pin 13. Pin 13 is a digital pin and can only be set high or low so setting it to 1234 makes no sense at all.
So what you really want to do is to generate a PWM signal with the mark period ( that is high ) as the value you send through the serial port and the space value ( that is low ) at what period?
You need to use the code that says:-
a small example for a interrupt driven soft PWM code
Grumpy_Mike:
So what you really want to do is to generate a PWM signal with the mark period ( that is high ) as the value you send through the serial port and the space value ( that is low ) at what period?
You need to use the code that says:-
a small example for a interrupt driven soft PWM code